Back to index

texmacs  1.0.7.15
parse_string.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : parse_string.hpp
00004 * DESCRIPTION: strings from which it is both easy to read and write characters
00005 *              they are used for entity replacement in the XML parser
00006 * COPYRIGHT  : (C) 2005  Joris van der Hoeven
00007 *******************************************************************************
00008 * This software falls under the GNU general public license version 3 or later.
00009 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00010 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00011 ******************************************************************************/
00012 
00013 #ifndef PARSE_STRING_H
00014 #define PARSE_STRING_H
00015 #include "string.hpp"
00016 #include "list.hpp"
00017 
00018 class parse_string;
00019 class parse_string_rep: concrete_struct {
00020   list<string> l;   // strings left to parse
00021   list<int>    p;   // positions in each string
00022 
00023 public:
00024   inline parse_string_rep (): l (), p () {}
00025   inline parse_string_rep (string s): l (s), p (0) {}
00026   inline ~parse_string_rep () {}
00027 
00028   void advance (int n);
00029   string read (int n);
00030   void write (string s);
00031   char get_char (int n);
00032   string get_string (int n);
00033   bool test (string s);
00034 
00035   friend class parse_string;
00036   friend tm_ostream& operator << (tm_ostream& out, parse_string s);
00037   friend bool test (parse_string s, string what);
00038 };
00039 
00040 class parse_string {
00041   CONCRETE(parse_string);
00042   inline parse_string (): rep (tm_new<parse_string_rep> ()) {}
00043   inline parse_string (string s): rep (tm_new<parse_string_rep> (s)) {}
00044   inline char operator [] (int i) { return rep->get_char (i); }
00045   inline operator bool () { return !is_nil (rep->l); }
00046   inline void operator += (int i) { rep->advance (i); }
00047 };
00048 CONCRETE_CODE(parse_string);
00049 
00050 bool test (parse_string s, string what);
00051 
00052 #endif // defined PARSE_STRING_H