1 /* Provides an Iterator for keyword characters.
2 Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc.
3 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
5 This file is part of GNU GPERF.
7 GNU GPERF 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 1, or (at your option)
12 GNU GPERF 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 GNU GPERF; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
26 /* Constructor for Iterator. */
28 Iterator::Iterator (const char *s
, int lo
, int hi
, int word_end
, int bad_val
, int key_end
)
30 T (Trace
t ("Iterator::Iterator");)
32 error_value
= bad_val
;
39 /* Provide an Iterator, returning the ``next'' value from
40 the list of valid values given in the constructor. */
43 Iterator::operator() (void)
45 T (Trace
t ("Iterator::operator()");)
46 /* Variables to record the Iterator's status when handling ranges, e.g., 3-12. */
49 static int curr_value
;
50 static int upper_bound
;
54 if (++curr_value
>= upper_bound
)
63 default: return error_value
;
64 case ',': str
++; break;
65 case '$': str
++; return end_word
;
66 case '0': case '1': case '2': case '3': case '4':
67 case '5': case '6': case '7': case '8': case '9':
68 for (curr_value
= 0; isdigit ((unsigned char)(*str
)); str
++)
69 curr_value
= curr_value
* 10 + (*str
- '0');
74 for (size
= 1, upper_bound
= 0;
75 isdigit ((unsigned char)(*++str
));
76 upper_bound
= upper_bound
* 10 + (*str
- '0'));
78 if (upper_bound
<= curr_value
|| upper_bound
> hi_bound
)
81 return curr_value
>= lo_bound
&& curr_value
<= hi_bound
82 ? curr_value
: error_value
;