ustring.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/ustring.h
  3. // Purpose: interface of wxUString
  4. // Author: Robert Roebling
  5. // Copyright: (c) Robert Roebling
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. /**
  9. @class wxUString
  10. wxUString is a class representing a Unicode character string where
  11. each character is stored using a 32-bit value. This is different from
  12. wxString which may store a character either as a UTF-8 or as a UTF-16
  13. sequence and different from @c std::string which stores a string
  14. as a sequence of simple 8-bit characters and also different from
  15. @c std::wstring which stores the string differently depending on
  16. the definition of wchar_t.
  17. The main purpose of wxUString is a to give users a Unicode string
  18. class that has O(1) access to its content, to be identical on all
  19. platforms and to be easily convertable to wxString as well as other
  20. ways to store strings (C string literals, wide character
  21. string literals, character buffer, etc) by providing several overloads
  22. and built-in conversions to and from the various string formats.
  23. wxUString derives from @c std::basic_string<wxChar32> and therefore
  24. offers the complete API of @c std::string.
  25. @library{wxbase}
  26. @category{data}
  27. @see wxString, @ref overview_string "wxString overview", @ref overview_unicode
  28. "Unicode overview"
  29. */
  30. class WXDLLIMPEXP_BASE wxUString: public std::basic_string<wxChar32>
  31. {
  32. public:
  33. /**
  34. Default constructor.
  35. */
  36. wxUString();
  37. /**
  38. Copy constructor.
  39. */
  40. wxUString( const wxUString &str );
  41. /**
  42. Constructs a string from a 32-bit string literal.
  43. */
  44. wxUString( const wxChar32 *str );
  45. /**
  46. Constructs a string from 32-bit string buffer.
  47. */
  48. wxUString( const wxU32CharBuffer &buf );
  49. /**
  50. Constructs a string from C string literal using wxConvLibc to convert it to Unicode.
  51. */
  52. wxUString( const char *str );
  53. /**
  54. Constructs a string from C string buffer using wxConvLibc to convert it to Unicode.
  55. */
  56. wxUString( const wxCharBuffer &buf );
  57. /**
  58. Constructs a string from C string literal using @a conv to convert it to Unicode.
  59. */
  60. wxUString( const char *str, const wxMBConv &conv );
  61. /**
  62. Constructs a string from C string literal using @a conv to convert it to Unicode.
  63. */
  64. wxUString( const wxCharBuffer &buf, const wxMBConv &conv );
  65. /**
  66. Constructs a string from UTF-16 string literal
  67. */
  68. wxUString( const wxChar16 *str );
  69. /**
  70. Constructs a string from UTF-16 string buffer
  71. */
  72. wxUString( const wxU16CharBuffer &buf );
  73. /**
  74. Constructs a string from wxString.
  75. */
  76. wxUString( const wxString &str );
  77. /**
  78. Constructs a string from using wxConvLibc to convert it to Unicode.
  79. */
  80. wxUString( char ch );
  81. /**
  82. Constructs a string from a UTF-16 character.
  83. */
  84. wxUString( wxChar16 ch );
  85. /**
  86. Constructs a string from 32-bit Unicode character.
  87. */
  88. wxUString( wxChar32 ch );
  89. /**
  90. Constructs a string from wxUniChar (returned by wxString's access operator)
  91. */
  92. wxUString( wxUniChar ch );
  93. /**
  94. Constructs a string from wxUniCharRef (returned by wxString's access operator)
  95. */
  96. wxUString( wxUniCharRef ch );
  97. /**
  98. Constructs a string from @a n characters @a ch.
  99. */
  100. wxUString( size_t n, char ch );
  101. /**
  102. Constructs a string from @a n characters @a ch.
  103. */
  104. wxUString( size_t n, wxChar16 ch );
  105. /**
  106. Constructs a string from @a n characters @a ch.
  107. */
  108. wxUString( size_t n, wxChar32 ch );
  109. /**
  110. Constructs a string from @a n characters @a ch.
  111. */
  112. wxUString( size_t n, wxUniChar ch );
  113. /**
  114. Constructs a string from @a n characters @a ch.
  115. */
  116. wxUString( size_t n, wxUniCharRef ch );
  117. /**
  118. Static construction of a wxUString from a 7-bit ASCII string
  119. */
  120. static wxUString FromAscii( const char *str, size_t n );
  121. /**
  122. Static construction of a wxUString from a 7-bit ASCII string
  123. */
  124. static wxUString FromAscii( const char *str );
  125. /**
  126. Static construction of a wxUString from a UTF-8 encoded string
  127. */
  128. static wxUString FromUTF8( const char *str, size_t n );
  129. /**
  130. Static construction of a wxUString from a UTF-8 encoded string
  131. */
  132. static wxUString FromUTF8( const char *str );
  133. /**
  134. Static construction of a wxUString from a UTF-16 encoded string
  135. */
  136. static wxUString FromUTF16( const wxChar16 *str, size_t n );
  137. /**
  138. Static construction of a wxUString from a UTF-16 encoded string
  139. */
  140. static wxUString FromUTF16( const wxChar16 *str );
  141. /**
  142. Assignment from a 7-bit ASCII string literal
  143. */
  144. wxUString &assignFromAscii( const char *str );
  145. /**
  146. Assignment from a 7-bit ASCII string literal
  147. */
  148. wxUString &assignFromAscii( const char *str, size_t n );
  149. /**
  150. Assignment from a UTF-8 string literal
  151. */
  152. wxUString &assignFromUTF8( const char *str );
  153. /**
  154. Assignment from a UTF-8 string literal
  155. */
  156. wxUString &assignFromUTF8( const char *str, size_t n );
  157. /**
  158. Assignment from a UTF-16 string literal
  159. */
  160. wxUString &assignFromUTF16( const wxChar16* str );
  161. /**
  162. Assignment from a UTF-16 string literal
  163. */
  164. wxUString &assignFromUTF16( const wxChar16* str, size_t n );
  165. /**
  166. Assignment from a C string literal using wxConvLibc
  167. */
  168. wxUString &assignFromCString( const char* str );
  169. /**
  170. Assignment from a C string literal using @a conv
  171. */
  172. wxUString &assignFromCString( const char* str, const wxMBConv &conv );
  173. /**
  174. Conversion to a UTF-8 string
  175. */
  176. wxCharBuffer utf8_str() const;
  177. /**
  178. Conversion to a UTF-16 string
  179. */
  180. wxU16CharBuffer utf16_str() const;
  181. /**
  182. Conversion to a wide character string (either UTF-16
  183. or UCS-4, depending on the size of wchar_t).
  184. */
  185. wxWCharBuffer wc_str() const;
  186. /**
  187. Implicit conversion to wxString.
  188. */
  189. operator wxString() const;
  190. /**
  191. wxUString assignment. wxUString additionally provides overloads for
  192. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  193. single and repeated characters etc.
  194. */
  195. wxUString &assign( const wxUString &str );
  196. /**
  197. Appending. wxUString additionally provides overloads for
  198. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  199. single and repeated characters etc.
  200. */
  201. wxUString &append( const wxUString &s );
  202. /**
  203. Insertion. wxUString additionally provides overloads for
  204. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  205. single characters etc.
  206. */
  207. wxUString &insert( size_t pos, const wxUString &s );
  208. /**
  209. Assignment operator. wxUString additionally provides overloads for
  210. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  211. single characters etc.
  212. */
  213. inline wxUString& operator=(const wxUString& s);
  214. /**
  215. Concatenation operator. wxUString additionally provides overloads for
  216. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  217. single characters etc.
  218. */
  219. inline wxUString& operator+=(const wxUString& s);
  220. };
  221. /**
  222. Concatenation operator. wxUString additionally provides overloads for
  223. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  224. single characters etc.
  225. */
  226. inline wxUString operator+(const wxUString &s1, const wxUString &s2);
  227. /**
  228. Equality operator. wxUString additionally provides overloads for
  229. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  230. single characters etc.
  231. */
  232. inline bool operator==(const wxUString& s1, const wxUString& s2);
  233. /**
  234. Inequality operator. wxUString additionally provides overloads for
  235. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  236. single characters etc.
  237. */
  238. inline bool operator!=(const wxUString& s1, const wxUString& s2);
  239. /**
  240. Comparison operator. wxUString additionally provides overloads for
  241. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  242. single characters etc.
  243. */
  244. inline bool operator< (const wxUString& s1, const wxUString& s2);
  245. /**
  246. Comparison operator. wxUString additionally provides overloads for
  247. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  248. single characters etc.
  249. */
  250. inline bool operator> (const wxUString& s1, const wxUString& s2);
  251. /**
  252. Comparison operator. wxUString additionally provides overloads for
  253. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  254. single characters etc.
  255. */
  256. inline bool operator<=(const wxUString& s1, const wxUString& s2);
  257. /**
  258. Comparison operator. wxUString additionally provides overloads for
  259. wxString, C string, UTF-16 strings, 32-bit strings, char buffers,
  260. single characters etc.
  261. */
  262. inline bool operator>=(const wxUString& s1, const wxUString& s2);