* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,217 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * String class in ANSI (or rather, current Windows code page), UTF-8, and UTF-16 |
|
| 3 |
- * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com] |
|
| 4 |
- * Last modification on 2014-09-08 |
|
| 5 |
- */ |
|
| 6 |
- |
|
| 7 |
-#pragma once |
|
| 8 |
- |
|
| 9 |
-#include <string> |
|
| 10 |
-#include <cstring> |
|
| 11 |
-#include <cwchar> |
|
| 12 |
-#include "UtfConverter.h" |
|
| 13 |
-#include "UTFEncodeDecode.h" |
|
| 14 |
- |
|
| 15 |
-class String |
|
| 16 |
-{
|
|
| 17 |
-public: |
|
| 18 |
- String(const std::locale &L = std::locale::classic()) : ansi(""), utf8(""), utf16(L""), loc(L) { }
|
|
| 19 |
- String(const char *new_str, bool is_utf8 = false, const std::locale &L = std::locale::classic()) : ansi(is_utf8 ? DecodeFromUTF8(new_str, L) : new_str), utf8(is_utf8 ? new_str : EncodeToUTF8(new_str, L)), |
|
| 20 |
- utf16(UtfConverter::FromUtf8(utf8)), loc(L) { }
|
|
| 21 |
- String(const std::string &new_str, bool is_utf8 = false, const std::locale &L = std::locale::classic()) : ansi(is_utf8 ? DecodeFromUTF8(new_str, L) : new_str), utf8(is_utf8 ? new_str : EncodeToUTF8(new_str, L)), |
|
| 22 |
- utf16(UtfConverter::FromUtf8(utf8)), loc(L) { }
|
|
| 23 |
- String(const wchar_t *new_wstr, const std::locale &L = std::locale::classic()) : ansi(DecodeFromUTF8(UtfConverter::ToUtf8(new_wstr), L)), utf8(UtfConverter::ToUtf8(new_wstr)), utf16(new_wstr), loc(L) { }
|
|
| 24 |
- String(const std::wstring &new_wstr, const std::locale &L = std::locale::classic()) : ansi(DecodeFromUTF8(UtfConverter::ToUtf8(new_wstr), L)), utf8(UtfConverter::ToUtf8(new_wstr)), utf16(new_wstr), loc(L) { }
|
|
| 25 |
- bool empty() const { return this->utf8.empty(); }
|
|
| 26 |
- std::string GetAnsi() const { return this->ansi; }
|
|
| 27 |
- const char *GetAnsiC() const { return this->ansi.c_str(); }
|
|
| 28 |
- std::string GetStr() const { return this->utf8; }
|
|
| 29 |
- const char *GetStrC() const { return this->utf8.c_str(); }
|
|
| 30 |
- std::wstring GetWStr() const { return this->utf16; }
|
|
| 31 |
- const wchar_t *GetWStrC() const { return this->utf16.c_str(); }
|
|
| 32 |
- bool operator==(const String &str2) const |
|
| 33 |
- {
|
|
| 34 |
- return this->utf8 == str2.utf8; |
|
| 35 |
- } |
|
| 36 |
- String &operator=(const std::string &new_str) |
|
| 37 |
- {
|
|
| 38 |
- this->ansi = DecodeFromUTF8(new_str, this->loc); |
|
| 39 |
- this->utf8 = new_str; |
|
| 40 |
- this->utf16 = UtfConverter::FromUtf8(new_str); |
|
| 41 |
- return *this; |
|
| 42 |
- } |
|
| 43 |
- String &operator=(const std::wstring &new_wstr) |
|
| 44 |
- {
|
|
| 45 |
- this->utf8 = UtfConverter::ToUtf8(new_wstr); |
|
| 46 |
- this->ansi = DecodeFromUTF8(this->utf8, this->loc); |
|
| 47 |
- this->utf16 = new_wstr; |
|
| 48 |
- return *this; |
|
| 49 |
- } |
|
| 50 |
- String &operator=(const String &new_string) |
|
| 51 |
- {
|
|
| 52 |
- if (this != &new_string) |
|
| 53 |
- {
|
|
| 54 |
- this->ansi = new_string.ansi; |
|
| 55 |
- this->utf8 = new_string.utf8; |
|
| 56 |
- this->utf16 = new_string.utf16; |
|
| 57 |
- } |
|
| 58 |
- return *this; |
|
| 59 |
- } |
|
| 60 |
- String &SetISO8859_1(const std::string &new_str) |
|
| 61 |
- {
|
|
| 62 |
- this->ansi = new_str; |
|
| 63 |
- this->utf8 = EncodeToUTF8(new_str, this->loc); |
|
| 64 |
- this->utf16 = UtfConverter::FromUtf8(this->utf8); |
|
| 65 |
- return *this; |
|
| 66 |
- } |
|
| 67 |
- String operator+(const String &str2) const |
|
| 68 |
- {
|
|
| 69 |
- String new_string = String(*this); |
|
| 70 |
- new_string.ansi.append(str2.ansi); |
|
| 71 |
- new_string.utf8.append(str2.utf8); |
|
| 72 |
- new_string.utf16.append(str2.utf16); |
|
| 73 |
- return new_string; |
|
| 74 |
- } |
|
| 75 |
- String operator+(char chr) const |
|
| 76 |
- {
|
|
| 77 |
- String new_string = String(*this); |
|
| 78 |
- char str2[] = { chr, 0 };
|
|
| 79 |
- new_string.ansi.append(str2); |
|
| 80 |
- std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 81 |
- new_string.utf8.append(new_utf8); |
|
| 82 |
- new_string.utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 83 |
- return new_string; |
|
| 84 |
- } |
|
| 85 |
- String operator+(wchar_t wchr) const |
|
| 86 |
- {
|
|
| 87 |
- String new_string = String(*this); |
|
| 88 |
- wchar_t wstr2[] = { wchr, 0 };
|
|
| 89 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 90 |
- new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 91 |
- new_string.utf8.append(new_utf8); |
|
| 92 |
- new_string.utf16.append(wstr2); |
|
| 93 |
- return new_string; |
|
| 94 |
- } |
|
| 95 |
- String operator+(const char *str2) const |
|
| 96 |
- {
|
|
| 97 |
- String new_string = String(*this); |
|
| 98 |
- new_string.ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 99 |
- new_string.utf8.append(str2); |
|
| 100 |
- new_string.utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 101 |
- return new_string; |
|
| 102 |
- } |
|
| 103 |
- String operator+(const std::string &str2) const |
|
| 104 |
- {
|
|
| 105 |
- String new_string = String(*this); |
|
| 106 |
- new_string.ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 107 |
- new_string.utf8.append(str2); |
|
| 108 |
- new_string.utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 109 |
- return new_string; |
|
| 110 |
- } |
|
| 111 |
- String operator+(const wchar_t *wstr2) const |
|
| 112 |
- {
|
|
| 113 |
- String new_string = String(*this); |
|
| 114 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 115 |
- new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 116 |
- new_string.utf8.append(new_utf8); |
|
| 117 |
- new_string.utf16.append(wstr2); |
|
| 118 |
- return new_string; |
|
| 119 |
- } |
|
| 120 |
- String operator+(const std::wstring &wstr2) const |
|
| 121 |
- {
|
|
| 122 |
- String new_string = String(*this); |
|
| 123 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 124 |
- new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 125 |
- new_string.utf8.append(new_utf8); |
|
| 126 |
- new_string.utf16.append(wstr2); |
|
| 127 |
- return new_string; |
|
| 128 |
- } |
|
| 129 |
- String &operator+=(const String &str2) |
|
| 130 |
- {
|
|
| 131 |
- if (this != &str2) |
|
| 132 |
- {
|
|
| 133 |
- this->ansi.append(str2.ansi); |
|
| 134 |
- this->utf8.append(str2.utf8); |
|
| 135 |
- this->utf16.append(str2.utf16); |
|
| 136 |
- } |
|
| 137 |
- return *this; |
|
| 138 |
- } |
|
| 139 |
- String &operator+=(char chr) |
|
| 140 |
- {
|
|
| 141 |
- char str2[] = { chr, 0 };
|
|
| 142 |
- this->ansi.append(str2); |
|
| 143 |
- std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 144 |
- this->utf8.append(new_utf8); |
|
| 145 |
- this->utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 146 |
- return *this; |
|
| 147 |
- } |
|
| 148 |
- String &operator+=(wchar_t wchr) |
|
| 149 |
- {
|
|
| 150 |
- wchar_t wstr2[] = { wchr, 0 };
|
|
| 151 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 152 |
- this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 153 |
- this->utf8.append(new_utf8); |
|
| 154 |
- this->utf16.append(wstr2); |
|
| 155 |
- return *this; |
|
| 156 |
- } |
|
| 157 |
- String &operator+=(const char *str2) |
|
| 158 |
- {
|
|
| 159 |
- this->ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 160 |
- this->utf8.append(str2); |
|
| 161 |
- this->utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 162 |
- return *this; |
|
| 163 |
- } |
|
| 164 |
- String &operator+=(const std::string &str2) |
|
| 165 |
- {
|
|
| 166 |
- this->ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 167 |
- this->utf8.append(str2); |
|
| 168 |
- this->utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 169 |
- return *this; |
|
| 170 |
- } |
|
| 171 |
- String &operator+=(const wchar_t *wstr2) |
|
| 172 |
- {
|
|
| 173 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 174 |
- this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 175 |
- this->utf8.append(new_utf8); |
|
| 176 |
- this->utf16.append(wstr2); |
|
| 177 |
- return *this; |
|
| 178 |
- } |
|
| 179 |
- String &operator+=(const std::wstring &wstr2) |
|
| 180 |
- {
|
|
| 181 |
- std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 182 |
- this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 183 |
- this->utf8.append(new_utf8); |
|
| 184 |
- this->utf16.append(wstr2); |
|
| 185 |
- return *this; |
|
| 186 |
- } |
|
| 187 |
- String &AppendISO8859_1(const std::string &str2) |
|
| 188 |
- {
|
|
| 189 |
- this->ansi.append(str2); |
|
| 190 |
- std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 191 |
- this->utf8.append(new_utf8); |
|
| 192 |
- this->utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 193 |
- return *this; |
|
| 194 |
- } |
|
| 195 |
- String Substring(size_t pos = 0, size_t n = std::string::npos) const |
|
| 196 |
- {
|
|
| 197 |
- String new_string = String(*this); |
|
| 198 |
- new_string.ansi.substr(pos, n); |
|
| 199 |
- new_string.utf8.substr(pos, n); |
|
| 200 |
- if (n == std::string::npos) |
|
| 201 |
- n = std::wstring::npos; |
|
| 202 |
- new_string.utf16.substr(pos, n); |
|
| 203 |
- return new_string; |
|
| 204 |
- } |
|
| 205 |
- void CopyToString(wchar_t *str, bool = false) const |
|
| 206 |
- {
|
|
| 207 |
- wcscpy(str, utf16.c_str()); |
|
| 208 |
- } |
|
| 209 |
- void CopyToString(char *str, bool use_utf8 = false) const |
|
| 210 |
- {
|
|
| 211 |
- strcpy(str, (use_utf8 ? utf8 : ansi).c_str()); |
|
| 212 |
- } |
|
| 213 |
-protected: |
|
| 214 |
- std::string ansi, utf8; |
|
| 215 |
- std::wstring utf16; |
|
| 216 |
- std::locale loc; |
|
| 217 |
-}; |
| ... | ... |
@@ -1,11 +1,10 @@ |
| 1 | 1 |
/* |
| 2 | 2 |
* String class in ANSI (or rather, current Windows code page), UTF-8, and UTF-16 |
| 3 | 3 |
* By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com] |
| 4 |
- * Last modification on 2013-03-25 |
|
| 4 |
+ * Last modification on 2014-09-08 |
|
| 5 | 5 |
*/ |
| 6 | 6 |
|
| 7 |
-#ifndef BIGSSTRING_H |
|
| 8 |
-#define BIGSSTRING_H |
|
| 7 |
+#pragma once |
|
| 9 | 8 |
|
| 10 | 9 |
#include <string> |
| 11 | 10 |
#include <cstring> |
| ... | ... |
@@ -216,5 +215,3 @@ protected: |
| 216 | 215 |
std::wstring utf16; |
| 217 | 216 |
std::locale loc; |
| 218 | 217 |
}; |
| 219 |
- |
|
| 220 |
-#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,220 @@ |
| 1 |
+/* |
|
| 2 |
+ * String class in ANSI (or rather, current Windows code page), UTF-8, and UTF-16 |
|
| 3 |
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com] |
|
| 4 |
+ * Last modification on 2013-03-25 |
|
| 5 |
+ */ |
|
| 6 |
+ |
|
| 7 |
+#ifndef BIGSSTRING_H |
|
| 8 |
+#define BIGSSTRING_H |
|
| 9 |
+ |
|
| 10 |
+#include <string> |
|
| 11 |
+#include <cstring> |
|
| 12 |
+#include <cwchar> |
|
| 13 |
+#include "UtfConverter.h" |
|
| 14 |
+#include "UTFEncodeDecode.h" |
|
| 15 |
+ |
|
| 16 |
+class String |
|
| 17 |
+{
|
|
| 18 |
+public: |
|
| 19 |
+ String(const std::locale &L = std::locale::classic()) : ansi(""), utf8(""), utf16(L""), loc(L) { }
|
|
| 20 |
+ String(const char *new_str, bool is_utf8 = false, const std::locale &L = std::locale::classic()) : ansi(is_utf8 ? DecodeFromUTF8(new_str, L) : new_str), utf8(is_utf8 ? new_str : EncodeToUTF8(new_str, L)), |
|
| 21 |
+ utf16(UtfConverter::FromUtf8(utf8)), loc(L) { }
|
|
| 22 |
+ String(const std::string &new_str, bool is_utf8 = false, const std::locale &L = std::locale::classic()) : ansi(is_utf8 ? DecodeFromUTF8(new_str, L) : new_str), utf8(is_utf8 ? new_str : EncodeToUTF8(new_str, L)), |
|
| 23 |
+ utf16(UtfConverter::FromUtf8(utf8)), loc(L) { }
|
|
| 24 |
+ String(const wchar_t *new_wstr, const std::locale &L = std::locale::classic()) : ansi(DecodeFromUTF8(UtfConverter::ToUtf8(new_wstr), L)), utf8(UtfConverter::ToUtf8(new_wstr)), utf16(new_wstr), loc(L) { }
|
|
| 25 |
+ String(const std::wstring &new_wstr, const std::locale &L = std::locale::classic()) : ansi(DecodeFromUTF8(UtfConverter::ToUtf8(new_wstr), L)), utf8(UtfConverter::ToUtf8(new_wstr)), utf16(new_wstr), loc(L) { }
|
|
| 26 |
+ bool empty() const { return this->utf8.empty(); }
|
|
| 27 |
+ std::string GetAnsi() const { return this->ansi; }
|
|
| 28 |
+ const char *GetAnsiC() const { return this->ansi.c_str(); }
|
|
| 29 |
+ std::string GetStr() const { return this->utf8; }
|
|
| 30 |
+ const char *GetStrC() const { return this->utf8.c_str(); }
|
|
| 31 |
+ std::wstring GetWStr() const { return this->utf16; }
|
|
| 32 |
+ const wchar_t *GetWStrC() const { return this->utf16.c_str(); }
|
|
| 33 |
+ bool operator==(const String &str2) const |
|
| 34 |
+ {
|
|
| 35 |
+ return this->utf8 == str2.utf8; |
|
| 36 |
+ } |
|
| 37 |
+ String &operator=(const std::string &new_str) |
|
| 38 |
+ {
|
|
| 39 |
+ this->ansi = DecodeFromUTF8(new_str, this->loc); |
|
| 40 |
+ this->utf8 = new_str; |
|
| 41 |
+ this->utf16 = UtfConverter::FromUtf8(new_str); |
|
| 42 |
+ return *this; |
|
| 43 |
+ } |
|
| 44 |
+ String &operator=(const std::wstring &new_wstr) |
|
| 45 |
+ {
|
|
| 46 |
+ this->utf8 = UtfConverter::ToUtf8(new_wstr); |
|
| 47 |
+ this->ansi = DecodeFromUTF8(this->utf8, this->loc); |
|
| 48 |
+ this->utf16 = new_wstr; |
|
| 49 |
+ return *this; |
|
| 50 |
+ } |
|
| 51 |
+ String &operator=(const String &new_string) |
|
| 52 |
+ {
|
|
| 53 |
+ if (this != &new_string) |
|
| 54 |
+ {
|
|
| 55 |
+ this->ansi = new_string.ansi; |
|
| 56 |
+ this->utf8 = new_string.utf8; |
|
| 57 |
+ this->utf16 = new_string.utf16; |
|
| 58 |
+ } |
|
| 59 |
+ return *this; |
|
| 60 |
+ } |
|
| 61 |
+ String &SetISO8859_1(const std::string &new_str) |
|
| 62 |
+ {
|
|
| 63 |
+ this->ansi = new_str; |
|
| 64 |
+ this->utf8 = EncodeToUTF8(new_str, this->loc); |
|
| 65 |
+ this->utf16 = UtfConverter::FromUtf8(this->utf8); |
|
| 66 |
+ return *this; |
|
| 67 |
+ } |
|
| 68 |
+ String operator+(const String &str2) const |
|
| 69 |
+ {
|
|
| 70 |
+ String new_string = String(*this); |
|
| 71 |
+ new_string.ansi.append(str2.ansi); |
|
| 72 |
+ new_string.utf8.append(str2.utf8); |
|
| 73 |
+ new_string.utf16.append(str2.utf16); |
|
| 74 |
+ return new_string; |
|
| 75 |
+ } |
|
| 76 |
+ String operator+(char chr) const |
|
| 77 |
+ {
|
|
| 78 |
+ String new_string = String(*this); |
|
| 79 |
+ char str2[] = { chr, 0 };
|
|
| 80 |
+ new_string.ansi.append(str2); |
|
| 81 |
+ std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 82 |
+ new_string.utf8.append(new_utf8); |
|
| 83 |
+ new_string.utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 84 |
+ return new_string; |
|
| 85 |
+ } |
|
| 86 |
+ String operator+(wchar_t wchr) const |
|
| 87 |
+ {
|
|
| 88 |
+ String new_string = String(*this); |
|
| 89 |
+ wchar_t wstr2[] = { wchr, 0 };
|
|
| 90 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 91 |
+ new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 92 |
+ new_string.utf8.append(new_utf8); |
|
| 93 |
+ new_string.utf16.append(wstr2); |
|
| 94 |
+ return new_string; |
|
| 95 |
+ } |
|
| 96 |
+ String operator+(const char *str2) const |
|
| 97 |
+ {
|
|
| 98 |
+ String new_string = String(*this); |
|
| 99 |
+ new_string.ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 100 |
+ new_string.utf8.append(str2); |
|
| 101 |
+ new_string.utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 102 |
+ return new_string; |
|
| 103 |
+ } |
|
| 104 |
+ String operator+(const std::string &str2) const |
|
| 105 |
+ {
|
|
| 106 |
+ String new_string = String(*this); |
|
| 107 |
+ new_string.ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 108 |
+ new_string.utf8.append(str2); |
|
| 109 |
+ new_string.utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 110 |
+ return new_string; |
|
| 111 |
+ } |
|
| 112 |
+ String operator+(const wchar_t *wstr2) const |
|
| 113 |
+ {
|
|
| 114 |
+ String new_string = String(*this); |
|
| 115 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 116 |
+ new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 117 |
+ new_string.utf8.append(new_utf8); |
|
| 118 |
+ new_string.utf16.append(wstr2); |
|
| 119 |
+ return new_string; |
|
| 120 |
+ } |
|
| 121 |
+ String operator+(const std::wstring &wstr2) const |
|
| 122 |
+ {
|
|
| 123 |
+ String new_string = String(*this); |
|
| 124 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 125 |
+ new_string.ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 126 |
+ new_string.utf8.append(new_utf8); |
|
| 127 |
+ new_string.utf16.append(wstr2); |
|
| 128 |
+ return new_string; |
|
| 129 |
+ } |
|
| 130 |
+ String &operator+=(const String &str2) |
|
| 131 |
+ {
|
|
| 132 |
+ if (this != &str2) |
|
| 133 |
+ {
|
|
| 134 |
+ this->ansi.append(str2.ansi); |
|
| 135 |
+ this->utf8.append(str2.utf8); |
|
| 136 |
+ this->utf16.append(str2.utf16); |
|
| 137 |
+ } |
|
| 138 |
+ return *this; |
|
| 139 |
+ } |
|
| 140 |
+ String &operator+=(char chr) |
|
| 141 |
+ {
|
|
| 142 |
+ char str2[] = { chr, 0 };
|
|
| 143 |
+ this->ansi.append(str2); |
|
| 144 |
+ std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 145 |
+ this->utf8.append(new_utf8); |
|
| 146 |
+ this->utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 147 |
+ return *this; |
|
| 148 |
+ } |
|
| 149 |
+ String &operator+=(wchar_t wchr) |
|
| 150 |
+ {
|
|
| 151 |
+ wchar_t wstr2[] = { wchr, 0 };
|
|
| 152 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 153 |
+ this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 154 |
+ this->utf8.append(new_utf8); |
|
| 155 |
+ this->utf16.append(wstr2); |
|
| 156 |
+ return *this; |
|
| 157 |
+ } |
|
| 158 |
+ String &operator+=(const char *str2) |
|
| 159 |
+ {
|
|
| 160 |
+ this->ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 161 |
+ this->utf8.append(str2); |
|
| 162 |
+ this->utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 163 |
+ return *this; |
|
| 164 |
+ } |
|
| 165 |
+ String &operator+=(const std::string &str2) |
|
| 166 |
+ {
|
|
| 167 |
+ this->ansi.append(DecodeFromUTF8(str2, this->loc)); |
|
| 168 |
+ this->utf8.append(str2); |
|
| 169 |
+ this->utf16.append(UtfConverter::FromUtf8(str2)); |
|
| 170 |
+ return *this; |
|
| 171 |
+ } |
|
| 172 |
+ String &operator+=(const wchar_t *wstr2) |
|
| 173 |
+ {
|
|
| 174 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 175 |
+ this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 176 |
+ this->utf8.append(new_utf8); |
|
| 177 |
+ this->utf16.append(wstr2); |
|
| 178 |
+ return *this; |
|
| 179 |
+ } |
|
| 180 |
+ String &operator+=(const std::wstring &wstr2) |
|
| 181 |
+ {
|
|
| 182 |
+ std::string new_utf8 = UtfConverter::ToUtf8(wstr2); |
|
| 183 |
+ this->ansi.append(DecodeFromUTF8(new_utf8, this->loc)); |
|
| 184 |
+ this->utf8.append(new_utf8); |
|
| 185 |
+ this->utf16.append(wstr2); |
|
| 186 |
+ return *this; |
|
| 187 |
+ } |
|
| 188 |
+ String &AppendISO8859_1(const std::string &str2) |
|
| 189 |
+ {
|
|
| 190 |
+ this->ansi.append(str2); |
|
| 191 |
+ std::string new_utf8 = EncodeToUTF8(str2, this->loc); |
|
| 192 |
+ this->utf8.append(new_utf8); |
|
| 193 |
+ this->utf16.append(UtfConverter::FromUtf8(new_utf8)); |
|
| 194 |
+ return *this; |
|
| 195 |
+ } |
|
| 196 |
+ String Substring(size_t pos = 0, size_t n = std::string::npos) const |
|
| 197 |
+ {
|
|
| 198 |
+ String new_string = String(*this); |
|
| 199 |
+ new_string.ansi.substr(pos, n); |
|
| 200 |
+ new_string.utf8.substr(pos, n); |
|
| 201 |
+ if (n == std::string::npos) |
|
| 202 |
+ n = std::wstring::npos; |
|
| 203 |
+ new_string.utf16.substr(pos, n); |
|
| 204 |
+ return new_string; |
|
| 205 |
+ } |
|
| 206 |
+ void CopyToString(wchar_t *str, bool = false) const |
|
| 207 |
+ {
|
|
| 208 |
+ wcscpy(str, utf16.c_str()); |
|
| 209 |
+ } |
|
| 210 |
+ void CopyToString(char *str, bool use_utf8 = false) const |
|
| 211 |
+ {
|
|
| 212 |
+ strcpy(str, (use_utf8 ? utf8 : ansi).c_str()); |
|
| 213 |
+ } |
|
| 214 |
+protected: |
|
| 215 |
+ std::string ansi, utf8; |
|
| 216 |
+ std::wstring utf16; |
|
| 217 |
+ std::locale loc; |
|
| 218 |
+}; |
|
| 219 |
+ |
|
| 220 |
+#endif |