Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / gperf / src / Iterator.cpp
blob2bf4be1cedf2f69a0cbec695a9048e569b6dd0e4
1 // -*- C++ -*-
3 /**
4 * Copyright (C) 1989 Free Software Foundation, Inc.
5 * written by Douglas C. Schmidt (d.schmidt@vanderbilt.edu)
7 * This file is part of GNU GPERF.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "Iterator.h"
25 #include "ace/OS_NS_ctype.h"
27 /// Constructor for Iterator.
28 Iterator::Iterator (char *s,
29 int lo,
30 int hi,
31 int word_end,
32 int bad_val,
33 int key_end)
34 : str (s),
35 end (key_end),
36 end_word (word_end),
37 error_value (bad_val),
38 hi_bound (hi),
39 lo_bound (lo)
43 /// Provide an Iterator, returning the ``next'' value from the list of
44 /// valid values given in the constructor.
45 int
46 Iterator::operator() ()
48 // Variables to record the Iterator's status when handling ranges,
49 // e.g., 3-12.
51 static int size;
52 static int curr_value;
53 static int upper_bound;
55 if (size)
57 if (++curr_value >= upper_bound)
58 size = 0;
59 return curr_value;
61 else
63 while (*str)
64 switch (*str)
66 default: return error_value;
67 case ',': str++; break;
68 case '$': str++; return end_word;
69 case '0': case '1': case '2': case '3': case '4':
70 case '5': case '6': case '7': case '8': case '9':
71 for (curr_value = 0; ACE_OS::ace_isdigit (*str); str++)
73 curr_value = curr_value * 10 + *str - '0';
76 if (*str == '-')
78 for (size = 1, upper_bound = 0;
79 ACE_OS::ace_isdigit (*++str);
80 upper_bound = upper_bound * 10 + *str - '0')
82 // Do nothing.
85 if (upper_bound <= curr_value || upper_bound > hi_bound)
87 return error_value;
91 return curr_value >= lo_bound && curr_value <= hi_bound
92 ? curr_value
93 : error_value;
96 return end;