1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
38 #include <anna/core/util/MultiRangeExpression.hpp>
40 #include <anna/core/util/Tokenizer.hpp>
41 #include <anna/core/functions.hpp>
47 //using namespace anna;
52 //------------------------------------------------------------------------------
53 //---------------------------------------------- MultiRangeExpression::refresh()
54 //------------------------------------------------------------------------------
55 void anna::MultiRangeExpression::refresh(void) throw() {
56 anna::Tokenizer ranges, borders;
57 anna::Tokenizer::const_iterator ranges_it, borders_it;
59 unsigned int min, max;
62 if(a_literal == "") return;
64 ranges.apply(a_literal, ",");
66 for(ranges_it = ranges.begin(); ranges_it != ranges.end(); ranges_it ++) {
67 range = anna::Tokenizer::data(ranges_it);
68 borders.apply(range, "-");
69 borders_it = borders.begin();
71 if(borders_it != borders.end()) {
72 min = atoi(anna::Tokenizer::data(borders_it));
76 if(borders_it != borders.end()) {
77 max = atoi(anna::Tokenizer::data(borders_it));
81 for(register unsigned int k = min; k <= max; k++) {
84 if(k == UINT_MAX/* overflow */) break;
91 //------------------------------------------------------------------------------
92 //----------------------------------- MultiRangeExpression::getExpandedLiteral()
93 //------------------------------------------------------------------------------
94 std::string anna::MultiRangeExpression::getExpandedLiteral(void) const throw() {
96 std::map < unsigned int, int/*dummy*/ >::const_iterator it;
97 std::map < unsigned int, int/*dummy*/ >::const_iterator it_min(a_data.begin());
98 std::map < unsigned int, int/*dummy*/ >::const_iterator it_max(a_data.end());
100 for(it = it_min; it != it_max; it++) {
101 result += anna::functions::asString((*it).first);
105 int pos = result.size();
107 if(pos) result.erase(pos - 1);