~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Kernel/Types/parse_string.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2008-04-06 15:11:41 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080406151141-w0sg20jnv86mlt6f
Tags: 1:1.0.6.14-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* 01_american.dpatch is updated
* Since thread support in guile-1.8 is now disabled, the segmentation faults
  should not arise anymore. More info at #439923. (Closes: #450499, #458685)
[kohda]
* This version fixed menu problem.  (Closes: #447083)
* Reverted orig.tar.gz to the upstream tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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
******************************************************************************/
 
13
 
 
14
#include "parse_string.hpp"
 
15
#include "analyze.hpp"
 
16
 
 
17
void
 
18
parse_string_rep::advance (int n) {
 
19
  if (is_nil (l) || n <= 0) return;
 
20
  p->item += n;
 
21
  if (p->item >= N (l->item)) {
 
22
    n= p->item - N (l->item);
 
23
    l= l->next;
 
24
    p= p->next;
 
25
    advance (n);
 
26
  }
 
27
}
 
28
 
 
29
string
 
30
parse_string_rep::read (int n) {
 
31
  string s;
 
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);
 
35
    l  = l->next;
 
36
    p  = p->next;
 
37
  }
 
38
  if (is_nil (l)) return s;
 
39
  s << l->item (p->item, p->item + n);
 
40
  p->item += n;
 
41
  if (p->item >= N(l->item)) {
 
42
    l= l->next;
 
43
    p= p->next;
 
44
  }
 
45
  return s;
 
46
}
 
47
 
 
48
void
 
49
parse_string_rep::write (string s) {
 
50
  if (N(s) > 0) {
 
51
    l= list<string> (s, l);
 
52
    p= list<int>    (0, p);
 
53
  }
 
54
}
 
55
 
 
56
char
 
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];
 
61
 
 
62
  list<string> ll= l;
 
63
  list<int>    pp= p;
 
64
  while (!is_nil (l) && pp->item + n >= N (ll->item)) {
 
65
    n -= (N (ll->item) - pp->item);
 
66
    ll = ll->next;
 
67
    pp = pp->next;
 
68
  }
 
69
  if (is_nil (ll)) return 0;
 
70
  return ll->item [pp->item + n];
 
71
}
 
72
 
 
73
string
 
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);
 
78
 
 
79
  string s;
 
80
  list<string> ll= l;
 
81
  list<int>    pp= p;
 
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);
 
85
    n -= m;
 
86
    ll = ll->next;
 
87
    pp = pp->next;
 
88
  }
 
89
  return s;
 
90
}
 
91
 
 
92
bool
 
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);
 
97
 
 
98
  return get_string (N(s)) == s;
 
99
}
 
100
 
 
101
bool
 
102
test (parse_string s, string what) {
 
103
  return s->test (what);
 
104
}
 
105
 
 
106
ostream&
 
107
operator << (ostream& out, parse_string s) {
 
108
  list<string> l= s->l;
 
109
  list<int>    p= s->p;
 
110
  while (!is_nil (l)) {
 
111
    out << l->item (p->item, N(l->item));
 
112
    l= l->next;
 
113
    p= p->next;
 
114
  }
 
115
  return out;
 
116
}