-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix free of wrong thing, misc cleanup (#1)
- Loading branch information
Showing
6 changed files
with
70 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <locale> | ||
#include <codecvt> | ||
#include <stringapiset.h> | ||
|
||
// https://stackoverflow.com/a/3999597 | ||
// Thank you tfinniga! | ||
|
||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunused-function" | ||
|
||
// Convert a wide Unicode string to an UTF8 string | ||
static inline std::string utf8_encode(const std::wstring &wstr) | ||
{ | ||
if (wstr.empty()) return std::string(); | ||
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); | ||
std::string strTo(size_needed, 0); | ||
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); | ||
return strTo; | ||
} | ||
|
||
// Convert an UTF8 string to a wide Unicode String | ||
static inline std::wstring utf8_decode(const std::string &str) | ||
{ | ||
if (str.empty()) return std::wstring(); | ||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); | ||
std::wstring wstrTo(size_needed, 0); | ||
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); | ||
return wstrTo; | ||
} | ||
|
||
#pragma clang diagnostic pop |