X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=include%2Ftext.h;h=fcb6dfafc3cf7bd872360f7a84d7ee8921782543;hb=4b7b856e70fe8047f985e2598020032d0d87a672;hp=2096a7eb0fda1b4ba680693dfe938ba05296742d;hpb=1c78f8bbdfe52be741185762123fba2c169d738a;p=meshio%2Fmeshio.git diff --git a/include/text.h b/include/text.h index 2096a7e..fcb6dfa 100644 --- a/include/text.h +++ b/include/text.h @@ -7,6 +7,10 @@ #include #include +#ifdef _WIN32 +#include +#endif + namespace meshio { namespace text { @@ -234,42 +238,41 @@ template class LineSplitter { cstr line_; - std::vector heads_; - std::vector tails_; - size_t index_; public: LineSplitter(cstr line) - : line_(line), index_(0) + : line_(line) { - const char *current=line.begin(); - for(; current!=line_.end();){ - for(; current!=line_.end(); ++current){ - if(!DELIMITER()(*current)){ - break; - } - } - if(current==line_.end()){ + } + + cstr get() + { + const char* head=0; + const char* tail=0; + const char *current=line_.begin(); + for(; current!=line_.end();){ + for(; current!=line_.end(); ++current){ + if(!DELIMITER()(*current)){ + head=current; break; } - heads_.push_back(current); + } + if(head){ for(; current!=line_.end(); ++current){ if(DELIMITER()(*current)){ break; } } - tails_.push_back(current); + tail=current; + } + if(tail){ + break; } } - - cstr get() - { - if(index_>=heads_.size()){ + if(!tail){ return cstr(); } - const char* head=heads_[index_]; - const char* tail=tails_[index_]; - ++index_; + line_=cstr(tail+1, line_.end()); return cstr(head, tail); } @@ -307,6 +310,15 @@ public: return la::Vector4(x, y, z, w); } + color::fRGBA getFloatRGBA() + { + float r=getFloat(); + float g=getFloat(); + float b=getFloat(); + float a=getFloat(); + return color::fRGBA(r, g, b, a); + } + color::bRGBA getByteRGBA() { int r=getInt(); @@ -335,10 +347,12 @@ public: } cstr token=cstr(begin, c); - begin=c+1; + + // advance + line_=cstr(c+1, line_.end()); + return token; } - }; inline void copyStringAndFillZero(char *dst, const std::string &src) @@ -357,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