comparison src/core/strings.cc @ 411:02a670a8e1c4

*: fix build fails
author Paper <paper@tflc.us>
date Sat, 25 Jul 2026 14:22:44 -0400
parents 4562bc8bfdff
children 192da585a0a8
comparison
equal deleted inserted replaced
410:eb554255ea5f 411:02a670a8e1c4
139 std::string ToLower(const std::string &string) 139 std::string ToLower(const std::string &string)
140 { 140 {
141 return ToUtf8String(session.config.locale.GetLocale().toLower(ToQString(string))); 141 return ToUtf8String(session.config.locale.GetLocale().toLower(ToQString(string)));
142 } 142 }
143 143
144 #ifdef __GNUC__
145 # pragma GCC diagnostic push
146 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
147 #endif
144 std::wstring ToWstring(const std::string &string) 148 std::wstring ToWstring(const std::string &string)
145 { 149 {
146 static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L""); 150 static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L"");
147 151
148 std::wstring wstr; 152 std::wstring wstr;
153 std::cerr << "Failed to convert UTF-8 to wide string!" << std::endl; 157 std::cerr << "Failed to convert UTF-8 to wide string!" << std::endl;
154 } 158 }
155 return wstr; 159 return wstr;
156 } 160 }
157 161
162 std::string ToUtf8String(const std::wstring &wstring)
163 {
164 static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L"");
165 return converter.to_bytes(wstring);
166 }
167
168 std::string ToUtf8String(const std::u32string &u32string)
169 {
170 static std::wstring_convert<std::codecvt_utf8_utf16<char32_t>, char32_t> converter;
171 return converter.to_bytes(u32string);
172 }
173
174 std::u32string ToUcs4String(const std::string &string)
175 {
176 static std::wstring_convert<std::codecvt_utf8_utf16<char32_t>, char32_t> converter;
177 return converter.from_bytes(string);
178 }
179 #ifdef __GNUC__
180 # pragma GCC diagnostic pop
181 #endif
182
158 std::wstring ToWstring(const QString &string) 183 std::wstring ToWstring(const QString &string)
159 { 184 {
160 std::wstring arr(string.size(), L'\0'); 185 std::wstring arr(string.size(), L'\0');
161 string.toWCharArray(&arr.front()); 186 string.toWCharArray(&arr.front());
162 return arr; 187 return arr;
163 }
164
165 std::string ToUtf8String(const std::wstring &wstring)
166 {
167 static std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("", L"");
168 return converter.to_bytes(wstring);
169 }
170
171 std::string ToUtf8String(const std::u32string &u32string)
172 {
173 static std::wstring_convert<std::codecvt_utf8_utf16<char32_t>, char32_t> converter;
174 return converter.to_bytes(u32string);
175 }
176
177 std::u32string ToUcs4String(const std::string &string)
178 {
179 static std::wstring_convert<std::codecvt_utf8_utf16<char32_t>, char32_t> converter;
180 return converter.from_bytes(string);
181 } 188 }
182 189
183 std::string ToUtf8String(const QString &string) 190 std::string ToUtf8String(const QString &string)
184 { 191 {
185 const QByteArray ba = string.toUtf8(); 192 const QByteArray ba = string.toUtf8();
229 } 236 }
230 #endif 237 #endif
231 238
232 bool ToBool(const std::string &str, bool def) 239 bool ToBool(const std::string &str, bool def)
233 { 240 {
234 std::istringstream s(Strings::ToLower(str)); 241 std::string l = Strings::ToLower(str);
235 s >> std::boolalpha >> def; 242
236 return def; 243 return (l == "true") ? true : (l == "false") ? false : def;
237 } 244 }
238 245
239 template<typename T> 246 template<typename T>
240 constexpr T ipow(T num, unsigned int pow) 247 constexpr T ipow(T num, unsigned int pow)
241 { 248 {