40 static int precision = 16;
49 return std::u32string::npos;
60 data = std::u32string(n, c);
141 _(
"index out of bounds."));
158 _(
"index out of bounds."));
170 return cdata.c_str();
180 else if (data == U
"false")
205 _(
"index out of bounds."));
207 data.insert(pos, s.data);
222 if ((pos >=
Size()) || (pos + n >
Size()))
231 s = data.substr(pos);
235 s = data.substr(pos, n);
264 if ((pos >=
Size()) || (pos + n >
Size()))
267 _(
"index out of bounds."));
288 if ((pos >=
Size()) || (pos + n >
Size()))
291 _(
"index out of bounds."));
293 data.replace(pos, n, s.data);
306 size_t old_suffix_length = old_suffix.
Length();
307 if (!old_suffix_length)
309 size_t word_length =
Length();
311 if (old_suffix_length <= word_length)
313 size_t pivot = word_length - old_suffix_length;
318 data.append(new_suffix.
Std());
334 size_t word_length =
Length();
336 if (n <= word_length)
338 size_t pivot = word_length - n;
341 data.append(new_suffix.
Std());
356 size_t suffix_length = suffix.
Length();
359 size_t word_length =
Length();
361 if (suffix_length <= word_length)
363 size_t pivot = word_length - suffix_length;
382 std::vector<String> found;
384 size_t n = suffixes.size();
386 for (
size_t k = 0; k < n; k++)
407 std::vector<String> found;
409 size_t n = prefixes.size();
411 for (
size_t k = 0; k < n; k++)
432 std::vector<String> found;
434 for (
auto str : substrings)
440 found.push_back(str);
458 for (
auto & elem : data)
471 for (
auto & elem : data)
472 elem = char32_t(
ToWUpper(wint_t(elem)));
483 data[0] = char32_t(
ToWUpper(wint_t(data[0])));
495 for (
auto & elem : data)
496 elem = char32_t(
ToWLower(wint_t(elem)));
517 if (from_pos >=
Size())
520 _(
"index out of bounds."));
522 return data.find(s.data, from_pos);
535 size_t idx =
Find(s, 0);
564 size_t length_main =
Length();
565 size_t length_suffix = s.
Length();
567 if (length_main < length_suffix)
573 size_t pos = length_main - length_suffix;
574 size_t idx =
Find(s, pos);
589 size_t nb_suffixes = suffixes.size();
593 while (!found && (k < nb_suffixes))
613 if (from_pos >=
Size())
616 _(
"index out of bounds."));
619 return data.find_first_of(s.data, from_pos);
633 if (from_pos >=
Size())
636 _(
"index out of bounds."));
639 return data.find_first_not_of(s.data, from_pos);
655 if (last_pos ==
NPos())
656 return data.rfind(s.data);
657 if (last_pos >=
Size())
660 _(
"index out of bounds."));
662 return data.rfind(s.data, last_pos);
676 if (last_pos ==
NPos())
677 return data.find_last_of(s.data);
678 if (last_pos >=
Size())
681 _(
"index out of bounds."));
683 return data.find_last_of(s.data, last_pos);
697 if (last_pos ==
NPos())
698 return data.find_last_not_of(s.data);
699 if (last_pos >=
Size())
702 _(
"index out of bounds."));
704 return data.find_last_not_of(s.data, last_pos);
716 unsigned int s1 = (
unsigned int)
Size();
717 unsigned int s2 = (
unsigned int)s.
Size();
718 std::vector<std::vector<unsigned int> > d(s1 + 1, std::vector<unsigned int>(s2 + 1));
720 for (
unsigned int i = 1; i <= s1; ++i) d[i][0] = i;
721 for (
unsigned int i = 1; i <= s2; ++i) d[0][i] = i;
723 for (
unsigned int i = 1; i <= s1; ++i)
724 for (
unsigned int j = 1; j <= s2; ++j)
725 d[i][j] = std::min(std::min(d[i - 1][j] + 1, d[i][j - 1] + 1),
726 d[i - 1][j - 1] + (data[i - 1] == s[j - 1] ? 0 : 1));
743 _(
"Wrong XML element."));
774 size_t n = data.length();
775 auto start = data.find_first_not_of(sep.data);
776 std::vector<String> words;
779 auto stop = data.find_first_of(sep.data, start);
780 if (stop > n) stop = n;
781 words.push_back(data.substr(start, stop - start));
782 start = data.find_first_not_of(sep.data, stop + 1);
790 data.shrink_to_fit();
806 Cloner::Register<String>();
807 Ruler::Register<String>();
virtual StringUTF8 GetValue() const override
Gets the content of the node.
wint_t ToWLower(wint_t c)
Transforms a character to its lower case.
size_t BackwardFind(const String &s, size_t last_pos=NPos()) const
Finds the last occurrence of a string.
wint_t ToWUpper(wint_t c)
Transforms a character to its upper case.
static crn::StringUTF8 CreateUniqueId(size_t len=8)
Generates an almost unique id.
std::vector< String > Split(const String &sep) const
Splits the string in multiple strings delimited by a set of separators.
size_t Size() const noexcept
Returns the length of the string.
StringUTF8 GetName() const
Gets the label of the element.
bool StartsWith(const String &s) const
Check if string has a given prefix.
const char * CStr() const
Conversion to UTF8 cstring.
size_t BackwardFindNotOf(const String &s, size_t from_pos=NPos()) const
Finds the last occurrence of character not in a list.
bool IsEmpty() const noexcept
Checks if the string is empty.
size_t Find(const String &s, size_t from_pos=0) const
Finds the first occurrence of a string.
String()=default
Default constructor (empty string)
bool IsFalse() const noexcept
Is false?
#define CRN_END_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
bool IsTrue() const noexcept
Is true?
std::string ToUtf8(const std::basic_string< char32_t > &widestring)
std::basic_string< char32_t > FromUtf8(const std::string &utf8string)
A UTF32 character string class.
void Deserialize(xml::Element &el)
Initializes the object from an XML element. Unsafe.
static int & Precision() noexcept
Precision of the floating point conversion.
Text PushBackText(const StringUTF8 &text, bool cdata=false)
Adds a text at the end of the children list.
void ShrinkToFit()
Optimizes the memory usage.
String & ReplaceSuffix(const String &old_suffix, const String &new_suffix)
Replaces suffix by another pattern if present.
String SubString(size_t pos, size_t n=0) const
Extracts a part of the string.
char32_t & operator[](size_t index)
Access to a character.
std::vector< String > WhichSuffixes(const std::vector< String > &suffixes) const
Returns suffixes found within a collection.
#define CRN_DATA_FACTORY_REGISTER(elemname, classname)
Registers a class to the data factory.
String & FirstCharacterToUpper()
Converts the first character of string to uppercase.
static String CreateUniqueId(size_t len=8)
Generates an almost unique id.
size_t Length() const noexcept
Returns the length of the string.
Prop3 ToProp3() const
Conversion to Prop3.
size_t BackwardFindAnyOf(const String &s, size_t from_pos=NPos()) const
Finds the last occurrence of character in a list.
Node GetFirstChild()
Gets the first child node.
std::vector< String > WhichPrefixes(const std::vector< String > &prefixes) const
Returns prefixes found within a collection.
size_t FindAnyOf(const String &s, size_t from_pos=0) const
Finds the first occurrence of character in a list.
String & ToLower()
Converts the string to lowercase.
bool EndsWith(const String &s) const
Check if string has a given suffix.
std::vector< String > WhichSubstrings(const std::vector< String > &substrings) const
Returns substring found within a collection.
xml::Element Serialize(xml::Element &parent) const
Dumps the object to an XML element. Unsafe.
String & Replace(const String &s, size_t pos, size_t n=0)
Replaces a part of the string.
std::string & Std()&noexcept
Conversion to std string.
A character string class.
int EditDistance(const String &s) const
Edit distance.
String & Erase(size_t pos, size_t n=0)
Erases a part of the string.
String & ToUpper()
Converts the string to uppercase.
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
std::u32string & Std()&noexcept
Conversion to std u32string.
String & Insert(size_t pos, const String &s)
Inserts a string.
Invalid argument error (e.g.: nullptr pointer)
static size_t NPos() noexcept
Last position in a string.
String & DeleteSuffix(const String &suffix)
Delete suffix if found.
size_t FindNotOf(const String &s, size_t from_pos=0) const
Finds the first occurrence of character not in a list.
String & Crop(size_t pos, size_t n=0)
Crops the string.
#define CRN_BEGIN_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.