Unicode character string. More...
#include <arccore/base/String.h>
Public Member Functions | |
| String () | |
| Creates a null string. | |
| String (const char *str) | |
| Creates a string from str in UTF-8 encoding. | |
| String (char *str) | |
| Creates a string from str in UTF-8 encoding. | |
| String (const char *str, bool do_alloc) | |
| Creates a string from str in UTF-8 encoding. | |
| String (const char *str, Integer len) | |
| Creates a string from str in UTF-8 encoding. | |
| String (std::string_view str) | |
| Creates a string from str in UTF-8 encoding. | |
| String (StringView str) | |
| Creates a string from str in UTF-8 encoding. | |
| String (const std::string &str) | |
| Creates a string from str in UTF-8 encoding. | |
| String (const UCharConstArrayView &ustr) | |
| Creates a string from str in UTF-16 encoding. | |
| String (const Span< const Byte > &ustr) | |
| Creates a string from str in UTF-8 encoding. | |
| String (StringImpl *impl) | |
| Creates a string from str in UTF-8 encoding. | |
| String (const String &str) | |
| Creates a string from str. | |
| String (String &&str) | |
| Creates a string from str. | |
| String & | operator= (const String &str) |
| Copies str into this instance. | |
| String & | operator= (String &&str) |
| Copies str into this instance. | |
| String & | operator= (StringView str) |
| Copies str into this instance. | |
| String & | operator= (const char *str) |
| References str encoded in UTF-8 in this instance. | |
| String & | operator= (std::string_view str) |
| Copies str encoded in UTF-8 into this instance. | |
| String & | operator= (const std::string &str) |
| Copies str encoded in UTF-8 into this instance. | |
| ~String () | |
| Frees resources. | |
| operator StringView () const | |
| Returns a view of the current string. | |
| ConstArrayView< UChar > | utf16 () const |
| Returns the conversion of the instance into UTF-16 encoding. | |
| ByteConstArrayView | utf8 () const |
| Returns the conversion of the instance into UTF-8 encoding. | |
| Span< const Byte > | bytes () const |
| Returns the conversion of the instance into UTF-8 encoding. | |
| const char * | localstr () const |
| Returns the conversion of the instance into UTF-8 encoding. | |
| std::string_view | toStdStringView () const |
| Returns an STL view of the current string. | |
| StringView | view () const |
| Returns a view of the current string. | |
| String | clone () const |
| Clones this string. | |
| String | upper () const |
| Transforms all characters in the string to uppercase. | |
| String | lower () const |
| Transforms all characters in the string to lowercase. | |
| bool | null () const |
| Returns true if the string is null. | |
| Integer | len () const |
| Returns the length of the string in 32 bits. | |
| Int64 | length () const |
| Returns the length of the string. | |
| bool | empty () const |
| True if the string is empty (null or ""). | |
| Int32 | hashCode () const |
| Calculates a hash value for this character string. | |
| void | writeBytes (std::ostream &o) const |
| Writes the string in UTF-8 format to the stream o. | |
| String | operator+ (const char *str) const |
| String | operator+ (std::string_view str) const |
| String | operator+ (const std::string &str) const |
| String | operator+ (const String &str) const |
| String | operator+ (unsigned long v) const |
| String | operator+ (unsigned int v) const |
| String | operator+ (double v) const |
| String | operator+ (long double v) const |
| String | operator+ (int v) const |
| String | operator+ (long v) const |
| String | operator+ (unsigned long long v) const |
| String | operator+ (long long v) const |
| String | operator+ (const APReal &v) const |
| bool | contains (const String &s) const |
| Indicates if the string contains s. | |
| bool | startsWith (const String &s) const |
| Indicates if the string starts with the characters of s. | |
| bool | endsWith (const String &s) const |
| Indicates if the string ends with the characters of s. | |
| String | substring (Int64 pos) const |
| Substring starting at position pos. | |
| String | substring (Int64 pos, Int64 len) const |
| Substring starting at position pos and of length len. | |
| template<typename StringContainer> | |
| void | split (StringContainer &str_array, char c) const |
| Splits the string based on the character c. | |
| void | internalDump (std::ostream &ostr) const |
| Displays the internal information of the class. | |
Static Public Member Functions | |
| static String | fromUtf8 (Span< const Byte > bytes) |
| static String | replaceWhiteSpace (const String &rhs) |
| Performs whitespace character normalization. | |
| static String | collapseWhiteSpace (const String &rhs) |
| Performs whitespace character normalization. | |
| static String | fromNumber (unsigned long v) |
| static String | fromNumber (unsigned int v) |
| static String | fromNumber (double v) |
| static String | fromNumber (double v, Integer nb_digit_after_point) |
| static String | fromNumber (long double v) |
| static String | fromNumber (int v) |
| static String | fromNumber (long v) |
| static String | fromNumber (unsigned long long v) |
| static String | fromNumber (long long v) |
| static String | fromNumber (const APReal &v) |
| static String | format (const String &str) |
| static String | format (const String &str, const StringFormatterArg &arg1) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4, const StringFormatterArg &arg5) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4, const StringFormatterArg &arg5, const StringFormatterArg &arg6) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4, const StringFormatterArg &arg5, const StringFormatterArg &arg6, const StringFormatterArg &arg7) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4, const StringFormatterArg &arg5, const StringFormatterArg &arg6, const StringFormatterArg &arg7, const StringFormatterArg &arg8) |
| static String | format (const String &str, const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4, const StringFormatterArg &arg5, const StringFormatterArg &arg6, const StringFormatterArg &arg7, const StringFormatterArg &arg8, const StringFormatterArg &arg9) |
| static String | concat (const StringFormatterArg &arg1) |
| static String | concat (const StringFormatterArg &arg1, const StringFormatterArg &arg2) |
| static String | concat (const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3) |
| static String | concat (const StringFormatterArg &arg1, const StringFormatterArg &arg2, const StringFormatterArg &arg3, const StringFormatterArg &arg4) |
| static String | plural (const Integer n, const String &str, const bool with_number=true) |
| Standard plural form by adding an 's'. | |
| static String | plural (const Integer n, const String &str, const String &str2, const bool with_number=true) |
| Special plural form by variant. | |
| static String | join (String delim, ConstArrayView< String > strs) |
Friends | |
| class | StringBuilder |
| class | StringUtilsImpl |
| bool | operator< (const String &a, const String &b) |
| bool | operator== (const String &a, const String &b) |
| Compares two unicode strings. | |
| bool | operator!= (const String &a, const String &b) |
| Compares two unicode strings. | |
| std::ostream & | operator<< (std::ostream &o, const String &str) |
| String output operator. | |
| std::istream & | operator>> (std::istream &o, String &str) |
| String input operator. | |
| bool | operator== (const char *a, const String &b) |
| Compares two unicode strings. | |
| bool | operator!= (const char *a, const String &b) |
| Compares two unicode strings. | |
| bool | operator== (const String &a, const char *b) |
| Compares two unicode strings. | |
| bool | operator!= (const String &a, const char *b) |
| Compares two unicode strings. | |
| String | operator+ (const char *a, const String &b) |
| Adds two strings. | |
| bool | operator< (const String &a, const String &b) |
Unicode character string.
This class allows managing a character string using either UTF-8 or UTF-16 encoding. Note that UTF-16 encoding is obsolete and will be removed in a later version when C++20 is available.
All methods using const char* as arguments assume that the encoding used is UTF-8.
Instances of this class are immutable.
This class is similar to std::string but with the following differences:
When C++20 is available, the String class will correspond to the std::optional<std::u8string> type.
For performance reasons, when building a string piece by piece, it is preferable to use the 'StringBuilder' class.
Definition at line 69 of file arccore/src/base/arccore/base/String.h.
|
inline |
Creates a null string.
Definition at line 80 of file arccore/src/base/arccore/base/String.h.
Referenced by clone(), collapseWhiteSpace(), contains(), endsWith(), lower(), operator!=, operator!=, operator!=, operator+, operator+(), operator+(), operator+(), operator+(), operator<<, operator=(), operator=(), operator=(), operator=(), operator=(), operator=(), operator==, operator==, operator==, operator>>, plural(), plural(), replaceWhiteSpace(), split(), startsWith(), String(), String(), substring(), substring(), and upper().
|
inline |
Creates a string from str in UTF-8 encoding.
Definition at line 89 of file arccore/src/base/arccore/base/String.h.
| Arcane::String::String | ( | char * | str | ) |
| Arcane::String::String | ( | const char * | str, |
| bool | do_alloc ) |
| Arcane::String::String | ( | const char * | str, |
| Integer | len ) |
| Arcane::String::String | ( | std::string_view | str | ) |
| Arcane::String::String | ( | StringView | str | ) |
Creates a string from str in UTF-8 encoding.
Definition at line 70 of file String.cc.
References toStdStringView().
| Arcane::String::String | ( | const std::string & | str | ) |
| Arcane::String::String | ( | const UCharConstArrayView & | ustr | ) |
|
explicit |
| Arcane::String::String | ( | const String & | str | ) |
|
inline |
Creates a string from str.
Definition at line 120 of file arccore/src/base/arccore/base/String.h.
References String().
|
inline |
Frees resources.
Definition at line 158 of file arccore/src/base/arccore/base/String.h.
Returns the conversion of the instance into UTF-8 encoding.
bytes().size() corresponds to the length of the character string but the returned view always contains a terminal '\0'.
Definition at line 292 of file String.cc.
Referenced by Arcane::ParameterList::addParameterLine(), endsWith(), hashCode(), Arcane::BasicSerializer::put(), Arcane::MeshReaderMng::readMesh(), Arcane::BasicSerializer::reserve(), startsWith(), writeBytes(), and Arcane::TraceMng::writeDirect().
| String Arcane::String::clone | ( | ) | const |
Performs whitespace character normalization.
The behavior is identical to replaceWhiteSpace() plus:
|
static |
|
static |
|
static |
|
static |
| bool Arcane::String::contains | ( | const String & | s | ) | const |
Indicates if the string contains s.
Definition at line 1078 of file String.cc.
References null(), String(), and toStdStringView().
| bool Arcane::String::empty | ( | ) | const |
True if the string is empty (null or "").
Definition at line 316 of file String.cc.
Referenced by Arcane::dom::DOMImplementation::_load(), Arcane::CaseOptions::_setMeshHandleAndCheckDisabled(), Arcane::MeshUtils::checkUniqueIdsHashCollective(), Arcane::ArcaneLauncher::init(), and Arcane::ArcaneLauncher::run().
| bool Arcane::String::endsWith | ( | const String & | s | ) | const |
Indicates if the string ends with the characters of s.
Definition at line 1094 of file String.cc.
References bytes(), Arcane::SpanImpl< T, SizeType, Extent >::data(), Arcane::SpanImpl< T, SizeType, Extent >::size(), and String().
Referenced by Arcane::Platform::getLoadedSharedLibraryFullPath().
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| Int32 Arcane::String::hashCode | ( | ) | const |
Calculates a hash value for this character string.
Definition at line 734 of file String.cc.
References bytes(), and Arcane::SpanImpl< T, SizeType, Extent >::size().
| void Arcane::String::internalDump | ( | std::ostream & | ostr | ) | const |
|
static |
| Integer Arcane::String::len | ( | ) | const |
Returns the length of the string in 32 bits.
Definition at line 329 of file String.cc.
References Arcane::arccoreCheckArraySize(), and toStdStringView().
Referenced by Arcane::dom::DOMImplementation::_load(), split(), String(), and substring().
| Int64 Arcane::String::length | ( | ) | const |
Returns the length of the string.
Definition at line 339 of file String.cc.
References toStdStringView().
Referenced by Arcane::MessagePassing::namedBarrier(), Arcane::BasicSerializer::put(), Arcane::platform::raiseFloatingException(), split(), and substring().
| const char * Arcane::String::localstr | ( | ) | const |
Returns the conversion of the instance into UTF-8 encoding.
If null() is true, returns the empty string. Otherwise, this method is equivalent to calling bytes().data(). There is always a terminal '\0' at the end of the returned string.
Definition at line 228 of file String.cc.
Referenced by Arcane::dom::DOMImplementation::_load(), Arcane::CartesianMeshCoarsening::createCoarseCells(), Arcane::Platform::createDirectory(), Arcane::MeshUtils::dumpSynchronizerTopologyJSON(), Arcane::platform::getCompilerId(), Arcane::Platform::getEnvironmentVariable(), Arcane::Platform::getLoadedSharedLibraryFullPath(), Arcane::CodeService::initCase(), Arcane::SimpleTableReaderWriterUtils::isFileExist(), Arcane::Platform::isFileReadable(), Arcane::MessagePassing::namedBarrier(), Arcane::operator<<(), operator<<, Arcane::platform::raiseFloatingException(), split(), Arcane::VersionInfo::VersionInfo(), Arcane::MeshUtils::writeMeshConnectivity(), and Arcane::MeshUtils::writeMeshInfosSorted().
| String Arcane::String::lower | ( | ) | const |
| bool Arcane::String::null | ( | ) | const |
Returns true if the string is null.
Definition at line 305 of file String.cc.
Referenced by Arcane::dom::DOMImplementation::_load(), Arcane::CaseOptionExtended::_search(), Arcane::CaseOptionMultiExtended::_search(), Arcane::CaseOptionMultiSimpleT< T >::_search(), Arcane::CaseOptionSimpleT< T >::_search(), Arcane::StringBuilder::append(), Arcane::XmlNode::attrValue(), collapseWhiteSpace(), contains(), Arcane::Accelerator::AcceleratorRuntimeInitialisationInfo::executionPolicy(), Arcane::Platform::getLoadedSharedLibraryFullPath(), Arcane::MemoryUtils::getMemoryResourceFromName(), Arcane::Materials::MeshMaterialVariableCommonStaticImpl< TrueType >::getReference(), Arcane::CaseOptionName::name(), Arcane::dom::LibXml2_Parser::parse(), Arcane::CaseOptions::read(), Arcane::TraceMng::setErrorFileName(), Arcane::TraceMng::setLogFileName(), Arcane::CaseFunction::setName(), Arcane::Internal::ServiceInfo::tagName(), Arcane::CaseOptionBase::translatedName(), Arcane::CaseOptions::translatedName(), and Arcane::Convert::ScalarType< T >::tryParseFromEnvironment().
| Arcane::String::operator StringView | ( | ) | const |
|
inline |
Returns the concatenation of this string with the string str encoded in UTF-8
Definition at line 376 of file arccore/src/base/arccore/base/String.h.
| String Arcane::String::operator+ | ( | const std::string & | str | ) | const |
| String Arcane::String::operator+ | ( | std::string_view | str | ) | const |
| String Arcane::String::operator+ | ( | unsigned long long | v | ) | const |
|
inline |
References str encoded in UTF-8 in this instance.
Definition at line 142 of file arccore/src/base/arccore/base/String.h.
References String().
| String & Arcane::String::operator= | ( | const std::string & | str | ) |
Copies str encoded in UTF-8 into this instance.
Definition at line 216 of file String.cc.
References operator=(), and String().
Copies str into this instance.
Definition at line 171 of file String.cc.
References String().
Referenced by operator=(), operator=(), and operator=().
| String & Arcane::String::operator= | ( | std::string_view | str | ) |
Copies str encoded in UTF-8 into this instance.
Definition at line 207 of file String.cc.
References operator=(), and String().
| String & Arcane::String::operator= | ( | StringView | str | ) |
Copies str into this instance.
Definition at line 198 of file String.cc.
References operator=(), and String().
Performs whitespace character normalization.
All whitespace characters are replaced by space characters #x20, namely #xD (Carriage Return), #xA (Line Feed), and #x9 (Tabulation). This corresponds to the xs:replace attribute of XMLSchema 1.0
Definition at line 441 of file String.cc.
References String().
|
inline |
Splits the string based on the character c.
Definition at line 495 of file arccore/src/base/arccore/base/String.h.
References len(), length(), localstr(), and String().
| bool Arcane::String::startsWith | ( | const String & | s | ) | const |
Indicates if the string starts with the characters of s.
Definition at line 1110 of file String.cc.
References bytes(), Arcane::SpanImpl< T, SizeType, Extent >::data(), Arcane::SpanImpl< T, SizeType, Extent >::size(), and String().
Substring starting at position pos.
Definition at line 1125 of file String.cc.
References length(), String(), and substring().
Referenced by Arcane::ParameterList::addParameterLine(), and substring().
| std::string_view Arcane::String::toStdStringView | ( | ) | const |
Returns an STL view of the current string.
The encoding used is UTF-8.
Definition at line 349 of file String.cc.
References ARCCORE_FATAL.
Referenced by contains(), len(), length(), Arcane::MeshReaderMng::readMesh(), and String().
| String Arcane::String::upper | ( | ) | const |
| ConstArrayView< UChar > Arcane::String::utf16 | ( | ) | const |
Returns the conversion of the instance into UTF-16 encoding.
The returned array always contains a terminal zero if the string is not null-terminated. Therefore, the size of any non-null string is the array size minus 1.
| ByteConstArrayView Arcane::String::utf8 | ( | ) | const |
Returns the conversion of the instance into UTF-8 encoding.
The returned array always contains a terminal zero if the string is not null-terminated. Therefore, the size of any non-null string is the array size minus 1.
Definition at line 276 of file String.cc.
References Arcane::arccoreCheckArraySize().
| StringView Arcane::String::view | ( | ) | const |
Returns a view of the current string.
The encoding used is UTF-8.
Definition at line 368 of file String.cc.
Referenced by Arcane::builtInGetValue(), and operator StringView().
| void Arcane::String::writeBytes | ( | std::ostream & | o | ) | const |
Writes the string in UTF-8 format to the stream o.
Definition at line 1246 of file String.cc.
References bytes(), Arcane::SpanImpl< T, SizeType, Extent >::data(), and Arcane::SpanImpl< T, SizeType, Extent >::size().
Referenced by operator<<.
|
friend |
Compares two unicode strings.
| true | if they are different, |
| false | if they are equal. |
Definition at line 345 of file arccore/src/base/arccore/base/String.h.
References operator==, and String().
|
friend |
Compares two unicode strings.
| true | if they are different, |
| false | if they are equal. |
Definition at line 362 of file arccore/src/base/arccore/base/String.h.
References operator==, and String().
Compares two unicode strings.
| true | if they are different, |
| false | if they are equal. \relate String |
Definition at line 323 of file arccore/src/base/arccore/base/String.h.
References operator==, and String().
|
friend |
String output operator.
Definition at line 1231 of file String.cc.
References localstr(), String(), and writeBytes().
|
friend |
Compares two unicode strings.
| true | if they are equal, |
| false | otherwise. |
Definition at line 1199 of file String.cc.
References operator==, and String().
|
friend |
Compares two unicode strings.
| true | if they are equal, |
| false | otherwise. |
Definition at line 1193 of file String.cc.
References operator==, and String().
Compares two unicode strings.
| true | if they are equal, |
| false | otherwise. \relate String |
Definition at line 1164 of file String.cc.
References Arcane::CStringUtils::isEqual(), operator==, and String().
Referenced by operator!=, operator!=, operator!=, operator==, operator==, and operator==.
|
friend |
|
friend |
Definition at line 74 of file arccore/src/base/arccore/base/String.h.
|
friend |
Definition at line 75 of file arccore/src/base/arccore/base/String.h.