mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 23:14:13 +01:00
ircd::locale: Move char16_t conversions into namespace.
This commit is contained in:
parent
fc6cf72e2d
commit
845e81e446
4 changed files with 54 additions and 29 deletions
|
@ -56,6 +56,6 @@ ircd::js::native_external_copy(const char *const &s,
|
|||
const size_t &len)
|
||||
{
|
||||
auto buf(std::make_unique<char16_t[]>(len + 1));
|
||||
ircd::locale::convert(s, buf.get(), len + 1);
|
||||
ircd::locale::char16::conv(s, buf.get(), len + 1);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -31,12 +31,17 @@ namespace locale {
|
|||
|
||||
// On newer platforms (gcc-5 etc) these conversions are standard C++.
|
||||
// On older platforms the definition file may use boost::locale.
|
||||
size_t convert(const char16_t *const &, char *const &buf, const size_t &max);
|
||||
size_t convert(const char *const &, char16_t *const &buf, const size_t &max); // uint8_t = max*2
|
||||
std::string convert(const char16_t *const &);
|
||||
std::string convert(const std::u16string &);
|
||||
std::u16string convert(const char *const &);
|
||||
std::u16string convert(const std::string &);
|
||||
namespace char16
|
||||
{
|
||||
char conv(const char16_t &);
|
||||
char16_t conv(const char &);
|
||||
size_t conv(const char16_t *const &, char *const &buf, const size_t &max);
|
||||
size_t conv(const char *const &, char16_t *const &buf, const size_t &max); // uint8_t = max*2
|
||||
std::string conv(const char16_t *const &);
|
||||
std::string conv(const std::u16string &);
|
||||
std::u16string conv(const char *const &);
|
||||
std::u16string conv(const std::string &);
|
||||
}
|
||||
|
||||
} // namespace locale
|
||||
} // namespace ircd
|
||||
|
|
|
@ -1419,7 +1419,7 @@ ircd::js::jserror::generate(const JSExnType &type,
|
|||
va_list ap)
|
||||
{
|
||||
ircd::exception::generate(fmt, ap);
|
||||
const auto msg(locale::convert(what()));
|
||||
const auto msg(locale::char16::conv(what()));
|
||||
|
||||
JSErrorReport report;
|
||||
report.ucmessage = msg.c_str();
|
||||
|
@ -1481,7 +1481,7 @@ ircd::js::jserror::generate_what_our(const JSErrorReport &report)
|
|||
report.lineno,
|
||||
report.column);
|
||||
|
||||
const auto msg(report.ucmessage? locale::convert(report.ucmessage) : std::string{});
|
||||
const auto msg(report.ucmessage? locale::char16::conv(report.ucmessage) : std::string{});
|
||||
snprintf(ircd::exception::buf, sizeof(ircd::exception::buf), "%s%s%s%s",
|
||||
reflect((JSExnType)report.exnType),
|
||||
msg.empty()? "." : ": ",
|
||||
|
@ -1652,10 +1652,10 @@ ircd::js::debug(const JSErrorReport &r)
|
|||
ss << reflect(JSExnType(r.exnType)) << " ";
|
||||
|
||||
if(r.ucmessage)
|
||||
ss << "\"" << locale::convert(r.ucmessage) << "\" ";
|
||||
ss << "\"" << locale::char16::conv(r.ucmessage) << "\" ";
|
||||
|
||||
for(auto it(r.messageArgs); it && *it; ++it)
|
||||
ss << "\"" << locale::convert(*it) << "\" ";
|
||||
ss << "\"" << locale::char16::conv(*it) << "\" ";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
|
|
@ -31,14 +31,14 @@ namespace locale {
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
std::u16string
|
||||
ircd::locale::convert(const std::string &s)
|
||||
ircd::locale::char16::conv(const std::string &s)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
return converter.from_bytes(s);
|
||||
}
|
||||
#else
|
||||
std::u16string
|
||||
ircd::locale::convert(const std::string &s)
|
||||
ircd::locale::char16::conv(const std::string &s)
|
||||
{
|
||||
return boost::locale::conv::utf_to_utf<char16_t>(s);
|
||||
}
|
||||
|
@ -46,14 +46,14 @@ ircd::locale::convert(const std::string &s)
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
std::u16string
|
||||
ircd::locale::convert(const char *const &s)
|
||||
ircd::locale::char16::conv(const char *const &s)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
return s? converter.from_bytes(s) : std::u16string{};
|
||||
}
|
||||
#else
|
||||
std::u16string
|
||||
ircd::locale::convert(const char *const &s)
|
||||
ircd::locale::char16::conv(const char *const &s)
|
||||
{
|
||||
return boost::locale::conv::utf_to_utf<char16_t>(s);
|
||||
}
|
||||
|
@ -61,14 +61,14 @@ ircd::locale::convert(const char *const &s)
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
std::string
|
||||
ircd::locale::convert(const std::u16string &s)
|
||||
ircd::locale::char16::conv(const std::u16string &s)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
return converter.to_bytes(s);
|
||||
}
|
||||
#else
|
||||
std::string
|
||||
ircd::locale::convert(const std::u16string &s)
|
||||
ircd::locale::char16::conv(const std::u16string &s)
|
||||
{
|
||||
return boost::locale::conv::utf_to_utf<char>(s);
|
||||
}
|
||||
|
@ -76,14 +76,14 @@ ircd::locale::convert(const std::u16string &s)
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
std::string
|
||||
ircd::locale::convert(const char16_t *const &s)
|
||||
ircd::locale::char16::conv(const char16_t *const &s)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
return s? converter.to_bytes(s) : std::string{};
|
||||
}
|
||||
#else
|
||||
std::string
|
||||
ircd::locale::convert(const char16_t *const &s)
|
||||
ircd::locale::char16::conv(const char16_t *const &s)
|
||||
{
|
||||
return boost::locale::conv::utf_to_utf<char>(s);
|
||||
}
|
||||
|
@ -91,9 +91,9 @@ ircd::locale::convert(const char16_t *const &s)
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
size_t
|
||||
ircd::locale::convert(const char16_t *const &str,
|
||||
char *const &buf,
|
||||
const size_t &max)
|
||||
ircd::locale::char16::conv(const char16_t *const &str,
|
||||
char *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
|
||||
|
@ -103,7 +103,7 @@ ircd::locale::convert(const char16_t *const &str,
|
|||
}
|
||||
#else
|
||||
size_t
|
||||
ircd::locale::convert(const char16_t *const &str,
|
||||
ircd::locale::char16::conv(const char16_t *const &str,
|
||||
char *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
|
@ -115,9 +115,9 @@ ircd::locale::convert(const char16_t *const &str,
|
|||
|
||||
#ifdef HAVE_CODECVT
|
||||
size_t
|
||||
ircd::locale::convert(const char *const &str,
|
||||
char16_t *const &buf,
|
||||
const size_t &max)
|
||||
ircd::locale::char16::conv(const char *const &str,
|
||||
char16_t *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
static std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> converter;
|
||||
|
||||
|
@ -133,9 +133,9 @@ ircd::locale::convert(const char *const &str,
|
|||
}
|
||||
#else
|
||||
size_t
|
||||
ircd::locale::convert(const char *const &str,
|
||||
char16_t *const &buf,
|
||||
const size_t &max)
|
||||
ircd::locale::char16::conv(const char *const &str,
|
||||
char16_t *const &buf,
|
||||
const size_t &max)
|
||||
{
|
||||
if(unlikely(!max))
|
||||
return 0;
|
||||
|
@ -148,3 +148,23 @@ ircd::locale::convert(const char *const &str,
|
|||
return cpsz;
|
||||
}
|
||||
#endif
|
||||
|
||||
char16_t
|
||||
ircd::locale::char16::conv(const char &c)
|
||||
{
|
||||
//TODO: optimize
|
||||
char16_t ret[2];
|
||||
char cs[2] = { c, '\0' };
|
||||
conv(cs, ret, 1);
|
||||
return ret[0];
|
||||
}
|
||||
|
||||
char
|
||||
ircd::locale::char16::conv(const char16_t &c)
|
||||
{
|
||||
//TODO: optimize
|
||||
char ret[2];
|
||||
char16_t cs[2] = { c, char16_t(0) };
|
||||
conv(cs, ret, 1);
|
||||
return ret[0];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue