|
8 | 8 | #include <tuple> |
9 | 9 | #include <memory> |
10 | 10 | #include <vector> |
11 | | -#include <locale> |
12 | | -#include <codecvt> |
13 | 11 |
|
14 | 12 | #define MODERN_SQLITE_VERSION 3002008 |
15 | 13 |
|
|
45 | 43 | #include "sqlite_modern_cpp/errors.h" |
46 | 44 | #include "sqlite_modern_cpp/utility/function_traits.h" |
47 | 45 | #include "sqlite_modern_cpp/utility/uncaught_exceptions.h" |
| 46 | +#include "sqlite_modern_cpp/utility/utf16_utf8.h" |
48 | 47 |
|
49 | 48 | #ifdef MODERN_SQLITE_STD_VARIANT_SUPPORT |
50 | 49 | #include "sqlite_modern_cpp/utility/variant.h" |
@@ -183,15 +182,9 @@ namespace sqlite { |
183 | 182 | } |
184 | 183 | } |
185 | 184 |
|
186 | | -#ifdef _MSC_VER |
187 | 185 | sqlite3_stmt* _prepare(const std::u16string& sql) { |
188 | | - return _prepare(std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(reinterpret_cast<const wchar_t*>(sql.c_str()))); |
| 186 | + return _prepare(utility::utf16_to_utf8(sql)); |
189 | 187 | } |
190 | | -#else |
191 | | - sqlite3_stmt* _prepare(const std::u16string& sql) { |
192 | | - return _prepare(std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().to_bytes(sql)); |
193 | | - } |
194 | | -#endif |
195 | 188 |
|
196 | 189 | sqlite3_stmt* _prepare(const std::string& sql) { |
197 | 190 | int hresult; |
@@ -421,11 +414,7 @@ namespace sqlite { |
421 | 414 | } |
422 | 415 |
|
423 | 416 | database(const std::u16string &db_name, const sqlite_config &config = {}): _db(nullptr) { |
424 | | -#ifdef _MSC_VER |
425 | | - auto db_name_utf8 = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>().to_bytes(reinterpret_cast<const wchar_t*>(db_name.c_str())); |
426 | | -#else |
427 | | - auto db_name_utf8 = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>().to_bytes(db_name); |
428 | | -#endif |
| 417 | + auto db_name_utf8 = utility::utf16_to_utf8(db_name); |
429 | 418 | sqlite3* tmp = nullptr; |
430 | 419 | auto ret = sqlite3_open_v2(db_name_utf8.data(), &tmp, static_cast<int>(config.flags), config.zVfs); |
431 | 420 | _db = std::shared_ptr<sqlite3>(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. |
|
0 commit comments