Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 11, 2024
1 parent 9a78455 commit e7f0161
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
27 changes: 2 additions & 25 deletions bee/platform/win/wtf8.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,8 @@
#pragma once

extern "C" {
#include <bee/platform/win/wtf8_c.h>
}
#include <bee/utility/zstring_view.h>

namespace bee::wtf8 {
inline std::wstring u2w(zstring_view str) noexcept {
if (str.empty()) {
return L"";
}
size_t wlen = wtf8_to_utf16_length(str.data(), str.size());
if (wlen == (size_t)-1) {
return L"";
}
std::wstring wresult(wlen, L'\0');
wtf8_to_utf16(str.data(), str.size(), wresult.data(), wlen);
return wresult;
}

inline std::string w2u(wzstring_view wstr) noexcept {
if (wstr.empty()) {
return "";
}
size_t len = wtf8_from_utf16_length(wstr.data(), wstr.size());
std::string result(len, '\0');
wtf8_from_utf16(wstr.data(), wstr.size(), result.data(), len);
return result;
}
std::wstring u2w(zstring_view str) noexcept;
std::string w2u(wzstring_view wstr) noexcept;
}
30 changes: 30 additions & 0 deletions bee/platform/win/wtf8_win.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bee/platform/win/wtf8.h>

extern "C" {
#include <bee/platform/win/wtf8_c.h>
}

namespace bee::wtf8 {
std::wstring u2w(zstring_view str) noexcept {
if (str.empty()) {
return L"";
}
size_t wlen = wtf8_to_utf16_length(str.data(), str.size());
if (wlen == (size_t)-1) {
return L"";
}
std::wstring wresult(wlen, L'\0');
wtf8_to_utf16(str.data(), str.size(), wresult.data(), wlen);
return wresult;
}

std::string w2u(wzstring_view wstr) noexcept {
if (wstr.empty()) {
return "";
}
size_t len = wtf8_from_utf16_length(wstr.data(), wstr.size());
std::string result(len, '\0');
wtf8_from_utf16(wstr.data(), wstr.size(), result.data(), len);
return result;
}
}

0 comments on commit e7f0161

Please sign in to comment.