7 #ifndef GDCORE_UTF8_STRING_H
8 #define GDCORE_UTF8_STRING_H
17 #include "GDCore/Utf8/utf8.h"
35 using value_type = char32_t;
36 using reference = char32_t&;
37 using const_reference =
const char32_t&;
38 using pointer = char32_t*;
39 using const_pointer =
const char32_t*;
41 using size_type = std::string::size_type;
42 using difference_type = std::string::difference_type;
44 static constexpr size_type npos = -1;
47 class GD_CORE_API
StringIterator :
public std::iterator<std::bidirectional_iterator_tag, String::value_type, String::difference_type>
60 String::value_type operator*() {return ::utf8::unchecked::peek_next(strIt);}
64 StringIterator<T>& operator--() { ::utf8::unchecked::prior(strIt);
return *
this; }
67 bool operator==(
const StringIterator<T> &other) {
return (strIt == other.strIt); }
71 bool operator<=(
const StringIterator<T> &other) {
return (strIt <= other.strIt); }
73 bool operator>=(
const StringIterator<T> &other) {
return (strIt >= other.strIt); }
75 T base()
const {
return strIt;}
84 using reverse_iterator = std::reverse_iterator<iterator>;
85 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
108 String(
const char *characters);
119 String(
const std::u32string &
string);
139 String& operator=(
const char *characters);
141 String& operator=(
const std::u32string &
string);
155 bool empty()
const {
return m_string.size() == 0; }
160 size_type size()
const;
165 size_type
length()
const {
return size(); };
174 void reserve(gd::String::size_type size) { m_string.reserve(size); }
188 String::iterator begin();
193 String::const_iterator begin()
const;
198 String::iterator end();
203 String::const_iterator end()
const;
221 static_assert(!std::is_same<T, std::string>::value,
"Can't use gd::String::From with std::string.");
223 std::ostringstream oss;
235 static_assert(!std::is_same<T, std::string>::value,
"Can't use gd::String::To with std::string.");
238 std::istringstream oss(m_string);
258 static String FromLocale(
const std::string &localizedString );
263 static String FromUTF32(
const std::u32string &
string );
268 static String FromUTF8(
const std::string &utf8Str );
273 static String FromWide(
const std::wstring &wstr );
289 std::string ToLocale()
const;
294 std::u32string ToUTF32()
const;
299 std::string ToUTF8()
const;
305 std::wstring ToWide()
const;
319 bool IsValid()
const;
325 String& ReplaceInvalid( value_type replacement = 0xfffd );
342 value_type operator[](
const size_type position )
const;
347 std::string&
Raw() {
return m_string; }
352 const std::string&
Raw()
const {
return m_string; }
357 const char*
c_str()
const {
return m_string.c_str(); }
370 String& operator+=(
const char *other );
372 String& operator+=( value_type character );
380 void push_back( value_type character );
406 String& replace( iterator i1, iterator i2,
const String &str );
415 String& replace( iterator i1, iterator i2, size_type n,
const char c );
424 String& replace( size_type pos, size_type len,
const String &str );
433 String& replace( size_type pos, size_type len,
const char c );
443 String& replace_if( iterator i1, iterator i2, std::function<
bool(char32_t)> p,
const String &str );
452 String& RemoveConsecutiveOccurrences(iterator i1, iterator i2,
const char c);
460 iterator erase( iterator first, iterator last );
467 iterator erase( iterator p );
475 void erase( size_type pos = 0, size_type len = npos );
500 std::vector<String> Split( value_type delimiter )
const;
528 String CapitalizeFirstLetter()
const;
544 String trimmedString(*
this);
546 return trimmedString;
555 String trimmedString(*
this);
557 return trimmedString;
584 String& Normalize(NormForm form = NFC);
589 String substr( size_type start = 0, size_type length = npos )
const;
594 size_type find(
const String &search, size_type pos = 0 )
const;
599 size_type find(
const char *search, size_type pos = 0 )
const;
604 size_type find(
const value_type search, size_type pos = 0 )
const;
609 size_type rfind(
const String &search, size_type pos = npos )
const;
614 size_type rfind(
const char *search, size_type pos = npos )
const;
619 size_type rfind(
const value_type &search, size_type pos = npos )
const;
628 size_type find_first_of(
const String &match, size_type startPos = 0 )
const;
637 size_type find_first_not_of(
const String ¬_match, size_type startPos = 0 )
const;
647 size_type find_last_of(
const String &match, size_type endPos = npos )
const;
657 size_type find_last_not_of(
const String ¬_match, size_type endPos = npos )
const;
662 int compare(
const String &other )
const;
671 size_type FindCaseInsensitive(
const String &search, size_type pos = 0 )
const;
678 std::string m_string;
691 String GD_CORE_API operator+(String lhs,
const String &rhs);
698 String GD_CORE_API operator+(String lhs,
const char *rhs);
705 String GD_CORE_API operator+(
const char *lhs,
const String &rhs);
707 const String& GD_CORE_API operator||(
const String &lhs,
const String &rhs);
709 String GD_CORE_API operator||(String lhs,
const char *rhs);
721 bool GD_CORE_API operator==(
const String &lhs,
const String &rhs );
723 bool GD_CORE_API operator==(
const String &lhs,
const char *rhs );
725 bool GD_CORE_API operator==(
const char *lhs,
const String &rhs );
728 bool GD_CORE_API operator!=(
const String &lhs,
const String &rhs );
730 bool GD_CORE_API operator!=(
const String &lhs,
const char *rhs );
732 bool GD_CORE_API operator!=(
const char *lhs,
const String &rhs );
735 bool GD_CORE_API operator<(
const String &lhs,
const String &rhs );
737 bool GD_CORE_API operator<(
const String &lhs,
const char *rhs );
739 bool GD_CORE_API operator<(
const char *lhs,
const String &rhs );
742 bool GD_CORE_API operator<=(
const String &lhs,
const String &rhs );
744 bool GD_CORE_API operator<=(
const String &lhs,
const char *rhs );
746 bool GD_CORE_API operator<=(
const char *lhs,
const String &rhs );
749 bool GD_CORE_API operator>(
const String &lhs,
const String &rhs );
751 bool GD_CORE_API operator>(
const String &lhs,
const char *rhs );
753 bool GD_CORE_API operator>(
const char *lhs,
const String &rhs );
756 bool GD_CORE_API operator>=(
const String &lhs,
const String &rhs );
758 bool GD_CORE_API operator>=(
const String &lhs,
const char *rhs );
760 bool GD_CORE_API operator>=(
const char *lhs,
const String &rhs );
780 std::ostream& GD_CORE_API
operator<<(std::ostream &os,
const String &str);
788 std::istream& GD_CORE_API operator>>(std::istream &is, String &str);
800 bool GD_CORE_API CaseSensitiveEquiv( String lhs, String rhs,
bool compat =
true );
807 bool GD_CORE_API CaseInsensitiveEquiv(
const String &lhs,
const String &rhs,
bool compat =
true );
816 template <>
struct GD_CORE_API hash<
gd::String>
820 return hash<std::string>()(x.
Raw());
String represents an UTF8 encoded string.
Definition: String.h:31
const std::string & Raw() const
Get the raw UTF8-encoded std::string.
Definition: String.h:352
static String From(T value)
Method to create a gd::String from a number (float, double, int, ...)
Definition: String.h:219
std::string & Raw()
Get the raw UTF8-encoded std::string.
Definition: String.h:347
size_type find_first_not_of(const String ¬_match, size_type startPos=0) const
Searches the string for the first character that doesn't match any of the characters specified in its...
Definition: String.cpp:583
void clear()
Clear the string.
Definition: String.h:172
String LeftTrim(const gd::String &chars=" \t\n\v\f\r")
Removes the specified characters (by default all the "whitespaces" and line breaks) from the beginnin...
Definition: String.h:542
String RightTrim(const gd::String &chars=" \t\n\v\f\r")
Removes the specified characters (by default all the "whitespaces" and line breaks) from the end of t...
Definition: String.h:553
String Trim(const gd::String &chars=" \t\n\v\f\r")
Removes the specified characters (by default all the "whitespaces" and line breaks) from the beginnin...
Definition: String.h:564
size_type find_last_not_of(const String ¬_match, size_type endPos=npos) const
Searches the string for the last character that doesn't match any of the characters specified in its ...
Definition: String.cpp:617
bool empty() const
Returns true if the string is empty.
Definition: String.h:155
NormForm
Definition: String.h:573
@ NFD
Normalization Form Decomposition: characters are decomposed by canonical equivalence,...
Definition: String.h:574
@ NFKC
Normalization Form Compatibility Composition: characters are decomposed by compatibility,...
Definition: String.h:577
@ NFKD
Normalization Form Compatibility Decomposition: characters are decomposed by compatibility,...
Definition: String.h:576
@ NFC
Normalization Form Composition: characters are decomposed and then recomposed by canonical equivalenc...
Definition: String.h:575
iterator erase(iterator first, iterator last)
Erase the characters between first and last (last not included).
Definition: String.cpp:328
const char * c_str() const
Get the C-string.
Definition: String.h:357
T To() const
Method to convert the string to a number.
Definition: String.h:233
size_type length() const
Returns the string's length.
Definition: String.h:165
Definition: CommonTools.h:24
std::ostream & operator<<(std::ostream &os, ExpressionCompletionDescription const &value)
Turn an ExpressionCompletionDescription to a string.
Definition: ExpressionCompletionFinder.cpp:19