15 #include "rangeDescription.h"
16 #include "string_utils.h"
44 while (p < param.length()) {
45 size_t q = param.find_first_of(
"[,", p);
46 if (q == string::npos) {
47 return parse_word(trim(param.substr(p)));
49 if (!parse_word(trim(param.substr(p, q - p)))) {
53 if (param[q] ==
'[') {
57 p = param.find(
"]", q + 2);
58 if ( p == string::npos) {
59 nout <<
"Unclosed open bracket.\n";
62 if (!parse_bracket(param.substr(q + 1, p - q - 1))) {
82 void RangeDescription::
83 output(ostream &out)
const {
84 bool first_time =
true;
85 RangeList::const_iterator ri;
86 for (ri = _range_list.begin(); ri != _range_list.end(); ++ri) {
87 const Range &range = (*ri);
92 if (range._from_code == range._to_code) {
93 out << range._from_code;
95 out << range._from_code <<
"-" << range._to_code;
108 bool RangeDescription::
109 parse_word(
const string &word) {
115 size_t hyphen = word.find(
'-');
116 if (hyphen == string::npos) {
119 if (!parse_code(word, code)) {
126 int from_code, to_code;
127 if (!parse_code(word.substr(0, hyphen), from_code)) {
130 if (!parse_code(word.substr(hyphen + 1), to_code)) {
133 add_range(from_code, to_code);
147 bool RangeDescription::
148 parse_code(
const string &word,
int &code) {
149 string str = trim(word);
150 const char *nptr = str.c_str();
152 code = strtol(nptr, &endptr, 0);
153 if (*endptr ==
'\0') {
157 nout <<
"Invalid Unicode value: " << word <<
"\n";
167 bool RangeDescription::
168 parse_bracket(
const string &str) {
169 string::const_iterator si;
171 while (si != str.end()) {
174 if (si != str.end() && (*si) ==
'-') {
177 if (si == str.end()) {
182 add_range(ch, (*si));
bool parse_parameter(const string ¶m)
Parses a string of comma- and hyphen-delimited unicode values, in decimal and/or hex, including possible bracket-delimited ASCII characters, as may have been passed on a command line.