From da1f3e0d1cca6cc9d4ffb57f3af78b43b92466c9 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 20 Jun 2020 02:02:21 -0700 Subject: [PATCH] ircd: Remove legacy locale header / unit. --- include/ircd/ircd.h | 1 - include/ircd/locale.h | 60 ---------- ircd/Makefile.am | 2 - ircd/locale.cc | 255 ------------------------------------------ 4 files changed, 318 deletions(-) delete mode 100644 include/ircd/locale.h delete mode 100644 ircd/locale.cc diff --git a/include/ircd/ircd.h b/include/ircd/ircd.h index f2ca62f9a..e060b658f 100644 --- a/include/ircd/ircd.h +++ b/include/ircd/ircd.h @@ -54,7 +54,6 @@ #include "backtrace.h" #include "info.h" #include "icu.h" -#include "locale.h" #include "time.h" #include "lex_cast.h" #include "logger.h" diff --git a/include/ircd/locale.h b/include/ircd/locale.h deleted file mode 100644 index 5ffe81798..000000000 --- a/include/ircd/locale.h +++ /dev/null @@ -1,60 +0,0 @@ -// Matrix Construct -// -// Copyright (C) Matrix Construct Developers, Authors & Contributors -// Copyright (C) 2016-2018 Jason Volk -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice is present in all copies. The -// full license for this software is available in the LICENSE file. - -#pragma once -#define HAVE_IRCD_LOCALE_H - -/// Utilities for internationalization. -namespace ircd::locale -{ - -} - -// On newer platforms (gcc-5 etc) these conversions are standard C++. -// On older platforms the definition file may use boost::locale. -namespace ircd::locale::char16 -{ - char conv(const char16_t &); - char16_t conv(const char &); - - size_t conv(const char16_t *const &, const size_t &len, char *const &buf, const size_t &max); - size_t conv(const char *const &, const size_t &len, char16_t *const &buf, const size_t &max); // uint8_t = max*2 - - 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 &, const size_t &len); - std::string conv(const char16_t *const &); - std::string conv(const std::u16string &); - - std::u16string conv(const char *const &, const size_t &len); - std::u16string conv(const char *const &); - std::u16string conv(const std::string &); - - std::ostream &operator<<(std::ostream &, const std::u16string &); -} - -namespace ircd::locale -{ - using char16::operator<<; -} - -namespace ircd -{ - using locale::operator<<; -} - -inline std::ostream & -ircd::locale::char16::operator<<(std::ostream &s, - const std::u16string &u) -{ - s << conv(u); - return s; -} diff --git a/ircd/Makefile.am b/ircd/Makefile.am index 10577948e..69f605ac3 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -122,7 +122,6 @@ libircd_la_SOURCES += demangle.cc libircd_la_SOURCES += backtrace.cc libircd_la_SOURCES += fpe.cc libircd_la_SOURCES += icu.cc -libircd_la_SOURCES += locale.cc libircd_la_SOURCES += timedate.cc libircd_la_SOURCES += lex_cast.cc libircd_la_SOURCES += stringops.cc @@ -236,7 +235,6 @@ endif json.lo: AM_CPPFLAGS := ${SPIRIT_UNIT_CPPFLAGS} ${AM_CPPFLAGS} json.lo: AM_CXXFLAGS := ${SPIRIT_UNIT_CXXFLAGS} ${AM_CXXFLAGS} lex_cast.lo: AM_CPPFLAGS := @BOOST_CPPFLAGS@ ${AM_CPPFLAGS} -locale.lo: AM_CPPFLAGS := @BOOST_CPPFLAGS@ ${AM_CPPFLAGS} tokens.lo: AM_CPPFLAGS := @BOOST_CPPFLAGS@ ${AM_CPPFLAGS} prof.lo: AM_CPPFLAGS := @BOOST_CPPFLAGS@ ${AM_CPPFLAGS} if MAGIC diff --git a/ircd/locale.cc b/ircd/locale.cc deleted file mode 100644 index 10f1910de..000000000 --- a/ircd/locale.cc +++ /dev/null @@ -1,255 +0,0 @@ -// Matrix Construct -// -// Copyright (C) Matrix Construct Developers, Authors & Contributors -// Copyright (C) 2016-2018 Jason Volk -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice is present in all copies. The -// full license for this software is available in the LICENSE file. - -#include - -namespace ircd { -namespace locale { - -} // namespace locale -} // namespace ircd - -#ifdef HAVE_CODECVT -std::u16string -ircd::locale::char16::conv(const std::string &s) -{ - static std::wstring_convert, char16_t> converter; - return converter.from_bytes(s); -} -#else -std::u16string -ircd::locale::char16::conv(const std::string &s) -{ - return boost::locale::conv::utf_to_utf(s); -} -#endif - -#ifdef HAVE_CODECVT -std::u16string -ircd::locale::char16::conv(const char *const &s) -{ - static std::wstring_convert, char16_t> converter; - return s? converter.from_bytes(s) : std::u16string{}; -} -#else -std::u16string -ircd::locale::char16::conv(const char *const &s) -{ - return boost::locale::conv::utf_to_utf(s); -} -#endif - -#ifdef HAVE_CODECVT -std::u16string -ircd::locale::char16::conv(const char *const &s, - const size_t &len) -{ - static std::wstring_convert, char16_t> converter; - return s && len? converter.from_bytes(s, s + len) : std::u16string{}; -} -#else -std::u16string -ircd::locale::char16::conv(const char *const &s, - const size_t &len) -{ - return boost::locale::conv::utf_to_utf(s, s + len); -} -#endif - -#ifdef HAVE_CODECVT -std::string -ircd::locale::char16::conv(const std::u16string &s) -{ - static std::wstring_convert, char16_t> converter; - return converter.to_bytes(s); -} -#else -std::string -ircd::locale::char16::conv(const std::u16string &s) -{ - return boost::locale::conv::utf_to_utf(s); -} -#endif - -#ifdef HAVE_CODECVT -std::string -ircd::locale::char16::conv(const char16_t *const &s) -{ - static std::wstring_convert, char16_t> converter; - return s? converter.to_bytes(s) : std::string{}; -} -#else -std::string -ircd::locale::char16::conv(const char16_t *const &s) -{ - return boost::locale::conv::utf_to_utf(s); -} -#endif - -#ifdef HAVE_CODECVT -std::string -ircd::locale::char16::conv(const char16_t *const &s, - const size_t &len) -{ - static std::wstring_convert, char16_t> converter; - return s && len? converter.to_bytes(s, s + len) : std::string{}; -} -#else -std::string -ircd::locale::char16::conv(const char16_t *const &s, - const size_t &len) -{ - return boost::locale::conv::utf_to_utf(s, s + len); -} -#endif - -#ifdef HAVE_CODECVT -size_t -ircd::locale::char16::conv(const char16_t *const &str, - char *const &buf, - const size_t &max) -{ - static std::wstring_convert, char16_t> converter; - - //TODO: optimize - const auto s(converter.to_bytes(str)); - return strlcpy(buf, s.c_str(), max); -} -#else -size_t -ircd::locale::char16::conv(const char16_t *const &str, - char *const &buf, - const size_t &max) -{ - //TODO: optimize - const auto s(boost::locale::conv::utf_to_utf(str)); - return strlcpy(buf, s.c_str(), max); -} -#endif - -#ifdef HAVE_CODECVT -size_t -ircd::locale::char16::conv(const char16_t *const &str, - const size_t &len, - char *const &buf, - const size_t &max) -{ - static std::wstring_convert, char16_t> converter; - - //TODO: optimize - const auto s(converter.to_bytes(str, str + len)); - return strlcpy(buf, s.c_str(), max); -} -#else -size_t -ircd::locale::char16::conv(const char16_t *const &str, - const size_t &len, - char *const &buf, - const size_t &max) -{ - //TODO: optimize - const auto s(boost::locale::conv::utf_to_utf(str, str + len)); - return strlcpy(buf, s.c_str(), max); -} -#endif - -#ifdef HAVE_CODECVT -size_t -ircd::locale::char16::conv(const char *const &str, - char16_t *const &buf, - const size_t &max) -{ - static std::wstring_convert, char16_t> converter; - - if(unlikely(!max)) - return 0; - - //TODO: optimize - const auto s(converter.from_bytes(str)); - const auto cpsz(std::min(s.size(), size_t(max - 1))); - memcpy(buf, s.data(), cpsz * 2); - buf[cpsz] = char16_t(0); - return cpsz; -} -#else -size_t -ircd::locale::char16::conv(const char *const &str, - char16_t *const &buf, - const size_t &max) -{ - if(unlikely(!max)) - return 0; - - //TODO: optimize - const auto s(boost::locale::conv::utf_to_utf(str)); - const auto cpsz(std::min(s.size(), size_t(max - 1))); - memcpy(buf, s.data(), cpsz * 2); - buf[cpsz] = char16_t(0); - return cpsz; -} -#endif - -#ifdef HAVE_CODECVT -size_t -ircd::locale::char16::conv(const char *const &str, - const size_t &len, - char16_t *const &buf, - const size_t &max) -{ - static std::wstring_convert, char16_t> converter; - - if(unlikely(!max)) - return 0; - - //TODO: optimize - const auto s(converter.from_bytes(str, str + len)); - const auto cpsz(std::min(s.size(), size_t(max - 1))); - memcpy(buf, s.data(), cpsz * 2); - buf[cpsz] = char16_t(0); - return cpsz; -} -#else -size_t -ircd::locale::char16::conv(const char *const &str, - const size_t &len, - char16_t *const &buf, - const size_t &max) -{ - if(unlikely(!max)) - return 0; - - //TODO: optimize - const auto s(boost::locale::conv::utf_to_utf(str, str + len)); - const auto cpsz(std::min(s.size(), size_t(max - 1))); - memcpy(buf, s.data(), cpsz * 2); - buf[cpsz] = char16_t(0); - 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]; -}