1 2 /* Web Polygraph http://www.web-polygraph.org/ 3 * Copyright 2003-2011 The Measurement Factory 4 * Licensed under the Apache License, Version 2.0 */ 5 6 #ifndef POLYGRAPH__PGL_PGLSTRRANGELEXER_H 7 #define POLYGRAPH__PGL_PGLSTRRANGELEXER_H 8 9 #include "xstd/Ring.h" 10 #include "xstd/String.h" 11 12 class PglStrRange; 13 14 // parsers a string range specification into lexems 15 // and facilitates conversion of the lexems into PglStrRange blocks 16 class PglStrRangeLexer { 17 protected: 18 19 class Lexem { 20 public: 21 Lexem(); 22 Lexem(const char *aStart, const char *aStop); 23 tag()24 char tag() const { return *theStart; } start()25 const char *start() const { return theStart; } stop()26 const char *stop() const { return theStop; } 27 28 protected: 29 const char *theStart; // pointers to the string 30 const char *theStop; // being parsed 31 }; 32 33 public: 34 PglStrRangeLexer(PglStrRange *anOwner, const String &anImage); 35 36 operator void *() const { return theLexems.empty() ? 0 : (void*)-1; } 37 38 bool parse(); // split the image into lexems 39 40 // first char of the next lexem 41 char next(int off = 0) const { return charAt(off); } 42 // converts next lexem into a block 43 void step(); 44 void skip(int count = 1); // skips next count lexems 45 46 bool range(bool isolated); // tries to convert next lexems into a range block 47 48 protected: 49 char charAt(int pos) const; 50 int intAt(int pos) const; 51 52 bool rangeItem(bool isolated); 53 bool isDigit(char ch); 54 55 protected: 56 Ring<Lexem> theLexems; 57 PglStrRange *theOwner; 58 const String theImage; 59 }; 60 61 #endif 62