add wstring to stirng.

This commit is contained in:
luocai 2024-05-28 15:18:38 +02:00
parent 264ac80d2b
commit 2ad8209814
3 changed files with 17 additions and 2 deletions

View File

@ -28,7 +28,7 @@ target_include_directories(mbedtls-${MBEDTLS_VERSION}
)
target_link_libraries(Encrypt
PRIVATE mbedtls-${MBEDTLS_VERSION}
PUBLIC mbedtls-${MBEDTLS_VERSION}
)
if(UNIX)

View File

@ -1,8 +1,10 @@
#include "StringUtility.h"
#include "BoostLog.h"
#include <algorithm>
#include <cctype>
#include <codecvt>
#ifdef WIN32
#include <Windows.h>
#endif
namespace Amass {
@ -54,6 +56,18 @@ std::wstring stringToWString(const std::string &string) {
return converter.from_bytes(string);
}
std::string wstringToString(const std::wstring &string) {
#ifdef WIN32
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.size(), NULL, 0, NULL, NULL);
std::string ret(sizeNeeded, 0);
WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.size(), &ret[0], sizeNeeded, NULL, NULL);
#else
std::string ret;
assert(false && "not implement.");
#endif
return ret;
}
bool equal(std::string_view lhs, std::string_view rhs, bool caseSensitivity) {
auto n = lhs.size();
if (rhs.size() != n) return false;

View File

@ -60,6 +60,7 @@ size_t utf8Length(const std::string &text);
std::string_view utf8At(const std::string &text, size_t index);
size_t utf8CharacterByteSize(const char *character);
std::wstring stringToWString(const std::string &string);
std::string wstringToString(const std::wstring &string);
} // namespace StringUtility