Lolly 1.4.28
Loading...
Searching...
No Matches
parse_string.cpp
Go to the documentation of this file.
1
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 version 3 or later.
9 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
10 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ******************************************************************************/
12
13#include "parse_string.hpp"
14#include "analyze.hpp"
15
16void
18 if (is_nil (l) || n <= 0) return;
19 p->item+= n;
20 if (p->item >= N (l->item)) {
21 n= p->item - N (l->item);
22 l= l->next;
23 p= p->next;
24 advance (n);
25 }
26}
27
28string
30 string s;
31 while (!is_nil (l) && p->item + n > N (l->item)) {
32 s << l->item (p->item, N (l->item));
33 n-= (N (l->item) - p->item);
34 l= l->next;
35 p= p->next;
36 }
37 if (is_nil (l)) return s;
38 s << l->item (p->item, p->item + n);
39 p->item+= n;
40 if (p->item >= N (l->item)) {
41 l= l->next;
42 p= p->next;
43 }
44 return s;
45}
46
47void
49 if (N (s) > 0) {
50 l= list<string> (s, l);
51 p= list<int> (0, p);
52 }
53}
54
55char
57 if (is_nil (l)) return 0;
58 if (p->item + n < N (l->item)) return l->item[p->item + n];
59
61 list<int> pp= p;
62 while (!is_nil (ll) && pp->item + n >= N (ll->item)) {
63 n-= (N (ll->item) - pp->item);
64 ll= ll->next;
65 pp= pp->next;
66 }
67 if (is_nil (ll)) return 0;
68 return ll->item[pp->item + n];
69}
70
71string
73 if (is_nil (l)) return "";
74 if (p->item + n <= N (l->item)) return l->item (p->item, p->item + n);
75
76 string s;
78 list<int> pp= p;
79 while (n >= 0 && !is_nil (ll)) {
80 int m= min (N (ll->item) - pp->item, n);
81 s << ll->item (pp->item, pp->item + m);
82 n-= m;
83 ll= ll->next;
84 pp= pp->next;
85 }
86 return s;
87}
88
89bool
91 if (is_nil (l)) return N (s) == 0;
92 if (p->item + N (s) <= N (l->item)) return ::test (l->item, p->item, s);
93
94 return get_string (N (s)) == s;
95}
96
97bool
98test (parse_string s, string what) {
99 return s->test (what);
100}
101
104 list<string> l= s->l;
105 list<int> p= s->p;
106 while (!is_nil (l)) {
107 out << l->item (p->item, N (l->item));
108 l= l->next;
109 p= p->next;
110 }
111 return out;
112}
int N(array< T > a)
Get the length of the array.
Definition array.hpp:170
bool is_nil(blackbox x)
Definition blackbox.hpp:29
The list class represents a linked list.
Definition list.hpp:48
void write(string s)
string get_string(int n)
string read(int n)
friend bool test(parse_string s, string what)
void advance(int n)
char get_char(int n)
list< string > l
SI min(SI i, SI j)
Returns the minimum of two signed integers.
Definition minmax.hpp:27
tm_ostream & operator<<(tm_ostream &out, parse_string s)
bool test(parse_string s, string what)