1 ///###//////////////////////////////////////////////////////////////////////// 2 // 3 // Burton Computer Corporation 4 // http://www.burton-computer.com 5 // http://www.cooldevtools.com 6 // $Id: StringReader.cc 272 2007-01-06 19:37:27Z brian $ 7 // 8 // Copyright (C) 2007 Burton Computer Corporation 9 // ALL RIGHTS RESERVED 10 // 11 // This program is open source software; you can redistribute it 12 // and/or modify it under the terms of the Q Public License (QPL) 13 // version 1.0. Use of this software in whole or in part, including 14 // linking it (modified or unmodified) into other programs is 15 // subject to the terms of the QPL. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // Q Public License for more details. 21 // 22 // You should have received a copy of the Q Public License 23 // along with this program; see the file LICENSE.txt. If not, visit 24 // the Burton Computer Corporation or CoolDevTools web site 25 // QPL pages at: 26 // 27 // http://www.burton-computer.com/qpl.html 28 // http://www.cooldevtools.com/qpl.html 29 // 30 31 #include "StringReader.h" 32 33 class StringReaderPosition : public AbstractCharReaderPosition 34 { 35 public: StringReaderPosition(int _index)36 StringReaderPosition(int _index) : index(_index) 37 { 38 } 39 ~StringReaderPosition()40 virtual ~StringReaderPosition() 41 { 42 } 43 44 int index; 45 }; 46 StringReader(const string & source)47StringReader::StringReader(const string &source) 48 : m_source(source), m_index(-1) 49 { 50 } 51 ~StringReader()52StringReader::~StringReader() 53 { 54 } 55 forward()56bool StringReader::forward() 57 { 58 return skip(1); 59 } 60 hasChar()61bool StringReader::hasChar() 62 { 63 return m_index >= 0 && m_index < m_source.length(); 64 } 65 skip(int nchars)66bool StringReader::skip(int nchars) 67 { 68 m_index += nchars; 69 if (m_index >= m_source.length()) { 70 return false; 71 } 72 setCurrentChar(m_source[m_index]); 73 return m_index < m_source.length(); 74 } 75 atEnd()76bool StringReader::atEnd() 77 { 78 return m_index >= m_source.length(); 79 } 80 createMark()81OWNED AbstractCharReaderPosition *StringReader::createMark() 82 { 83 return new StringReaderPosition(m_index); 84 } 85 returnToMark(AbstractCharReaderPosition * pos)86void StringReader::returnToMark(AbstractCharReaderPosition *pos) 87 { 88 m_index = dynamic_cast<StringReaderPosition*>(pos)->index; 89 } 90 91