9 #ifndef GDCORE_UTF8_STRING_H
10 #define GDCORE_UTF8_STRING_H
19 #include "GDCore/Utf8/utf8.h"
37 using value_type = char32_t;
38 using reference = char32_t&;
39 using const_reference =
const char32_t&;
40 using pointer = char32_t*;
41 using const_pointer =
const char32_t*;
43 using size_type = std::string::size_type;
44 using difference_type = std::string::difference_type;
46 static constexpr size_type npos = -1;
49 class GD_CORE_API
StringIterator :
public std::iterator<std::bidirectional_iterator_tag, String::value_type, String::difference_type>
62 String::value_type operator*() {return ::utf8::unchecked::peek_next(strIt);}
66 StringIterator<T>& operator--() { ::utf8::unchecked::prior(strIt);
return *
this; }
69 bool operator==(
const StringIterator<T> &other) {
return (strIt == other.strIt); }
73 bool operator<=(
const StringIterator<T> &other) {
return (strIt <= other.strIt); }
75 bool operator>=(
const StringIterator<T> &other) {
return (strIt >= other.strIt); }
77 T base()
const {
return strIt;}
86 using reverse_iterator = std::reverse_iterator<iterator>;
87 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
110 String(
const char *characters);
121 String(
const std::u32string &
string);
141 String& operator=(
const char *characters);
143 String& operator=(
const std::u32string &
string);
157 bool empty()
const {
return m_string.size() == 0; }
162 size_type size()
const;
167 size_type
length()
const {
return size(); };
176 void reserve(gd::String::size_type size) { m_string.reserve(size); }
190 String::iterator begin();
195 String::const_iterator begin()
const;
200 String::iterator end();
205 String::const_iterator end()
const;
223 static_assert(!std::is_same<T, std::string>::value,
"Can't use gd::String::From with std::string.");
225 std::ostringstream oss;
237 static_assert(!std::is_same<T, std::string>::value,
"Can't use gd::String::To with std::string.");
240 std::istringstream oss(m_string);
260 static String FromLocale(
const std::string &localizedString );
265 static String FromUTF32(
const std::u32string &
string );
270 static String FromUTF8(
const std::string &utf8Str );
275 static String FromWide(
const std::wstring &wstr );
291 std::string ToLocale()
const;
296 std::u32string ToUTF32()
const;
301 std::string ToUTF8()
const;
307 std::wstring ToWide()
const;
321 bool IsValid()
const;
327 String& ReplaceInvalid( value_type replacement = 0xfffd );
344 value_type operator[](
const size_type position )
const;
349 std::string&
Raw() {
return m_string; }
354 const std::string&
Raw()
const {
return m_string; }
359 const char*
c_str()
const {
return m_string.c_str(); }
372 String& operator+=(
const char *other );
374 String& operator+=( value_type character );
382 void push_back( value_type character );
408 String& replace( iterator i1, iterator i2,
const String &str );
417 String& replace( iterator i1, iterator i2, size_type n,
const char c );
426 String& replace( size_type pos, size_type len,
const String &str );
435 String& replace( size_type pos, size_type len,
const char c );
445 String& replace_if( iterator i1, iterator i2, std::function<
bool(char32_t)> p,
const String &str );
454 String& RemoveConsecutiveOccurrences(iterator i1, iterator i2,
const char c);
462 iterator erase( iterator first, iterator last );
469 iterator erase( iterator p );
477 void erase( size_type pos = 0, size_type len = npos );
502 std::vector<String> Split( value_type delimiter )
const;
530 String CapitalizeFirstLetter()
const;
546 String trimmedString(*
this);
548 return trimmedString;
557 String trimmedString(*
this);
559 return trimmedString;
586 String& Normalize(NormForm form = NFC);
591 String substr( size_type start = 0, size_type length = npos )
const;
596 size_type find(
const String &search, size_type pos = 0 )
const;
601 size_type find(
const char *search, size_type pos = 0 )
const;
606 size_type find(
const value_type search, size_type pos = 0 )
const;
611 size_type rfind(
const String &search, size_type pos = npos )
const;
616 size_type rfind(
const char *search, size_type pos = npos )
const;
621 size_type rfind(
const value_type &search, size_type pos = npos )
const;
630 size_type find_first_of(
const String &match, size_type startPos = 0 )
const;
639 size_type find_first_not_of(
const String ¬_match, size_type startPos = 0 )
const;
649 size_type find_last_of(
const String &match, size_type endPos = npos )
const;
659 size_type find_last_not_of(
const String ¬_match, size_type endPos = npos )
const;
664 int compare(
const String &other )
const;
673 size_type FindCaseInsensitive(
const String &search, size_type pos = 0 )
const;
680 std::string m_string;
693 String GD_CORE_API operator+(String lhs,
const String &rhs);
700 String GD_CORE_API operator+(String lhs,
const char *rhs);
707 String GD_CORE_API operator+(
const char *lhs,
const String &rhs);
709 const String& GD_CORE_API operator||(
const String &lhs,
const String &rhs);
711 String GD_CORE_API operator||(String lhs,
const char *rhs);
723 bool GD_CORE_API operator==(
const String &lhs,
const String &rhs );
725 bool GD_CORE_API operator==(
const String &lhs,
const char *rhs );
727 bool GD_CORE_API operator==(
const char *lhs,
const String &rhs );
730 bool GD_CORE_API operator!=(
const String &lhs,
const String &rhs );
732 bool GD_CORE_API operator!=(
const String &lhs,
const char *rhs );
734 bool GD_CORE_API operator!=(
const char *lhs,
const String &rhs );
737 bool GD_CORE_API operator<(
const String &lhs,
const String &rhs );
739 bool GD_CORE_API operator<(
const String &lhs,
const char *rhs );
741 bool GD_CORE_API operator<(
const char *lhs,
const String &rhs );
744 bool GD_CORE_API operator<=(
const String &lhs,
const String &rhs );
746 bool GD_CORE_API operator<=(
const String &lhs,
const char *rhs );
748 bool GD_CORE_API operator<=(
const char *lhs,
const String &rhs );
751 bool GD_CORE_API operator>(
const String &lhs,
const String &rhs );
753 bool GD_CORE_API operator>(
const String &lhs,
const char *rhs );
755 bool GD_CORE_API operator>(
const char *lhs,
const String &rhs );
758 bool GD_CORE_API operator>=(
const String &lhs,
const String &rhs );
760 bool GD_CORE_API operator>=(
const String &lhs,
const char *rhs );
762 bool GD_CORE_API operator>=(
const char *lhs,
const String &rhs );
782 std::ostream& GD_CORE_API
operator<<(std::ostream &os,
const String &str);
790 std::istream& GD_CORE_API operator>>(std::istream &is, String &str);
802 bool GD_CORE_API CaseSensitiveEquiv( String lhs, String rhs,
bool compat =
true );
809 bool GD_CORE_API CaseInsensitiveEquiv(
const String &lhs,
const String &rhs,
bool compat =
true );
818 template <>
struct GD_CORE_API hash<
gd::String>
822 return hash<std::string>()(x.
Raw());
String represents an UTF8 encoded string.
Definition: String.h:33
const std::string & Raw() const
Get the raw UTF8-encoded std::string.
Definition: String.h:354
static String From(T value)
Method to create a gd::String from a number (float, double, int, ...)
Definition: String.h:221
std::string & Raw()
Get the raw UTF8-encoded std::string.
Definition: String.h:349
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:585
void clear()
Clear the string.
Definition: String.h:174
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:544
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:555
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:566
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:619
bool empty() const
Returns true if the string is empty.
Definition: String.h:157
NormForm
Definition: String.h:575
@ NFD
Normalization Form Decomposition: characters are decomposed by canonical equivalence,...
Definition: String.h:576
@ NFKC
Normalization Form Compatibility Composition: characters are decomposed by compatibility,...
Definition: String.h:579
@ NFKD
Normalization Form Compatibility Decomposition: characters are decomposed by compatibility,...
Definition: String.h:578
@ NFC
Normalization Form Composition: characters are decomposed and then recomposed by canonical equivalenc...
Definition: String.h:577
iterator erase(iterator first, iterator last)
Erase the characters between first and last (last not included).
Definition: String.cpp:330
const char * c_str() const
Get the C-string.
Definition: String.h:359
T To() const
Method to convert the string to a number.
Definition: String.h:235
size_type length() const
Returns the string's length.
Definition: String.h:167
Definition: CommonTools.h:24
std::ostream & operator<<(std::ostream &os, ExpressionCompletionDescription const &value)
Turn an ExpressionCompletionDescription to a string.
Definition: ExpressionCompletionFinder.cpp:19