15 #ifndef INCG_IRIS_IUTEST_CHARCODE_HPP_D444FB3E_3AFA_46D0_AD69_33FAAF5615E3_
16 #define INCG_IRIS_IUTEST_CHARCODE_HPP_D444FB3E_3AFA_46D0_AD69_33FAAF5615E3_
23 #if IUTEST_HAS_CXX_HDR_CODECVT
28 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_BEGIN()
43 inline ::std::string AnyStringToMultiByteString(
const char* str,
int num = -1)
45 return num < 0 ? str : ::std::string(str, num);
54 ::std::string AnyStringToUTF8(
const wchar_t* str,
int num=-1);
62 ::std::string AnyStringToMultiByteString(
const wchar_t* str,
int num=-1);
64 #if IUTEST_HAS_CHAR16_T
72 ::std::string AnyStringToUTF8(
const char16_t* str,
int num=-1);
80 ::std::string AnyStringToMultiByteString(
const char16_t* str,
int num=-1);
84 #if IUTEST_HAS_CHAR32_T
92 ::std::string AnyStringToUTF8(
const char32_t* str,
int num = -1);
100 ::std::string AnyStringToMultiByteString(
const char32_t* str,
int num = -1);
109 ::std::wstring MultiByteStringToWideString(
const char* str);
117 ::std::string MultiByteStringToUTF8(
const char* src,
int num=-1);
124 template<
typename CharType>
125 ::std::string ShowAnyCString(
const CharType* any_c_str)
127 if( any_c_str == NULL )
129 return kStrings::Null;
131 return AnyStringToMultiByteString(any_c_str);
134 #if IUTEST_HAS_CXX_HDR_CODECVT
136 template<
typename In,
typename Out,
typename State>
137 struct codecvt :
public ::std::codecvt<In, Out, State> { ~codecvt() {} };
144 #if defined(_MSC_VER)
145 template<
typename In,
typename Out,
typename State>
146 ::std::basic_string<Out> CodeConvert(
const In* str, ::std::locale loc = ::std::locale(
""))
148 ::std::wstring_convert< codecvt<In, Out, State>, In> conv(&::std::use_facet< codecvt<In, Out, State> >(loc));
149 return conv.to_bytes(str);
152 template<
typename In,
typename Out,
typename State>
153 ::std::basic_string<Out> CodeConvert(
const In* str)
155 ::std::wstring_convert< codecvt<In, Out, State>, In> conv;
157 return conv.to_bytes(str);
165 namespace mbs_ptr_impl
171 const char* ptr(
const char* arg) {
return arg; }
173 struct wcs_to_mbs_ptr
176 const char* ptr(
const wchar_t* arg)
178 m_arg = ShowAnyCString(arg);
179 return m_arg.c_str();
183 struct to_mbs_ptr<wchar_t> :
public wcs_to_mbs_ptr {};
185 struct to_mbs_ptr<const wchar_t> :
public wcs_to_mbs_ptr {};
192 template<
typename CharType>
193 struct mbs_ptr :
public mbs_ptr_impl::to_mbs_ptr<CharType>
199 #if IUTEST_HAS_EXTERN_TEMPLATE
201 IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_BEGIN()
203 extern template struct mbs_ptr<char>;
204 extern template struct mbs_ptr<wchar_t>;
206 IUTEST_PRAGMA_EXTERN_TEMPLATE_WARN_DISABLE_END()
210 template struct mbs_ptr<char>;
211 template struct mbs_ptr<wchar_t>;
216 IUTEST_PRAGMA_CRT_SECURE_WARN_DISABLE_END()
222 # include "../impl/iutest_charcode.ipp"
225 #endif // INCG_IRIS_IUTEST_CHARCODE_HPP_D444FB3E_3AFA_46D0_AD69_33FAAF5615E3_