58 #if !defined(THEOLIZER_INTERNAL_U8STRING_H) 59 #define THEOLIZER_INTERNAL_U8STRING_H 61 #include "internal/external.h" 66 #pragma warning(disable:4702) 85 #pragma warning(disable:4251) 106 extern const THEOLIZER_INTERNAL_DLL
unsigned kCP_ACP;
110 extern const THEOLIZER_INTERNAL_DLL
unsigned kCP_UTF8;
114 unsigned THEOLIZER_INTERNAL_DLL
getACP();
118 bool THEOLIZER_INTERNAL_DLL
setACP(
unsigned iCodePage);
129 bool THEOLIZER_INTERNAL_DLL
registerStream(std::istream* iIStream);
133 bool THEOLIZER_INTERNAL_DLL
registerStream(std::ostream* iOStream);
137 bool THEOLIZER_INTERNAL_DLL
registerStream(std::iostream* iIOStream);
157 bool THEOLIZER_INTERNAL_DLL
isInputByUtf8(std::istream* iIStream);
161 bool THEOLIZER_INTERNAL_DLL
isOutputByUtf8(std::ostream* iOStream);
185 #ifndef THEOLIZER_INTERNAL_DOXYGEN 187 template<
class tCharOut,
class tCharIn>
190 static std::basic_string<tCharOut> THEOLIZER_INTERNAL_DLL conv(tCharIn
const* iIn) noexcept;
191 static std::basic_string<tCharOut> conv(std::basic_string<tCharIn>
const& iIn) noexcept
193 return conv(iIn.c_str());
203 template<
class tCharOut>
204 struct Converter<tCharOut, MultiByte>
206 static std::basic_string<tCharOut> THEOLIZER_INTERNAL_DLL conv(
char const* iIn) noexcept;
207 static std::basic_string<tCharOut> conv(std::string
const& iIn) noexcept
209 return conv(iIn.c_str());
215 template<
class tCharIn>
216 struct Converter<MultiByte, tCharIn>
218 static std::string THEOLIZER_INTERNAL_DLL conv(tCharIn
const* iIn) noexcept;
219 static std::string conv(std::basic_string<tCharIn>
const& iIn) noexcept
221 return conv(iIn.c_str());
225 #endif // THEOLIZER_INTERNAL_DOXYGEN 293 u8string(std::string
const& str) : mString(str) { }
295 u8string(std::string
const& str, std::size_t pos, std::size_t len = std::string::npos)
296 : mString(str, pos, len) { }
300 u8string(
char const* s, std::size_t n) : mString(s, n) { }
302 u8string(std::size_t n,
char c) : mString(n, c) { }
304 template <
class InputIterator>
306 : mString(first, last) { }
308 u8string(std::initializer_list<char> il) : mString(il) { }
310 u8string(std::string&& str) noexcept : mString(str) { }
315 #define THEOLIZER_INTERNAL_CONSTRUCTOR(dFromChar) \ 317 u8string(const dFromChar* iIn) : \ 318 mString(internal::Converter<char, dFromChar>::conv(iIn)) { } \ 320 u8string(const std::basic_string<dFromChar>& iIn) : \ 321 mString(internal::Converter<char, dFromChar>::conv(iIn)) { } 326 #undef THEOLIZER_INTERNAL_CONSTRUCTOR 330 mString(internal::Converter<char,
MultiByte>::conv(iIn)) { }
333 mString(internal::Converter<char,
MultiByte>::conv(iIn)) { }
344 #define THEOLIZER_INTERNAL_FUNCTION(dFunc) \ 345 u8string& dFunc(const u8string& iIn) { \ 346 mString.dFunc(iIn.mString); \ 358 #undef THEOLIZER_INTERNAL_FUNCTION 365 return std::operator+(lhs.mString, rhs.mString);
370 return std::operator+(lhs.mString, rhs);
375 return std::operator+(lhs, rhs.mString);
379 #define THEOLIZER_INTERNAL_FRIEND_RELATIONAL_OPERATOR(dFunc) \ 381 friend bool dFunc(const u8string& lhs, const u8string& rhs) \ 383 return std::dFunc(lhs.mString, rhs.mString); \ 386 friend bool dFunc(const u8string& lhs, char const* rhs) \ 388 return std::dFunc(lhs.mString, rhs); \ 391 friend bool dFunc(char const* lhs, const u8string& rhs) \ 393 return std::dFunc(lhs, rhs.mString); \ 402 #undef THEOLIZER_INTERNAL_FRIEND_RELATIONAL_OPERATOR 407 std::swap(lhs.mString, rhs.mString);
415 std::operator>>(iIStream, rhs.mString);
420 std::operator>>(iIStream, aString);
421 rhs.mString=theolizer::internal::Converter<char, theolizer::MultiByte>::conv(aString);
436 theolizer::internal::Converter<theolizer::MultiByte, char>::conv(rhs.mString));
446 std::string&
str() {
return mString;}
448 std::string
const&
str()
const {
return mString;}
451 char const*
c_str()
const {
return mString.c_str();}
458 #define THEOLIZER_INTERNAL_GET_STRING(dToChar, dName) \ 459 std::dName get_##dName() const \ 461 return internal::Converter<dToChar, char>::conv(mString); \ 472 #undef THEOLIZER_INTERNAL_GET_STRING 479 operator std::string()
const {
return get_string();}
481 operator std::wstring()
const {
return get_wstring();}
483 operator std::u16string()
const {
return get_u16string();}
485 operator std::u32string()
const {
return get_u32string();}
500 std::string mMBstring;
501 std::wstring mWstring;
502 std::u16string mU16string;
503 std::u32string mU32string;
509 operator char const*() {mMBstring =mString.
getMultiByte();
return mMBstring.c_str();}
511 operator const wchar_t*() {mWstring =mString.
get_wstring();
return mWstring.c_str();}
513 operator const char16_t*() {mU16string=mString.
get_u16string();
return mU16string.c_str();}
515 operator const char32_t*() {mU32string=mString.
get_u32string();
return mU32string.c_str();}
534 return internal::Converter<MultiByte, char>::conv(mString);
540 *
this = internal::Converter<char, MultiByte>::conv(iIn);
547 *
this = internal::Converter<char, MultiByte>::conv(iIn);
557 #if defined(_MSC_VER) 558 std::wstring get_fstring()
const {
return get_wstring();}
560 std::string get_fstring()
const {
return getMultiByte();}
571 std::wstring get_bstring()
const {
return get_wstring();}
612 inline std::ostream&
operator<<(std::ostream& iOStream,
char const* iString)
621 theolizer::internal::Converter<theolizer::MultiByte, char>::conv(iString));
630 inline std::ostream&
operator<<(std::ostream& iOStream, std::string
const& iString)
632 iOStream << iString.c_str();
640 inline std::istream& operator>>(std::istream& iIStream, std::string& iString)
644 std::operator>>(iIStream, iString);
649 std::operator>>(iIStream, aString);
650 iString=theolizer::internal::Converter<char, theolizer::MultiByte>::conv(aString);
660 #ifndef THEOLIZER_INTERNAL_DOXYGEN 666 #define THEOLIZER_INTERNAL_LEFT_SHIFT_OPERATOR(dChar) \ 667 inline std::ostream& operator<<(std::ostream& iOStream, const dChar* iString)\ 669 if (theolizer::isOutputByUtf8(&iOStream)) { \ 670 std::operator<<(iOStream, \ 671 theolizer::internal::Converter<char, dChar>::conv(iString));\ 673 std::operator<<(iOStream, \ 674 theolizer::internal::Converter<theolizer::MultiByte, dChar>::conv(iString));\ 678 inline std::ostream& operator<<(std::ostream& iOStream, \ 679 const std::basic_string<dChar>& iString)\ 681 iOStream << iString.c_str(); \ 685 THEOLIZER_INTERNAL_LEFT_SHIFT_OPERATOR(
wchar_t)
686 THEOLIZER_INTERNAL_LEFT_SHIFT_OPERATOR(char16_t)
687 THEOLIZER_INTERNAL_LEFT_SHIFT_OPERATOR(char32_t)
688 #undef THEOLIZER_INTERNAL_LEFT_SHIFT_OPERATOR 694 #define THEOLIZER_INTERNAL_RIGHT_SHIFT_OPERATOR(dChar) \ 695 inline std::istream& operator>>(std::istream& iIStream,std::basic_string<dChar>& iString)\ 697 std::string aString; \ 698 std::operator>>(iIStream, aString); \ 699 if (theolizer::isInputByUtf8(&iIStream)) { \ 700 iString=theolizer::internal::Converter<dChar, char>::conv(aString);\ 702 iString=theolizer::internal::Converter<dChar, \ 703 theolizer::MultiByte>::conv(aString); \ 708 THEOLIZER_INTERNAL_RIGHT_SHIFT_OPERATOR(
wchar_t)
709 THEOLIZER_INTERNAL_RIGHT_SHIFT_OPERATOR(char16_t)
710 THEOLIZER_INTERNAL_RIGHT_SHIFT_OPERATOR(char32_t)
711 #undef THEOLIZER_INTERNAL_RIGHT_SHIFT_OPERATOR 713 #endif // THEOLIZER_INTERNAL_DOXYGEN 727 #endif // THEOLIZER_INTERNAL_U8STRING_H bool THEOLIZER_INTERNAL_DLL isOutputByUtf8(std::ostream *iOStream)
bool THEOLIZER_INTERNAL_DLL registerStream(std::istream *iIStream)
u8string & setMultiByte(char const *iIn)
friend std::ostream & operator<<(std::ostream &iOStream, u8string const &rhs)
#define THEOLIZER_INTERNAL_CONSTRUCTOR(dFromChar)
u8string & setMultiByte(std::string const &iIn)
u8string(char const *iIn, MultiByte)
std::string getMultiByte() const
#define THEOLIZER_INTERNAL_FUNCTION(dFunc)
friend void swap(u8string &lhs, u8string &rhs)
std::u32string get_u32string() const
u8string(InputIterator first, InputIterator last)
Unicode記録用文字列クラスu8string.
bool THEOLIZER_INTERNAL_DLL isInputByUtf8(std::istream *iIStream)
u8string(std::initializer_list< char > il)
std::string const & str() const
bool THEOLIZER_INTERNAL_DLL setACP(unsigned iCodePage)
const THEOLIZER_INTERNAL_DLL unsigned kCP_ACP
#define THEOLIZER_INTERNAL_FRIEND_RELATIONAL_OPERATOR(dFunc)
std::wstring get_wstring() const
friend u8string operator+(char const *lhs, u8string const &rhs)
u8string(char const *s, std::size_t n)
b_string(u8string const &iString)
unsigned THEOLIZER_INTERNAL_DLL getACP()
#define THEOLIZER_INTERNAL_GET_STRING(dToChar, dName)
u8string(std::string &&str) noexcept
bool THEOLIZER_INTERNAL_DLL unregisterStream(std::istream *iIStream)
const THEOLIZER_INTERNAL_DLL unsigned kCP_UTF8
friend u8string operator+(u8string const &lhs, char const *rhs)
friend u8string operator+(u8string const &lhs, u8string const &rhs)
THEOLIZER_INTERNAL_DLL std::ostream & operator<<(std::ostream &iOStream, CheckMode iCheckMode)
CheckModeの表示用オーバーロード
std::string get_bstring() const
u8string(std::string const &str)
friend std::istream & operator>>(std::istream &iIStream, u8string &rhs)
std::string get_fstring() const
u8string(std::string const &str, std::size_t pos, std::size_t len=std::string::npos)
char const * c_str() const
u8string(std::size_t n, char c)
u8string(std::string const &iIn, MultiByte)
std::u16string get_u16string() const