bump to -rc12
[gnucap-felix.git] / lib / ap_skip.cc
blob4b13e4c88243318c608076b4f78c51945c0da409
1 /*$Id: ap_skip.cc,v 1.1 2009-10-23 12:01:44 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
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.
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.
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.
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
35 CS& CS::skipbl()
37 while (peek() && (!isgraph(peek()))) {
38 skip();
40 return *this;
42 /*--------------------------------------------------------------------------*/
43 /* skip1b: skip 1 matching character and surrounding blanks
44 * _ok = did it
46 CS& CS::skip1b(char t)
48 skipbl();
49 skip1(t);
50 skipbl();
51 return *this;
53 /*--------------------------------------------------------------------------*/
54 /* skip1: skip 1 character matching any in t
55 * _ok = did it
57 CS& CS::skip1(char t)
59 if (match1(t)) {
60 skip();
61 assert(_ok);
62 }else{
63 _ok = false;
65 return *this;
67 /*--------------------------------------------------------------------------*/
68 /* skip1b: skip 1 matching character and surrounding blanks
69 * _ok = did it
71 CS& CS::skip1b(const std::string& t)
73 skipbl();
74 skip1(t);
75 skipbl();
76 return *this;
78 /*--------------------------------------------------------------------------*/
79 /* skip1: skip 1 character matching any in t
80 * _ok = did it
82 CS& CS::skip1(const std::string& t)
84 if (match1(t)) {
85 skip();
86 assert(_ok);
87 }else{
88 _ok = false;
90 return *this;
92 /*--------------------------------------------------------------------------*/
93 /* skiparg: skip an argument (maybe just a comma)
94 * _ok = skipped something
96 CS& CS::skiparg()
98 unsigned here = cursor();
99 if (!skipcom()) {
100 if (peek()) {
101 skip();
102 }else{
104 while (is_alpha() || is_float() || is_argsym()) {
105 skip();
107 skipcom();
108 }else{untested();
109 // empty field, just a comma
111 _ok = cursor() > here;
112 return *this;
114 /*--------------------------------------------------------------------------*/
115 /* skipto: skip to a character (one of ...)
116 * _ok = skipped something
118 CS& CS::skipto1(const std::string& t)
119 {untested();
120 unsigned here = cursor();
121 while (ns_more() && !match1(t)) {untested();
122 skip();
124 _ok = ns_more();
125 if (!_ok) {untested();
126 reset(here);
127 }else{untested();
129 return *this;
131 /*--------------------------------------------------------------------------*/
132 /* skipto: skip to a character (explicit)
133 * _ok = skipped something
135 CS& CS::skipto1(char c)
137 unsigned here = cursor();
138 while (ns_more() && !match1(c)) {
139 skip();
141 _ok = ns_more();
142 if (!_ok) {untested();
143 reset(here);
144 }else{
146 return *this;
148 /*--------------------------------------------------------------------------*/
149 /*--------------------------------------------------------------------------*/
150 // vim:ts=8:sw=2:noet: