28 std::vector<mp_integer> numbers(input_numbers);
29 std::sort(numbers.begin(), numbers.end());
30 if(numbers.front() == numbers.back())
33 std::stringstream number_range;
35 auto start_number = numbers.front();
37 for(std::vector<mp_integer>::const_iterator it = numbers.begin();
41 const auto number = *it;
42 const auto next = std::next(it);
45 if(next != numbers.end() && *next <= number + 1)
49 if(start_number != numbers.front())
52 if(number == start_number)
54 number_range << number;
56 else if(number == start_number + 1)
58 number_range << start_number <<
',' << number;
62 number_range << start_number <<
'-' << number;
65 if(next != numbers.end())
70 return number_range.str();
75 const std::string &number_range,
76 std::vector<mp_integer> &numbers,
77 bool last_number_is_set,
80 if(!last_number_is_set && is_range)
83 "unterminated number range '" +
integer2string(*(++numbers.rbegin())) +
87 if(!last_number_is_set)
90 "invalid number range '" + number_range +
"'");
99 if(begin_range > end_range)
102 "lower bound must not be larger than upper bound '" +
105 for(
mp_integer i = begin_range; i < end_range; ++i)
106 numbers.push_back(i);
109 numbers.push_back(end_range);
115 std::vector<mp_integer> numbers(1, 0);
116 bool last_number_is_set =
false;
117 bool is_range =
false;
119 for(
char c : number_range)
121 if(
'0' <= c && c <=
'9')
123 numbers.back() *= 10;
124 numbers.back() += c -
'0';
125 last_number_is_set =
true;
129 append_numbers(number_range, numbers, last_number_is_set, is_range);
131 numbers.push_back(0);
132 last_number_is_set =
false;
137 if(!last_number_is_set)
140 "lower bound missing in number range '" + number_range +
"'");
142 numbers.push_back(0);
143 last_number_is_set =
false;
149 std::string(
"character '") + c +
"' not allowed in number range");
152 append_numbers(number_range, numbers, last_number_is_set, is_range);
Thrown when failing to deserialize a value from some low level format, like JSON or raw bytes.
const std::string integer2string(const mp_integer &n, unsigned base)
#define PRECONDITION(CONDITION)
#define POSTCONDITION(CONDITION)