Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/agcstack.cpp @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1997-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * agcstk.cpp - character stack | |
7 */ | |
8 | |
9 #include "agcstack.h" | |
10 #include "assert.h" | |
11 | |
12 //#define INCLUDE_LOGGING | |
13 #include "log.h" | |
14 | |
15 | |
16 AgString AgCharStack::popString(unsigned n) { | |
17 LOGSECTION("AgCharStack::popString(unsigned)"); | |
18 assert(n <= size()); | |
19 LOGV(size()); | |
20 LOGV(n); | |
21 AgString result(n); | |
22 char *p = result.pointer(); | |
23 while (n--) { | |
24 p[n] = pop(); | |
25 } | |
26 return result; | |
27 } | |
28 | |
29 AgString AgCharStack::popString() { | |
30 LOGSECTION("AgCharStack::popString"); | |
31 unsigned n = size(); | |
32 LOGV(size()); | |
33 LOGV(n); | |
34 AgString result(n); | |
35 char *p = result.pointer(); | |
36 while (n--) { | |
37 p[n] = pop(); | |
38 } | |
39 return result; | |
40 } | |
41 | |
42 AgCharStack &AgCharStack::push(const char *s) { | |
43 while (*s) { | |
44 push(*s++); | |
45 } | |
46 return *this; | |
47 } | |
48 | |
49 AgCharStack &AgCharStack::push(const char *s, unsigned n) { | |
50 for (unsigned i = 0; i < n; i++) { | |
51 push(s[i]); | |
52 } | |
53 return *this; | |
54 } | |
55 | |
56 | |
57 AgCharStack &AgCharStack::operator << (AgString s) { | |
58 int n = s.size(); | |
59 char *p = s.pointer(); | |
60 while (n--) { | |
61 (*this) << *p++; | |
62 } | |
63 return *this; | |
64 } | |
65 | |
66 AgCharStack &AgCharStack::operator << (const char *s) { | |
67 if (s) { | |
68 while (*s) { | |
69 push(*s++); | |
70 } | |
71 } | |
72 return *this; | |
73 } |