2
/******************************************************************************
3
* MODULE : parse_string.cpp
4
* DESCRIPTION: strings from which it is both easy to read and write characters
5
* they are used for entity replacement in the XML parser
6
* COPYRIGHT : (C) 2005 Joris van der Hoeven
7
*******************************************************************************
8
* This software falls under the GNU general public license and comes WITHOUT
9
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
10
* If you don't have this file, write to the Free Software Foundation, Inc.,
11
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
12
******************************************************************************/
14
#include "parse_string.hpp"
15
#include "analyze.hpp"
18
parse_string_rep::advance (int n) {
19
if (is_nil (l) || n <= 0) return;
21
if (p->item >= N (l->item)) {
22
n= p->item - N (l->item);
30
parse_string_rep::read (int n) {
32
while (!is_nil (l) && p->item + n > N (l->item)) {
33
s << l->item (p->item, N (l->item));
34
n -= (N (l->item) - p->item);
38
if (is_nil (l)) return s;
39
s << l->item (p->item, p->item + n);
41
if (p->item >= N(l->item)) {
49
parse_string_rep::write (string s) {
51
l= list<string> (s, l);
57
parse_string_rep::get_char (int n) {
58
if (is_nil (l)) return 0;
59
if (p->item + n < N (l->item))
60
return l->item [p->item + n];
64
while (!is_nil (l) && pp->item + n >= N (ll->item)) {
65
n -= (N (ll->item) - pp->item);
69
if (is_nil (ll)) return 0;
70
return ll->item [pp->item + n];
74
parse_string_rep::get_string (int n) {
75
if (is_nil (l)) return "";
76
if (p->item + n <= N (l->item))
77
return l->item (p->item, p->item + n);
82
while (n >= 0 && !is_nil (ll)) {
83
int m= min (N (ll->item) - pp->item, n);
84
s << ll->item (pp->item, pp->item + m);
93
parse_string_rep::test (string s) {
94
if (is_nil (l)) return N(s) == 0;
95
if (p->item + N(s) <= N (l->item))
96
return ::test (l->item, p->item, s);
98
return get_string (N(s)) == s;
102
test (parse_string s, string what) {
103
return s->test (what);
107
operator << (ostream& out, parse_string s) {
108
list<string> l= s->l;
110
while (!is_nil (l)) {
111
out << l->item (p->item, N(l->item));