X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=include%2Ftext.h;h=fcb6dfafc3cf7bd872360f7a84d7ee8921782543;hb=16747520a6f143bfed46cf02617ad0ab306ecdf8;hp=be8ba4f12586d96a2db3879dffdf3f8b1dc8c801;hpb=2e272c8234ed76c70119a71a8371c4c48b8d7a33;p=meshio%2Fmeshio.git diff --git a/include/text.h b/include/text.h old mode 100755 new mode 100644 index be8ba4f..fcb6dfa --- a/include/text.h +++ b/include/text.h @@ -7,6 +7,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + namespace meshio { namespace text { @@ -367,6 +371,39 @@ inline void copyStringAndFillZero(char *dst, const std::string &src) } } +#ifdef _WIN32 +inline std::wstring to_WideChar(UINT uCodePage, const std::string &text) +{ + int size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, NULL, 0); + std::vector buf(size); + size=MultiByteToWideChar(uCodePage, 0, text.c_str(), -1, &buf[0], buf.size()); + return std::wstring(buf.begin(), buf.begin()+size); +} + +inline std::string to_MultiByte(UINT uCodePage, const std::wstring &text) +{ + int size=WideCharToMultiByte(uCodePage, 0, text.c_str(), -1, NULL, 0, 0, NULL); + std::vector buf(size); + size=WideCharToMultiByte(uCodePage, 0, text.c_str(), -1, &buf[0], buf.size(), 0, NULL); + return std::string(buf.begin(), buf.begin()+size); +} + +inline std::string cp932_to_utf8(const std::string &text) +{ + return to_MultiByte(CP_UTF8, to_WideChar(CP_OEMCP, text)); +} + +inline std::wstring trim(const std::wstring &src){ + std::wstring::const_iterator end=src.begin(); + for(; end!=src.end(); ++end){ + if(*end==L'\0'){ + break; + } + } + return std::wstring(src.begin(), end); +} +#endif + } // namespace text } // namespace meshio #endif // MESH_IO_TEXT_H_INCLUDED