PLCnext API Documentation 25.0.2.69
BasicString.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
7#include "Arp/Base/Core/Detail/PrimitiveTypes.hpp"
8#include <string>
9#include <memory>
10#include <iosfwd>
11#include <vector>
12#include <functional>
13#include <initializer_list>
14#include <span>
15
16#ifndef ARP_INSIDE_ARP_BASE_CORE_ARP_H
17 #error Never include 'BasicString.hxx' directly, just include 'Arp.hpp'
18#endif
19
20namespace Arp { namespace Base { namespace Core
21{
22
32template<class C, class A = std::allocator<C>>
34{
35public: // usings
36 using Allocator = A;
37 using AllocatorTraits = std::allocator_traits<Allocator>;
38 using CharType = C;
41 using StdString = std::basic_string<CharType, std::char_traits<CharType>, Allocator>;
42 using Reference = typename StdString::reference;
43 using ConstReference = typename StdString::const_reference;
44 using Iterator = typename StdString::iterator;
45 using ConstIterator = typename StdString::const_iterator;
46 using ReverseIterator = typename StdString::reverse_iterator;
47 using ConstReverseIterator = typename StdString::const_reverse_iterator;
48 using Tokens = std::vector<SelfType>;
49 using AppendToken = std::function < void(SelfType&&) >;
50 using Bytes = std::vector<byte>;
51
52public: // container policy usings
55 using size_type = typename StdString::size_type;
56 using difference_type = typename StdString::difference_type;
57 using reference = typename StdString::reference;
58 using const_reference = typename StdString::const_reference;
59 using pointer = typename AllocatorTraits::pointer;
60 using const_pointer = typename AllocatorTraits::const_pointer;
61 using iterator = typename StdString::iterator;
62 using const_iterator = typename StdString::const_iterator;
63 using reverse_iterator = typename StdString::reverse_iterator;
64 using const_reverse_iterator = typename StdString::const_reverse_iterator;
65
66public: // construction/destruction
68 BasicString(const SelfType& arg);
69 BasicString(SelfType&& arg)noexcept;
71 SelfType& operator=(SelfType&& arg)noexcept;
73
74 explicit BasicString(const Allocator& alloc);
75 explicit BasicString(const Bytes& bytes, const Allocator& alloc = Allocator());
76 BasicString(const StdString& arg);
77 BasicString(StdString&& arg)noexcept;
78 BasicString(const SelfType& arg, const Allocator& alloc);
79 BasicString(const SelfType& arg, size_type offset, size_type count = NPos);
80 BasicString(const SelfType& arg, size_type offset, size_type count, const Allocator& alloc);
81 BasicString(const CharType* pChars, size_type count);
82 BasicString(const CharType* pChars, size_type count, const Allocator& alloc);
83 BasicString(const CharType* pChars);
84 BasicString(const Char8uType* pChars);
85 BasicString(const CharType* pChars, const Allocator& alloc);
87 BasicString(size_type count, CharType c, const Allocator& alloc);
88 BasicString(SelfType&& arg, const Allocator& alloc);
89 BasicString(std::initializer_list<CharType> arg, const Allocator& alloc = Allocator());
90 BasicString(Iterator first, Iterator last, const Allocator& alloc = Allocator());
91 BasicString(ConstIterator first, ConstIterator last, const Allocator& alloc = Allocator());
92
93public: // static fields
94 static const size_type NPos = size_type(-1);
95 static const SelfType Empty;
96 static const SelfType NewLine;
97
98public: // replace_all operations
99 SelfType& ReplaceAll(const SelfType& pattern, const SelfType& replacement);
100
101public: // Misc operations
102 Allocator GetAllocator(void)const;
103 StdString& GetStdString(void);
104 const StdString& GetStdString(void)const;
105
106public: // Trim operations
107 SelfType TrimLeft(void)const;
108 SelfType TrimLeft(CharType trim)const;
109 SelfType TrimRight(void)const;
110 SelfType TrimRight(CharType trim)const;
111 SelfType Trim(void)const;
112 SelfType Trim(CharType trim)const;
113
114public: // Split operations
115 Tokens Split(CharType delimiter, bool trimTokens = true, bool removeEmptyTokens = true)const;
116 Tokens Split(std::span<const CharType> delimiters, bool trimTokens = true, bool removeEmptyTokens = true)const;
117 Tokens SplitByWord(const SelfType& delimiter, bool trimTokens = true, bool removeEmptyTokens = true)const;
118 void Split(CharType delimiter, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken)const;
119 void Split(std::span<const CharType> delimiters, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken)const;
120 void SplitByWord(const SelfType& delimiter, bool trimTokens, bool removeEmptyTokens, AppendToken appendToken)const;
121
122public: // Format operations
123 template<typename... Args> static SelfType Format(const SelfType& format, const Args& ... args);
124 template<typename... Args> static SelfType Format(const char* format, const Args& ... args);
125 template<typename... Args> static SelfType FormatPrintf(const char* format, const Args& ... args);
126
127private: // fields
128 StdString stdString;
129};
130
132// initializing of static fields
133template<class C, class A>
135
136template <class C, class A>
138
139}}} // end of namespace Arp::Base::Core
This template class implements the extensions of class String related to std::string,...
Definition: BasicString.hxx:34
typename StdString::difference_type difference_type
The difference type of this type.
Definition: BasicString.hxx:56
typename AllocatorTraits::pointer pointer
The pointer type of this type.
Definition: BasicString.hxx:59
BasicString(SelfType &&arg) noexcept
This move constructor moves the as argument passed string to this string.
static SelfType FormatPrintf(const char *format, const Args &... args)
Formats the format C-string using the printf syntax with the given variadic arguments.
Definition: BasicString.inl:280
SelfType & operator=(const SelfType &arg)
This assignment operator copies the right-hand-side operand to this string.
typename StdString::const_iterator ConstIterator
The iterator type of this type.
Definition: BasicString.hxx:45
std::allocator_traits< Allocator > AllocatorTraits
The allocator type traits.
Definition: BasicString.hxx:37
CharType value_type
The char type of this type.
Definition: BasicString.hxx:54
std::basic_string< CharType, std::char_traits< CharType >, Allocator > StdString
The type of the basic std string.
Definition: BasicString.hxx:41
typename StdString::size_type size_type
The size type of this type.
Definition: BasicString.hxx:55
typename StdString::reverse_iterator reverse_iterator
The reverse iterator type of this type.
Definition: BasicString.hxx:63
Allocator GetAllocator(void) const
Gets the allocator of this string.
Definition: BasicString.inl:309
SelfType & operator=(SelfType &&arg) noexcept
This move assignment operator moves the right-hand-side operand to this string.
typename StdString::reference Reference
The reference type of this type.
Definition: BasicString.hxx:42
typename AllocatorTraits::const_pointer const_pointer
The const pointer type of this type.
Definition: BasicString.hxx:60
static SelfType Format(const SelfType &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: BasicString.inl:255
std::vector< SelfType > Tokens
Used by initializing operations.
Definition: BasicString.hxx:48
typename StdString::const_reference ConstReference
The const reference type of this type.
Definition: BasicString.hxx:43
Tokens SplitByWord(const SelfType &delimiter, bool trimTokens=true, bool removeEmptyTokens=true) const
Splits this string into tokens using the specified (single) delimiter string.
Definition: BasicString.inl:435
C CharType
The character type.
Definition: BasicString.hxx:38
typename StdString::reverse_iterator ReverseIterator
The iterator type of this type.
Definition: BasicString.hxx:46
Arp::Base::Core::char8u Char8uType
The UTF8 character type.
Definition: BasicString.hxx:39
typename StdString::iterator iterator
The iterator type of this type.
Definition: BasicString.hxx:61
typename StdString::const_reverse_iterator const_reverse_iterator
The const reverse iterator type of this type.
Definition: BasicString.hxx:64
typename StdString::const_reference const_reference
The const reference type of this type.
Definition: BasicString.hxx:58
BasicString(const SelfType &arg)
The copy constructor copies the as argument passed string deeply.
BasicString(void)
The default constructor constructs an empty string instance.
Allocator allocator_type
The allocator type of this type.
Definition: BasicString.hxx:53
typename StdString::const_iterator const_iterator
The const iterator type of this type.
Definition: BasicString.hxx:62
typename StdString::iterator Iterator
The iterator type of this type.
Definition: BasicString.hxx:44
A Allocator
The characters allocator type.
Definition: BasicString.hxx:36
typename StdString::const_reverse_iterator ConstReverseIterator
Used by Split() operations.
Definition: BasicString.hxx:47
~BasicString(void)
The destructor deallocates all memory of this instance.
typename StdString::reference reference
The reference type of this type.
Definition: BasicString.hxx:57
StdString & GetStdString(void)
Gets the basic std string.
Definition: BasicString.inl:293
SelfType & ReplaceAll(const SelfType &pattern, const SelfType &replacement)
Replaces a given pattern by a replacement string.
Definition: BasicString.inl:231
Tokens Split(CharType delimiter, bool trimTokens=true, bool removeEmptyTokens=true) const
Splits this string into tokens using the specified delimiter characters (multiple).
Definition: BasicString.inl:406
char8_t char8u
The Arp UTF8 character type of 1 byte size.
Definition: PrimitiveTypes.hpp:47
Root namespace for the PLCnext API