1 #ifndef MESH_IO_TEXT_H_INCLUDED
2 #define MESH_IO_TEXT_H_INCLUDED
14 *
\8eQ
\8fÆ
\83I
\83\93\83\8a\81[
\82Ì
\8aÈ
\88Õ
\95¶
\8e\9a\97ñ
\83N
\83\89\83X
26 cstr(const char *begin, const char *end)
27 : begin_(begin), end_(end)
30 bool operator==(const char *rhs)const
33 for(const char *r=rhs; *r; ++r, ++l){
44 bool operator!=(const char *rhs)const
49 bool include(char c)const
51 for(const char *l=begin_; l!=end_; ++l){
59 bool startswith(const char *rhs)
62 for(const char *l=begin_; l!=end_ && *r!='\0'; ++l, ++r){
75 std::string str()const{ return std::string(begin_, end_); }
76 const char* begin()const{ return begin_; }
77 const char* end()const{ return end_; }
78 std::pair<const char*, const char*> range()const{
79 return std::make_pair(begin_, end_);
82 template<typename IsTrim>
83 cstr &trim(IsTrim isTrim){
84 while(begin_!=end_ && isTrim(*begin_)){
87 while(end_!=begin_ && isTrim(end_[-1])){
93 inline std::ostream &operator<<(std::ostream &os, const cstr &rhs)
95 return os << rhs.str();
100 bool operator()(char byte)const
105 case '\r': // fall through
116 bool operator()(char byte)const
121 case '\t': // fall through
132 bool operator()(cstr line)const
138 template<class DELIMITER=IsCRLF,
140 class LINESKIP=IsEmptyLine>
143 binary::IReader &reader_;
144 unsigned int lineCount_;
145 std::vector<char> buf_;
149 LineReader(binary::IReader &reader)
150 : reader_(reader), lineCount_(0), isEnd_(false)
162 if(LINESKIP()(line)){
171 unsigned int getLineCount()const
186 while(char byte=reader_.getChar()){
187 if(DELIMITER()(byte)){
190 buf_.push_back(byte);
193 while(char byte=reader_.getChar()){
194 if(DELIMITER()(byte)){
197 buf_.push_back(byte);
213 if(front>=buf_.size()){
216 if(!TRIM()(buf_[front])){
222 size_t back=buf_.size()-1;
223 for(; back>=0; --back){
224 if(!TRIM()(buf_[back])){
229 return cstr(&buf_[0]+front, &buf_[0]+back+1);
233 template<class DELIMITER=IsSpace>
239 LineSplitter(cstr line)
248 const char *current=line_.begin();
249 for(; current!=line_.end();){
250 for(; current!=line_.end(); ++current){
251 if(!DELIMITER()(*current)){
257 for(; current!=line_.end(); ++current){
258 if(DELIMITER()(*current)){
271 line_=cstr(tail+1, line_.end());
272 return cstr(head, tail);
277 return atoi(get().begin());
282 return static_cast<float>(atof(get().begin()));
285 la::Vector2 getVector2()
289 return la::Vector2(x, y);
292 la::Vector3 getVector3()
297 return la::Vector3(x, y, z);
300 la::Vector4 getVector4()
306 return la::Vector4(x, y, z, w);
309 color::fRGBA getFloatRGBA()
315 return color::fRGBA(r, g, b, a);
318 color::bRGBA getByteRGBA()
324 return color::bRGBA(r, g, b, a);
329 const char *begin=line_.begin();
330 for(; begin!=line_.end(); ++begin){
336 assert(begin<=line_.end());
338 const char *c=begin+1;
339 for(; c!=line_.end(); ++c){
345 cstr token=cstr(begin, c);
348 line_=cstr(c+1, line_.end());
354 inline void copyStringAndFillZero(char *dst, const std::string &src)
357 for(; i<src.size(); ++i)
364 for(; i<src.size(); ++i)
371 } // namespace meshio
372 #endif // MESH_IO_TEXT_H_INCLUDED