1 /*$Id: ap_skip.cc,v 26.81 2008/05/27 05:34:00 al Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
4 *
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * collection of functions to skip input
23 * all except skip1 skip leading whitespace, skip whatever is being skipped,
24 * then skip trailing whitespace.
25 */
26 //testing=script 2006.07.17
27 #include "ap.h"
28 /*--------------------------------------------------------------------------*/
29 /* skipbl: skip whitespace. (any non-graphic character is ws)
30 * =,(,) are also ws
31 * update string pointer
32 * pointer points to first non-space
33 * does NOT update _ok flag
34 */
skipbl()35 CS& CS::skipbl()
36 {
37 while (peek() && (!isgraph(peek()))) {
38 skip();
39 }
40 return *this;
41 }
42 /*--------------------------------------------------------------------------*/
43 /* skip1b: skip 1 matching character and surrounding blanks
44 * _ok = did it
45 */
skip1b(char t)46 CS& CS::skip1b(char t)
47 {
48 skipbl();
49 skip1(t);
50 skipbl();
51 return *this;
52 }
53 /*--------------------------------------------------------------------------*/
54 /* skip1: skip 1 character matching any in t
55 * _ok = did it
56 */
skip1(char t)57 CS& CS::skip1(char t)
58 {
59 if (match1(t)) {
60 skip();
61 assert(_ok);
62 }else{
63 _ok = false;
64 }
65 return *this;
66 }
67 /*--------------------------------------------------------------------------*/
68 /* skip1b: skip 1 matching character and surrounding blanks
69 * _ok = did it
70 */
skip1b(const std::string & t)71 CS& CS::skip1b(const std::string& t)
72 {
73 skipbl();
74 skip1(t);
75 skipbl();
76 return *this;
77 }
78 /*--------------------------------------------------------------------------*/
79 /* skip1: skip 1 character matching any in t
80 * _ok = did it
81 */
skip1(const std::string & t)82 CS& CS::skip1(const std::string& t)
83 {
84 if (match1(t)) {
85 skip();
86 assert(_ok);
87 }else{
88 _ok = false;
89 }
90 return *this;
91 }
92 /*--------------------------------------------------------------------------*/
93 /* skiparg: skip an argument (maybe just a comma)
94 * _ok = skipped something
95 */
skiparg()96 CS& CS::skiparg()
97 {
98 unsigned here = cursor();
99 if (!skipcom()) {
100 if (peek()) {
101 skip();
102 }else{
103 }
104 while (is_alpha() || is_float() || is_argsym()) {
105 skip();
106 }
107 skipcom();
108 }else{untested();
109 // empty field, just a comma
110 }
111 _ok = cursor() > here;
112 return *this;
113 }
114 /*--------------------------------------------------------------------------*/
115 /* skipto: skip to a character (one of ...)
116 * _ok = skipped something
117 */
skipto1(const std::string & t)118 CS& CS::skipto1(const std::string& t)
119 {untested();
120 unsigned here = cursor();
121 while (ns_more() && !match1(t)) {untested();
122 skip();
123 }
124 _ok = ns_more();
125 if (!_ok) {untested();
126 reset(here);
127 }else{untested();
128 }
129 return *this;
130 }
131 /*--------------------------------------------------------------------------*/
132 /* skipto: skip to a character (explicit)
133 * _ok = skipped something
134 */
skipto1(char c)135 CS& CS::skipto1(char c)
136 {
137 unsigned here = cursor();
138 while (ns_more() && !match1(c)) {
139 skip();
140 }
141 _ok = ns_more();
142 if (!_ok) {untested();
143 reset(here);
144 }else{
145 }
146 return *this;
147 }
148 /*--------------------------------------------------------------------------*/
149 /*--------------------------------------------------------------------------*/
150