Skip to content

Commit 455f3b4

Browse files
committed
Use explicit UTF8 conversion
This also allows making deprecations an error again.
1 parent 7efb456 commit 455f3b4

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Diff for: build.zig

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub fn build(b: *std.Build) void {
2626
"-Wextra",
2727
"-Wformat=2",
2828
"-Werror",
29-
"-Wno-deprecated-declarations",
3029
"-Wno-format-nonliteral",
3130
"-Wno-unguarded-availability-new",
3231
};

Diff for: src/main/cpp/win_fsnotifier.cpp

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@
33
#include "win_fsnotifier.h"
44
#include "command.h"
55

6-
#include <codecvt>
76
#include <locale>
87

98
using namespace std;
109

11-
string wideToUtf8String(const wstring& string) {
12-
wstring_convert<deletable_facet<codecvt<wchar_t, char, mbstate_t>>, wchar_t> conv;
13-
return conv.to_bytes(string);
10+
string wideToUtf8String(const wstring& wstr) {
11+
if (wstr.empty()) return std::string();
12+
13+
int utf8Size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr);
14+
if (utf8Size == 0) {
15+
return std::string("INVALID_UTF8");
16+
}
17+
18+
std::string utf8Str(utf8Size, '\0');
19+
20+
int result = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), &utf8Str[0], utf8Size, nullptr, nullptr);
21+
if (result == 0) {
22+
return std::string("INVALID_UTF8");
23+
}
24+
25+
return utf8Str;
1426
}
1527

1628
#define wideToUtf16String(string) (u16string((string).begin(), (string).end()))

0 commit comments

Comments
 (0)