Boost.UI
User Interface Boost library
|
Go to the documentation of this file.
8 #ifndef BOOST_UI_STRING_HPP
9 #define BOOST_UI_STRING_HPP
13 #ifdef BOOST_HAS_PRAGMA_ONCE
19 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
20 #include <initializer_list>
23 #ifndef BOOST_UI_NO_STD_HASH
34 #define BOOST_UI_NO_STRING_DESTRUCTIVE
39 #define BOOST_UI_NO_CAST_FROM_ASCII
59 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
68 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
72 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
73 uistring(std::initializer_list<char> list)
83 uistring(
const wchar_t* str);
84 uistring(
const std::wstring& str);
85 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
95 #ifndef BOOST_NO_CXX11_CHAR16_T
96 uistring(
const char16_t* str) { init(std::u16string(str)); }
97 uistring(
const std::u16string& str) { init(str); }
98 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
109 #ifndef BOOST_NO_CXX11_CHAR32_T
110 uistring(
const char32_t* str) { init(std::u32string(str)); }
112 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
127 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
140 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
141 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
142 uistring& assign(std::initializer_list<char> list)
147 uistring& operator=(std::initializer_list<char> list) {
return assign(list); }
161 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
162 uistring& append(size_type count,
char ch);
164 uistring& append(size_type count,
wchar_t ch);
165 #ifndef BOOST_NO_CXX11_CHAR16_T
167 {
return append(count,
static_cast<wchar_t>(ch)); }
169 #ifndef BOOST_NO_CXX11_CHAR32_T
171 {
return append(count,
static_cast<wchar_t>(ch)); }
173 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
174 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
175 uistring& append(std::initializer_list<char> list)
177 for ( std::initializer_list<char>::const_iterator i = list.begin();
178 i != list.end(); ++i )
183 uistring& operator+=(std::initializer_list<char> list) {
return append(list); }
187 for ( std::initializer_list<wchar_t>::const_iterator i = list.begin();
188 i != list.end(); ++i )
194 #ifndef BOOST_NO_CXX11_CHAR16_T
197 for ( std::initializer_list<char16_t>::const_iterator i = list.begin();
198 i != list.end(); ++i )
205 #ifndef BOOST_NO_CXX11_CHAR32_T
208 for ( std::initializer_list<char32_t>::const_iterator i = list.begin();
209 i != list.end(); ++i )
220 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
221 void push_back(
char ch);
222 uistring& operator+=(
char ch) { push_back(ch);
return *
this; }
224 void push_back(
wchar_t ch);
226 #ifndef BOOST_NO_CXX11_CHAR16_T
230 #ifndef BOOST_NO_CXX11_CHAR32_T
237 int compare(
const uistring& other)
const BOOST_NOEXCEPT;
239 {
return compare(other) == 0; }
241 {
return compare(other) != 0; }
243 {
return compare(other) < 0; }
245 {
return compare(other) <= 0; }
247 {
return compare(other) > 0; }
249 {
return compare(other) >= 0; }
256 bool empty() const BOOST_NOEXCEPT;
259 void clear() BOOST_NOEXCEPT;
262 void shrink_to_fit();
269 template <class charT>
270 std::basic_string<charT> utf() const;
273 template <class charT>
274 std::basic_string<charT> basic_string() const;
277 std::
string u8string() const;
279 #ifndef BOOST_UI_NO_STRING_DESTRUCTIVE
280 std::string asciistring()
const;
285 std::string string()
const;
289 std::wstring wstring()
const;
291 #ifndef BOOST_NO_CXX11_CHAR16_T
292 std::u16string u16string()
const
294 {
return xstring<std::u16string>(); }
297 #ifndef BOOST_NO_CXX11_CHAR32_T
298 std::u32string u32string()
const
300 {
return xstring<std::u32string>(); }
314 void init(
const std::wstring& str);
316 static uistring make_from_utf8(
const char* str);
317 static uistring make_from_ascii(
const char* str);
319 template <
class String>
320 void init(
const String& str)
323 wstr.reserve(str.size());
324 for (
typename String::const_iterator iter = str.begin();
325 iter != str.end(); ++iter )
326 wstr.push_back(
static_cast<wchar_t>(*iter));
330 template <
class String>
331 String xstring()
const
333 const std::wstring wstr = wstring();
335 result.reserve(wstr.size());
336 for ( std::wstring::const_iterator iter = wstr.begin();
337 iter != wstr.end(); ++iter )
338 result.push_back(*iter);
346 friend class native_helper;
356 #ifndef BOOST_UI_NO_STRING_DESTRUCTIVE
370 #ifndef BOOST_NO_CXX11_CHAR16_T
380 #ifndef BOOST_NO_CXX11_CHAR32_T
415 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
418 return std::move(lhs.append(rhs));
423 result.
append(std::move(rhs));
429 return std::move(lhs.append(rhs));
433 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
434 inline uistring
operator+(
const uistring& lhs,
char rhs)
436 uistring result(lhs);
437 result.push_back(rhs);
440 inline uistring
operator+(
const uistring& lhs,
const char* rhs)
442 uistring result(lhs);
446 inline uistring
operator+(
char lhs,
const uistring& rhs)
453 inline uistring
operator+(
const char* lhs,
const uistring& rhs)
487 #ifndef BOOST_NO_CXX11_CHAR16_T
515 #ifndef BOOST_NO_CXX11_CHAR32_T
544 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
545 #ifndef BOOST_UI_NO_CAST_FROM_ASCII
546 inline uistring
operator+(uistring&& lhs,
char rhs)
548 return std::move(lhs.append(1, rhs));
550 inline uistring
operator+(uistring&& lhs,
const char* rhs)
552 return std::move(lhs.append(rhs));
557 return std::move(lhs.append(1, rhs));
561 return std::move(lhs.append(rhs));
563 #ifndef BOOST_NO_CXX11_CHAR16_T
566 return std::move(lhs.append(1, rhs));
570 return std::move(lhs.append(rhs));
573 #ifndef BOOST_NO_CXX11_CHAR32_T
576 return std::move(lhs.append(1, rhs));
580 return std::move(lhs.append(rhs));
583 #endif // BOOST_NO_CXX11_RVALUE_REFERENCES
590 BOOST_UI_DECL uistring
to_uistring(
unsigned int value);
592 BOOST_UI_DECL uistring
to_uistring(
unsigned long value);
593 BOOST_UI_DECL uistring
to_uistring(
long long value);
594 BOOST_UI_DECL uistring
to_uistring(
unsigned long long value);
597 BOOST_UI_DECL uistring
to_uistring(
long double value);
602 BOOST_UI_DECL std::size_t
hash_value(
const uistring& value);
614 #ifndef BOOST_UI_NO_STD_HASH
619 :
public std::unary_function<boost::ui::uistring, std::size_t>
624 return std::hash<std::wstring>()(key.
wstring());
632 #endif // BOOST_UI_STRING_HPP
Helper class to convert string between UI and application logic only.
Definition: string.hpp:49
std::size_t size_type
Unsigned integral type.
Definition: string.hpp:53
uistring & operator+=(char32_t ch)
Appends character to the end of string.
Definition: string.hpp:232
bool operator<=(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:244
uistring & operator=(uistring &&other)
Assigns other string to this string.
Definition: string.hpp:133
std::size_t operator()(const boost::ui::uistring &key) const
Calculates the hash of the boost::ui::uistring.
Definition: string.hpp:622
std::u32string u32string() const
Returns UTF-32 std::u32string.
Definition: string.hpp:299
uistring & operator+=(char16_t ch)
Appends character to the end of string.
Definition: string.hpp:228
uistring & append(size_type count, char32_t ch)
Appends characters to the end of string.
Definition: string.hpp:170
uistring(const char16_t *str)
Constructs uistring from UTF-16 string.
Definition: string.hpp:96
std::string u8string() const
Returns UTF-8 encoded string.
std::basic_string< charT > basic_string() const
Returns std::basic_string<charT>
Boost C++ libraries namespace.
Definition: window.hpp:19
void push_back(char32_t ch)
Appends character to the end of string.
Definition: string.hpp:231
bool operator>(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:246
void push_back(wchar_t ch)
Appends character to the end of string.
void clear() noexcept
Clears the contents.
uistring & append(std::initializer_list< wchar_t > list)
Appends characters to the end of string.
Definition: string.hpp:185
void push_back(char16_t ch)
Appends character to the end of string.
Definition: string.hpp:227
bool operator<(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:242
uistring(const std::u16string &str)
Constructs uistring from UTF-16 string.
Definition: string.hpp:97
uistring & operator=(std::initializer_list< wchar_t > list)
Assigns other string to this string.
Definition: string.hpp:154
std::size_t hash_value(const uistring &value)
Returns hash of uistring for boost::hash.
uistring & assign(uistring &&other)
Assigns other string to this string.
Definition: string.hpp:128
uistring & append(std::initializer_list< char16_t > list)
Appends characters to the end of string.
Definition: string.hpp:195
bool operator==(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:238
uistring & operator+=(std::initializer_list< char32_t > list)
Appends characters to the end of string.
Definition: string.hpp:214
bool operator>=(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:248
uistring operator+(const uistring &lhs, const uistring &rhs)
Concatenates two strings or the string and the character.
Definition: string.hpp:408
uistring(uistring &&other)
Constructs uistring from other uistring.
Definition: string.hpp:60
uistring & append(std::initializer_list< char32_t > list)
Appends characters to the end of string.
Definition: string.hpp:206
uistring(const std::u32string &str)
Constructs uistring from UTF-32 string.
Definition: string.hpp:111
native_handle_type native_handle()
Returns the implementation-defined underlying string handle.
Definition: string.hpp:308
uistring ascii(const char *str)
Constructs uistring from 7-bit ASCII encoded string.
Definition: string.hpp:402
uistring(std::initializer_list< wchar_t > list)
Constructs uistring from Unicode wide char string.
Definition: string.hpp:86
std::wstring wstring() const
Returns Unicode wide std::wstring.
uistring u8uistring(const char *str)
Constructs uistring from UTF-8 encoded string.
Definition: string.hpp:392
uistring(std::initializer_list< char32_t > list)
Constructs uistring from UTF-32 string.
Definition: string.hpp:113
uistring & operator=(const uistring &other)
Assigns other string to this string.
Definition: string.hpp:126
std::u16string u16string() const
Returns UTF-16 std::u16string.
Definition: string.hpp:293
uistring & assign(std::initializer_list< wchar_t > list)
Assigns other string to this string.
Definition: string.hpp:149
std::basic_string< charT > utf() const
Returns UTF-8/16/32 encoded string Returns UTF-8 encoded string if charT is char, returns UTF-16 enco...
uistring to_uistring(int value)
Converts numeric value to uistring.
Standard C++ namespace.
Definition: string_io.hpp:117
uistring asciiuistring(const char *str)
Constructs uistring from 7-bit ASCII encoded string.
Definition: string.hpp:400
uistring & append(const uistring &str)
Appends characters to the end of string.
uistring & append(size_type count, char16_t ch)
Appends characters to the end of string.
Definition: string.hpp:166
uistring & operator+=(std::initializer_list< char16_t > list)
Appends characters to the end of string.
Definition: string.hpp:203
void swap(const uistring &other)
Exchanges the contents of strings.
uistring & operator+=(const uistring &str)
Appends characters to the end of string.
Definition: string.hpp:160
uistring(const char32_t *str)
Constructs uistring from UTF-32 string.
Definition: string.hpp:110
uistring(std::initializer_list< char16_t > list)
Constructs uistring from UTF-16 string.
Definition: string.hpp:99
void swap(boost::ui::uistring &a, boost::ui::uistring &b)
Specializes the std::swap algorithm.
Definition: string.hpp:612
uistring & operator+=(wchar_t ch)
Appends character to the end of string.
Definition: string.hpp:225
uistring utf8(const char *str)
Constructs uistring from UTF-8 encoded string.
Definition: string.hpp:394
void * native_handle_type
Implementation-defined string type.
Definition: string.hpp:305
uistring & operator+=(std::initializer_list< wchar_t > list)
Appends characters to the end of string.
Definition: string.hpp:193
bool operator!=(const uistring &other) const noexcept
Lexicographically compares two strings.
Definition: string.hpp:240
const native_handle_type native_handle() const
Returns the implementation-defined underlying string handle.
Definition: string.hpp:309