OLD | NEW |
1 #include <memory> | 1 #include <memory> |
2 #include <stdexcept> | 2 #include <stdexcept> |
3 #include <vector> | 3 #include <vector> |
4 | 4 |
5 #include <Windows.h> | 5 #include <Windows.h> |
6 #include <ShlObj.h> | 6 #include <ShlObj.h> |
7 | 7 |
8 #include "Utils.h" | 8 #include "Utils.h" |
9 | 9 |
10 namespace | 10 namespace |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 int utf16StringLength = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length, N
ULL, 0); | 60 int utf16StringLength = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length, N
ULL, 0); |
61 if (utf16StringLength == 0) | 61 if (utf16StringLength == 0) |
62 throw std::runtime_error("ToUTF16String failed. Can't determine the length o
f the buffer needed."); | 62 throw std::runtime_error("ToUTF16String failed. Can't determine the length o
f the buffer needed."); |
63 | 63 |
64 std::wstring utf16String(utf16StringLength, L'\0'); | 64 std::wstring utf16String(utf16StringLength, L'\0'); |
65 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length, &utf16String[0], utf16Str
ingLength); | 65 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), length, &utf16String[0], utf16Str
ingLength); |
66 return utf16String; | 66 return utf16String; |
67 } | 67 } |
68 | 68 |
| 69 std::vector<std::wstring> ToUtf16Strings(const std::vector<std::string>& values) |
| 70 { |
| 71 std::vector<std::wstring> result; |
| 72 result.reserve(values.size()); |
| 73 transform(values.begin(), values.end(), back_inserter(result), ToUtf16String); |
| 74 return result; |
| 75 } |
| 76 |
69 std::wstring GetDllDir() | 77 std::wstring GetDllDir() |
70 { | 78 { |
71 std::vector<WCHAR> path(MAX_PATH); | 79 std::vector<WCHAR> path(MAX_PATH); |
72 int length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast
<DWORD>(path.size())); | 80 int length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast
<DWORD>(path.size())); |
73 | 81 |
74 while (length == path.size()) | 82 while (length == path.size()) |
75 { | 83 { |
76 // Buffer too small, double buffer size | 84 // Buffer too small, double buffer size |
77 path.resize(path.size() * 2); | 85 path.resize(path.size() * 2); |
78 length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast<D
WORD>(path.size())); | 86 length = GetModuleFileNameW((HINSTANCE)&__ImageBase, &path[0], static_cast<D
WORD>(path.size())); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 131 } |
124 | 132 |
125 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st
d::wstring replacement) | 133 void ReplaceString(std::wstring& input, const std::wstring placeholder, const st
d::wstring replacement) |
126 { | 134 { |
127 size_t replaceStart = input.find(placeholder); | 135 size_t replaceStart = input.find(placeholder); |
128 if (replaceStart != std::string::npos) | 136 if (replaceStart != std::string::npos) |
129 { | 137 { |
130 input.replace(replaceStart, placeholder.length(), replacement); | 138 input.replace(replaceStart, placeholder.length(), replacement); |
131 } | 139 } |
132 } | 140 } |
OLD | NEW |