回答編集履歴
2
結果に影響はないと思うが、MB_ERR_INVALID_CHARSだけ対応
test
CHANGED
@@ -15,15 +15,18 @@
|
|
15
15
|
ch[2] = 0;
|
16
16
|
for (ch[0] = 0x20; ch[0] != 0; ++ch[0]) {
|
17
17
|
wchar_t wch[3];
|
18
|
-
int len = MultiByteToWideChar(932,
|
18
|
+
int len = MultiByteToWideChar(932, MB_ERR_INVALID_CHARS, ch, 1, wch, sizeof(wch) / sizeof(wch[0]));
|
19
19
|
if (len == 1) {
|
20
20
|
sjis2ws[std::string(ch)] = std::wstring(1, wch[0]);
|
21
|
+
}
|
22
|
+
else {
|
21
23
|
for (ch[1] = 0x20; ch[1] != 0; ++ch[1]) {
|
22
|
-
int len = MultiByteToWideChar(932,
|
24
|
+
int len = MultiByteToWideChar(932, MB_ERR_INVALID_CHARS, ch, 2, wch, sizeof(wch) / sizeof(wch[0]));
|
23
25
|
if (len == 1) {
|
24
26
|
sjis2ws[std::string(ch)] = std::wstring(1, wch[0]);
|
25
27
|
}
|
26
28
|
}
|
29
|
+
|
27
30
|
}
|
28
31
|
}
|
29
32
|
return sjis2ws;
|
1
コードを他に合わせた
test
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
#include <iomanip>
|
10
10
|
#include <windows.h>
|
11
11
|
auto create_sjis2ws() {
|
12
|
-
std::map<std::string, std::wstring>
|
12
|
+
std::map<std::string, std::wstring> sjis2ws;
|
13
13
|
char ch[3];
|
14
14
|
ch[1] = 0;
|
15
15
|
ch[2] = 0;
|
@@ -17,16 +17,16 @@
|
|
17
17
|
wchar_t wch[3];
|
18
18
|
int len = MultiByteToWideChar(932, 0, ch, 1, wch, sizeof(wch) / sizeof(wch[0]));
|
19
19
|
if (len == 1) {
|
20
|
-
|
20
|
+
sjis2ws[std::string(ch)] = std::wstring(1, wch[0]);
|
21
21
|
for (ch[1] = 0x20; ch[1] != 0; ++ch[1]) {
|
22
22
|
int len = MultiByteToWideChar(932, 0, ch, 2, wch, sizeof(wch) / sizeof(wch[0]));
|
23
23
|
if (len == 1) {
|
24
|
-
|
24
|
+
sjis2ws[std::string(ch)] = std::wstring(1, wch[0]);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
}
|
28
28
|
}
|
29
|
-
return
|
29
|
+
return sjis2ws;
|
30
30
|
}
|
31
31
|
template<typename K, typename V>
|
32
32
|
auto create_ws2sjis(const std::map<K,V>& sjis2ws) {
|