Skip to content

Commit 6a9a534

Browse files
committed
fix: fix 126 error
1 parent a7d0fc0 commit 6a9a534

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/pl/internal/StringUtils.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
std::wstring pl::utils::str2wstr(const std::string& str, UINT codePage) {
1515
int len = MultiByteToWideChar(codePage, 0, str.data(), (int)str.size(), nullptr, 0);
1616
std::wstring wstr;
17-
if (len == 0) { return wstr; }
18-
wstr.reserve(len);
17+
if (len == 0) return wstr;
18+
wstr.resize(len);
1919
MultiByteToWideChar(codePage, 0, str.data(), (int)str.size(), wstr.data(), len);
2020
return wstr;
2121
}
@@ -24,11 +24,11 @@ std::wstring pl::utils::str2wstr(const std::string& str) { return str2wstr(str,
2424

2525
std::string pl::utils::wstr2str(const std::wstring& wstr) {
2626
int len = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), nullptr, 0, nullptr, nullptr);
27-
std::string ret;
28-
if (len == 0) { return ret; }
29-
ret.reserve(len);
30-
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), ret.data(), (int)ret.size(), nullptr, nullptr);
31-
return ret;
27+
std::string str;
28+
if (len == 0) return str;
29+
str.resize(len);
30+
WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(), str.data(), (int)str.size(), nullptr, nullptr);
31+
return str;
3232
}
3333

3434
std::vector<std::string_view> pl::utils::split(std::string_view s, std::string_view delimiter) {

0 commit comments

Comments
 (0)