#include <string>
#include <stdlib.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
namespace meshio {
namespace text {
class LineSplitter
{
cstr line_;
- std::vector<const char*> heads_;
- std::vector<const char*> 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);
}
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();
}
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)
}
}
+#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<wchar_t> 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<char> 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