PH Logo
Logo intepreter modeled after UCB Logo.
/Users/paul/Documents/phlogo/core/StringTokenStream.h
00001 /*
00002  *  StringTokenStream.h
00003  *
00004  *  Author: Paul Hamilton
00005  *      Date: 28 Jul 2011
00006  *
00007  */
00008 #ifndef _STRINGTOKENSTREAM_H
00009 #define _STRINGTOKENSTREAM_H
00010 
00011 #include "TokenStream.h"
00012 
00013 namespace phlogo {
00014 
00018 class StringTokenStream : public TokenStream {
00019                 
00020 public:
00021         StringTokenStream(const std::string &input) : 
00022                 _input(input), _begin(0), _subend(0), _end(input.length()), _next(0) {}
00023 
00024         // TokenStream overrides
00025         virtual bool withinSubExpression() { return _subend != 0; }
00026         virtual bool hasMoreSubExpression() { return _next != _subend; }
00027         virtual bool atEnd() { return _next == _end; }
00028         virtual size_t findEndSubExpression();
00029         virtual void finishSubExpression(size_t pos) { _next = pos; _subend = 0; }
00030 
00031         std::string nextWord();
00032         void skipWs();
00033         bool hasMore() { return _next != std::string::npos && _next < _end; }
00034         void forward(size_t offs) { _next += offs; }
00035         char nextChar() { return _input[_next]; }
00036         std::string remain() { return _input.substr(_next); };
00037         char charAt(size_t pos) { return _input[pos]; };
00038         
00039 private:
00040         std::string _input;
00041         size_t _begin; 
00042         size_t _subend;
00043         size_t _end;
00044         size_t _next;
00045 };
00046 
00047 }
00048 
00049 #endif // _STRINGTOKENSTREAM_H
 All Classes Functions