scummvm/textsplit.h

66 lines
2.1 KiB
C
Raw Normal View History

2003-08-15 18:00:22 +00:00
// Residual - Virtual machine to run LucasArts' 3D adventure games
// Copyright (C) 2003-2004 The ScummVM-Residual Team (www.scummvm.org)
2003-08-15 18:00:22 +00:00
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#ifndef TEXTSPLIT_HH
#define TEXTSPLIT_HH
#include <cstdlib>
// A utility class to help in parsing the text-format files. Splits
// the text data into lines, skipping comments, trailing whitespace,
// and empty lines. Also folds everything to lowercase.
class TextSplitter {
public:
TextSplitter(const char *data, int len);
2003-08-15 18:00:22 +00:00
char *nextLine() {
2004-12-09 23:55:43 +00:00
_curr_line = _next_line;
processLine();
2004-12-09 23:55:43 +00:00
return _curr_line;
}
2003-08-15 18:00:22 +00:00
2004-12-09 23:55:43 +00:00
char *currentLine() { return _curr_line; }
const char *currentLine() const { return _curr_line; }
bool eof() const { return _curr_line == NULL; }
2003-08-15 18:00:22 +00:00
// Check if the current line contains 'needle'
bool TextSplitter::checkString(const char *needle);
// Expect a certain fixed string; bail out with an error if not
// found. Advance to the next line.
void expectString(const char *expected);
2003-08-15 18:00:22 +00:00
// Scan a line according to the given format (compatible with
// scanf); if not all fields are read (according to the field_count
// argument), bail out with an error. Advance to the next line.
void scanString(const char *fmt, int field_count, ...)
2003-08-15 18:00:22 +00:00
#ifdef __GNUC__
__attribute__((format (scanf, 2, 4)))
2003-08-15 18:00:22 +00:00
#endif
;
2003-08-15 18:00:22 +00:00
2004-12-09 23:55:43 +00:00
~TextSplitter() { delete[] _data; }
2003-08-15 18:00:22 +00:00
private:
2004-12-09 23:55:43 +00:00
char *_data, *_curr_line, *_next_line;
2003-08-15 18:00:22 +00:00
void processLine();
2003-08-15 18:00:22 +00:00
};
#endif