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;
238 static_assert(!std::is_same<T, std::string>::value,
"Can't use gd::String::To with std::string.");
241 std::istringstream oss(m_string);
261 static String FromLocale(
const std::string &localizedString );
266 static String FromUTF32(
const std::u32string &
string );
271 static String FromUTF8(
const std::string &utf8Str );
276 static String FromWide(
const std::wstring &wstr );
292 std::string ToLocale()
const;
297 std::u32string ToUTF32()
const;
302 std::string ToUTF8()
const;
308 std::wstring ToWide()
const;
322 bool IsValid()
const;
328 String& ReplaceInvalid( value_type replacement = 0xfffd );
345 value_type operator[](
const size_type position )
const;
350 std::string&
Raw() {
return m_string; }
355 const std::string&
Raw()
const {
return m_string; }
360 const char*
c_str()
const {
return m_string.c_str(); }
373 String& operator+=(
const char *other );
375 String& operator+=( value_type character );
383 void push_back( value_type character );
409 String& replace( iterator i1, iterator i2,
const String &str );
418 String& replace( iterator i1, iterator i2, size_type n,
const char c );
427 String& replace( size_type pos, size_type len,
const String &str );
436 String& replace( size_type pos, size_type len,
const char c );
446 String& replace_if( iterator i1, iterator i2, std::function<
bool(char32_t)> p,
const String &str );
455 String& RemoveConsecutiveOccurrences(iterator i1, iterator i2,
const char c);
463 iterator erase( iterator first, iterator last );
470 iterator erase( iterator p );
478 void erase( size_type pos = 0, size_type len = npos );
503 std::vector<String> Split( value_type delimiter )
const;
531 String CapitalizeFirstLetter()
const;
547 String trimmedString(*
this);
549 return trimmedString;
558 String trimmedString(*
this);
560 return trimmedString;
587 String& Normalize(NormForm form = NFC);
592 String substr( size_type start = 0, size_type length = npos )
const;
597 size_type find(
const String &search, size_type pos = 0 )
const;
602 size_type find(
const char *search, size_type pos = 0 )
const;
607 size_type find(
const value_type search, size_type pos = 0 )
const;
612 size_type rfind(
const String &search, size_type pos = npos )
const;
617 size_type rfind(
const char *search, size_type pos = npos )
const;
622 size_type rfind(
const value_type &search, size_type pos = npos )
const;
631 size_type find_first_of(
const String &match, size_type startPos = 0 )
const;
640 size_type find_first_not_of(
const String ¬_match, size_type startPos = 0 )
const;
650 size_type find_last_of(
const String &match, size_type endPos = npos )
const;
660 size_type find_last_not_of(
const String ¬_match, size_type endPos = npos )
const;
665 int compare(
const String &other )
const;
674 size_type FindCaseInsensitive(
const String &search, size_type pos = 0 )
const;
681 std::string m_string;
694 String GD_CORE_API operator+(String lhs,
const String &rhs);
701 String GD_CORE_API operator+(String lhs,
const char *rhs);
708 String GD_CORE_API operator+(
const char *lhs,
const String &rhs);
710 const String& GD_CORE_API operator||(
const String &lhs,
const String &rhs);
712 String GD_CORE_API operator||(String lhs,
const char *rhs);
724 bool GD_CORE_API operator==(
const String &lhs,
const String &rhs );
726 bool GD_CORE_API operator==(
const String &lhs,
const char *rhs );
728 bool GD_CORE_API operator==(
const char *lhs,
const String &rhs );
731 bool GD_CORE_API operator!=(
const String &lhs,
const String &rhs );
733 bool GD_CORE_API operator!=(
const String &lhs,
const char *rhs );
735 bool GD_CORE_API operator!=(
const char *lhs,
const String &rhs );
738 bool GD_CORE_API operator<(
const String &lhs,
const String &rhs );
740 bool GD_CORE_API operator<(
const String &lhs,
const char *rhs );
742 bool GD_CORE_API operator<(
const char *lhs,
const String &rhs );
745 bool GD_CORE_API operator<=(
const String &lhs,
const String &rhs );
747 bool GD_CORE_API operator<=(
const String &lhs,
const char *rhs );
749 bool GD_CORE_API operator<=(
const char *lhs,
const String &rhs );
752 bool GD_CORE_API operator>(
const String &lhs,
const String &rhs );
754 bool GD_CORE_API operator>(
const String &lhs,
const char *rhs );
756 bool GD_CORE_API operator>(
const char *lhs,
const String &rhs );
759 bool GD_CORE_API operator>=(
const String &lhs,
const String &rhs );
761 bool GD_CORE_API operator>=(
const String &lhs,
const char *rhs );
763 bool GD_CORE_API operator>=(
const char *lhs,
const String &rhs );
783 std::ostream& GD_CORE_API
operator<<(std::ostream &os,
const String &str);
791 std::istream& GD_CORE_API operator>>(std::istream &is, String &str);
803 bool GD_CORE_API CaseSensitiveEquiv( String lhs, String rhs,
bool compat =
true );
810 bool GD_CORE_API CaseInsensitiveEquiv(
const String &lhs,
const String &rhs,
bool compat =
true );
819 template <>
struct GD_CORE_API hash<
gd::String>
823 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:355
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:350
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:545
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:556
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:567
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:576
@ NFD
Normalization Form Decomposition: characters are decomposed by canonical equivalence,...
Definition: String.h:577
@ NFKC
Normalization Form Compatibility Composition: characters are decomposed by compatibility,...
Definition: String.h:580
@ NFKD
Normalization Form Compatibility Decomposition: characters are decomposed by compatibility,...
Definition: String.h:579
@ NFC
Normalization Form Composition: characters are decomposed and then recomposed by canonical equivalenc...
Definition: String.h:578
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:360
T To() const
Method to convert the string to a number.
Definition: String.h:236
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