string: add trivial wchar-to-utf8 conversions
This commit is contained in:
parent
d1ec872bd4
commit
a1b35dfbbe
21
string.cpp
21
string.cpp
@ -17,9 +17,30 @@
|
||||
#include "./string.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
|
||||
using util::tokeniser;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::string
|
||||
util::to_utf8 (const wchar_t *src)
|
||||
{
|
||||
using convert_t = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_t,wchar_t> 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.
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user