\hypertarget{icu_8h_source}{}\doxysection{icu.\+h} \label{icu_8h_source}\index{kblib/icu.h@{kblib/icu.h}} \mbox{\hyperlink{icu_8h}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00001}00001 \textcolor{comment}{/* *****************************************************************************}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00002}00002 \textcolor{comment}{ * kblib is a general utility library for C++14 and C++17, intended to provide}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00003}00003 \textcolor{comment}{ * performant high-\/level abstractions and more expressive ways to do simple}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00004}00004 \textcolor{comment}{ * things.}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00005}00005 \textcolor{comment}{ *}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00006}00006 \textcolor{comment}{ * Copyright (c) 2021 killerbee}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00007}00007 \textcolor{comment}{ *}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00008}00008 \textcolor{comment}{ * This program is free software: you can redistribute it and/or modify}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00009}00009 \textcolor{comment}{ * it under the terms of the GNU General Public License as published by}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00010}00010 \textcolor{comment}{ * the Free Software Foundation, either version 3 of the License, or}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00011}00011 \textcolor{comment}{ * (at your option) any later version.}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00012}00012 \textcolor{comment}{ *}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00013}00013 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00014}00014 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00015}00015 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00016}00016 \textcolor{comment}{ * GNU General Public License for more details.}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00017}00017 \textcolor{comment}{ *}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00018}00018 \textcolor{comment}{ * You should have received a copy of the GNU General Public License}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00019}00019 \textcolor{comment}{ * along with this program. If not, see .}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00020}00020 \textcolor{comment}{ * ****************************************************************************/}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00021}00021 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00031}00031 \textcolor{preprocessor}{\#ifndef KBLIB\_ICU\_H}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00032}00032 \textcolor{preprocessor}{\#define KBLIB\_ICU\_H}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00033}00033 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00034}00034 \textcolor{preprocessor}{\#include "{}\mbox{\hyperlink{tdecl_8h}{tdecl.h}}"{}}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00035}00035 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00036}00036 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00037}00037 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00038}00038 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00039}00039 \textcolor{preprocessor}{\#include }} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00040}00040 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00041}00041 \textcolor{keyword}{namespace }\mbox{\hyperlink{tdecl_8h_a4b5c574c663a392148218cd4410fd7a1}{KBLIB\_NS}} \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00042}00042 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00051}00051 \textcolor{keyword}{template} <\textcolor{keyword}{typename} \textcolor{keywordtype}{string} = std::\textcolor{keywordtype}{string}>} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00052}\mbox{\hyperlink{namespacekblib_a27540546baa5adb2684d6b01b82d9594}{00052}} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_a27540546baa5adb2684d6b01b82d9594}{toUTF8}}(\textcolor{keyword}{const} icu::UnicodeString\& s) -\/> \textcolor{keywordtype}{string} \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00053}00053 \textcolor{keywordtype}{string} res;} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00054}00054 \textcolor{keywordflow}{return} s.toUTF8String(res);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00055}00055 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00056}00056 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00066}00066 \textcolor{keyword}{template} <\textcolor{keyword}{typename} \textcolor{keywordtype}{string}>} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00067}\mbox{\hyperlink{namespacekblib_aa90b416613cc12193d5e239ab10ca8a5}{00067}} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_aa90b416613cc12193d5e239ab10ca8a5}{fromUTF8}}(\textcolor{keywordtype}{string} s) -\/> icu::UnicodeString \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00068}00068 \textcolor{keywordflow}{return} \mbox{\hyperlink{namespacekblib_aa90b416613cc12193d5e239ab10ca8a5}{icu::UnicodeString::fromUTF8}}(s);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00069}00069 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00070}00070 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00077}00077 \textcolor{keyword}{template} <\textcolor{keyword}{typename} \textcolor{keywordtype}{string} = std::u32\textcolor{keywordtype}{string}>} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00078}\mbox{\hyperlink{namespacekblib_a1308a2a6edc5a4ed26a7c5b5dea812d1}{00078}} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_a1308a2a6edc5a4ed26a7c5b5dea812d1}{toUTF32}}(\textcolor{keyword}{const} icu::UnicodeString\& s) -\/> \textcolor{keywordtype}{string} \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00079}00079 \textcolor{keywordtype}{string} res(s.countChar32(), \textcolor{charliteral}{'\(\backslash\)0'});} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00080}00080 UErrorCode ec\{U\_ZERO\_ERROR\};} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00081}00081 s.toUTF32(\&res[0], res.size(), ec);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00082}00082 \textcolor{keywordflow}{if} (U\_FAILURE(ec)) \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00083}00083 \textcolor{comment}{// silence warnings about ec not being a temporary}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00084}00084 \textcolor{keywordflow}{throw} UErrorCode\{ec\};} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00085}00085 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00086}00086 \textcolor{keywordflow}{return} res;} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00087}00087 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00088}00088 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00098}00098 \textcolor{keyword}{template} <\textcolor{keyword}{typename} \textcolor{keywordtype}{string}>} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00099}\mbox{\hyperlink{namespacekblib_aca43a53354402a1f1352b0da9ac32fee}{00099}} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_aca43a53354402a1f1352b0da9ac32fee}{fromUTF32}}(\textcolor{keywordtype}{string} s) -\/> icu::UnicodeString \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00100}00100 \textcolor{keywordflow}{return} \mbox{\hyperlink{namespacekblib_aca43a53354402a1f1352b0da9ac32fee}{icu::UnicodeString::fromUTF32}}(s.data(), s.length());} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00101}00101 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00102}00102 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00107}\mbox{\hyperlink{namespacekblib_1_1icu__str__ops}{00107}} \textcolor{keyword}{namespace }icu\_str\_ops \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00108}00108 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00117}\mbox{\hyperlink{namespacekblib_1_1icu__str__ops_ace81bc910484f6efe549883206d4ddae}{00117}} \textcolor{keyword}{inline} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_1_1icu__str__ops_ace81bc910484f6efe549883206d4ddae}{operator<<}}(std::ostream\& os, \textcolor{keyword}{const} icu::UnicodeString\& str)} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00118}00118 -\/> std::ostream\& \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00119}00119 \textcolor{keywordflow}{return} os << \mbox{\hyperlink{namespacekblib_a27540546baa5adb2684d6b01b82d9594}{toUTF8}}(str);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00120}00120 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00121}00121 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00126}\mbox{\hyperlink{namespacekblib_1_1icu__str__ops_a4ff4a1606ef53a0e2004f84954073fcf}{00126}} \textcolor{keyword}{inline} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_1_1icu__str__ops_a300f61654dd90dbbfe58efb8d6ed414c}{operator+}}(std::string lhs, \textcolor{keyword}{const} icu::UnicodeString\& str)} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00127}00127 -\/> std::string \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00128}00128 \textcolor{keywordflow}{return} str.toUTF8String(lhs);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00129}00129 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00130}00130 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00134}\mbox{\hyperlink{namespacekblib_1_1icu__str__ops_a300f61654dd90dbbfe58efb8d6ed414c}{00134}} \textcolor{keyword}{inline} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_1_1icu__str__ops_a300f61654dd90dbbfe58efb8d6ed414c}{operator+}}(icu::UnicodeString lhs, \textcolor{keyword}{const} std::string\& rhs)} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00135}00135 -\/> icu::UnicodeString \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00136}00136 \textcolor{keywordflow}{return} lhs += \mbox{\hyperlink{namespacekblib_aa90b416613cc12193d5e239ab10ca8a5}{fromUTF8}}(rhs);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00137}00137 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00138}00138 \} \textcolor{comment}{// namespace icu\_str\_ops}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00139}00139 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00148}00148 \textcolor{keyword}{template} <\textcolor{keyword}{typename} T>} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00149}\mbox{\hyperlink{namespacekblib_a8f83f373124cb00091260e5bab6c4b60}{00149}} \textcolor{keyword}{auto} \mbox{\hyperlink{namespacekblib_a8f83f373124cb00091260e5bab6c4b60}{fromStr}}(\textcolor{keyword}{const} icu::UnicodeString\& val, \textcolor{keyword}{const} \textcolor{keywordtype}{char}* type = \textcolor{keyword}{typeid}(T).name())} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00150}00150 -\/> T \{} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00151}00151 \textcolor{keywordflow}{return} fromStr(\mbox{\hyperlink{namespacekblib_a27540546baa5adb2684d6b01b82d9594}{toUTF8}}(val), type);} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00152}00152 \}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00153}00153 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00154}00154 \} \textcolor{comment}{// namespace KBLIB\_NS}} \DoxyCodeLine{\Hypertarget{icu_8h_source_l00155}00155 } \DoxyCodeLine{\Hypertarget{icu_8h_source_l00156}00156 \textcolor{preprocessor}{\#endif }\textcolor{comment}{// KBLIB\_ICU\_H}} \end{DoxyCode}