39 while (p < param.length()) {
40 size_t q = param.find_first_of(
"[,", p);
41 if (q == string::npos) {
42 return parse_word(
trim(param.substr(p)));
44 if (!parse_word(
trim(param.substr(p, q - p)))) {
48 if (param[q] ==
'[') {
52 p = param.find(
"]", q + 2);
53 if ( p == string::npos) {
54 nout <<
"Unclosed open bracket.\n";
57 if (!parse_bracket(param.substr(q + 1, p - q - 1))) {
75 void RangeDescription::
76 output(std::ostream &out)
const {
77 bool first_time =
true;
78 RangeList::const_iterator ri;
79 for (ri = _range_list.begin(); ri != _range_list.end(); ++ri) {
80 const Range &range = (*ri);
85 if (range._from_code == range._to_code) {
86 out << range._from_code;
88 out << range._from_code <<
"-" << range._to_code;
98 bool RangeDescription::
99 parse_word(
const string &word) {
105 size_t hyphen = word.find(
'-');
106 if (hyphen == string::npos) {
109 if (!parse_code(word, code)) {
116 int from_code, to_code;
117 if (!parse_code(word.substr(0, hyphen), from_code)) {
120 if (!parse_code(word.substr(hyphen + 1), to_code)) {
123 add_range(from_code, to_code);
133 bool RangeDescription::
134 parse_code(
const string &word,
int &code) {
135 string str =
trim(word);
136 const char *nptr = str.c_str();
138 code = strtol(nptr, &endptr, 0);
139 if (*endptr ==
'\0') {
143 nout <<
"Invalid Unicode value: " << word <<
"\n";
150 bool RangeDescription::
151 parse_bracket(
const string &str) {
152 string::const_iterator si;
154 while (si != str.end()) {
157 if (si != str.end() && (*si) ==
'-') {
160 if (si == str.end()) {
165 add_range(ch, (*si));
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool parse_parameter(const std::string ¶m)
Parses a string of comma- and hyphen-delimited unicode values, in decimal and/or hex,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
string trim(const string &str)
Returns a new string representing the contents of the given string with both leading and trailing whi...