diff --git a/string.cpp b/string.cpp index 4601d1a6..34423493 100644 --- a/string.cpp +++ b/string.cpp @@ -17,9 +17,30 @@ #include "./string.hpp" #include +#include +#include using util::tokeniser; + +/////////////////////////////////////////////////////////////////////////////// +std::string +util::to_utf8 (const wchar_t *src) +{ + using convert_t = std::codecvt_utf8; + std::wstring_convert converter; + return converter.to_bytes (src); +} + + +//----------------------------------------------------------------------------- +std::string +util::to_utf8 (const std::wstring &src) +{ + return to_utf8 (src.c_str ()); +} + + /////////////////////////////////////////////////////////////////////////////// // TODO: Horribly inefficient, but God help you if you're relying on this // being efficient in the first place. diff --git a/string.hpp b/string.hpp index 539bc9fd..d7c9434e 100644 --- a/string.hpp +++ b/string.hpp @@ -20,6 +20,12 @@ #include "./view.hpp" +namespace util { + std::string to_utf8 (const wchar_t*); + std::string to_utf8 (const std::wstring&); +} + + bool strbegins(const char *restrict str, const char *restrict prefix);