ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

textsplit.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRIM_TEXTSPLIT_HH
00024 #define GRIM_TEXTSPLIT_HH
00025 
00026 namespace Common {
00027 class SeekableReadStream;
00028 }
00029 
00030 namespace Grim {
00031 
00032 // A utility class to help in parsing the text-format files.  Splits
00033 // the text data into lines, skipping comments, trailing whitespace,
00034 // and empty lines.  Also folds everything to lowercase.
00035 
00036 class TextSplitter {
00037 public:
00038     TextSplitter(const Common::String &fname, Common::SeekableReadStream *data);
00039     ~TextSplitter();
00040 
00041     char *nextLine() {
00042         processLine();
00043         return _currLine;
00044     }
00045 
00046     char *getCurrentLine() { return _currLine; }
00047     const char *getCurrentLine() const { return _currLine; }
00048     bool isEof() const { return _lineIndex == _numLines; }
00049     int getLineNumber() { return _lineIndex; }
00050     void setLineNumber(int line) { _lineIndex = line - 1; processLine(); }
00051 
00052     // Check if the current line contains 'needle'
00053     bool checkString(const char *needle);
00054 
00055     // Expect a certain fixed string; bail out with an error if not
00056     // found.  Advance to the next line.
00057     void expectString(const char *expected);
00058 
00059     // Scan a line according to the given format (compatible with
00060     // scanf); if not all fields are read (according to the field_count
00061     // argument), bail out with an error.  Advance to the next line.
00062     void scanString(const char *fmt, int field_count, ...);
00063 
00064     // Scan a line starting at offset 'offset' according to the given format
00065     // (compatible with scanf); if not all fields are read (according to the
00066     // field_count argument), bail out with an error.  Advance to the next line.
00067     void scanStringAtOffset(int offset, const char *fmt, int field_count, ...);
00068 
00069     // Just like scanString(), but without advancing to the next line.
00070     void scanStringNoNewLine(const char *fmt, int field_count, ...);
00071 
00072     // Just like scanStringAtOffset(), but without advancing to the next line.
00073     void scanStringAtOffsetNoNewLine(int offset, const char *fmt, int field_count, ...);
00074 
00075 private:
00076     Common::String _fname;
00077     char *_stringData;
00078     char *_currLine;
00079     int _numLines, _lineIndex;
00080     char **_lines;
00081 
00082     void processLine();
00083 };
00084 
00085 } // end of namespace Grim
00086 
00087 #endif


Generated on Sat Feb 16 2019 05:01:08 for ResidualVM by doxygen 1.7.1
curved edge   curved edge