int countWords (const char string[]) { int i, wordCount = 0; bool lookingForWord = true, wordchar (const char c), numchar (const char c); for ( i = 0; string[i] != '\0'; ++i ) if ( wordchar (string[i]) || numchar (string[i]) ) { if ( lookingForWord ) { ++wordCount; lookingForWord = false; } } else lookingForWord = true; return wordCount; }
node::number_holder::number_holder(const std::string& expr, size_t& ptr, size_t len) { //-?(0|1-9[0-9]+)(.[0-9]+)?([eE][+-]?[0-9]+)? int state = 0; size_t tmp = ptr; size_t tmp2 = ptr; std::string x; while(tmp < len) { unsigned c = numchar(expr[tmp]); unsigned ns = (numdfa[state] >> (4 * c)) & 0xF; if(ns == 0xF) break; else state = ns; tmp++; } if(!(numdfa[state] >> 28)) goto bad; x = expr.substr(ptr, tmp - ptr); ptr = tmp; try { if(regex_match("[0-9]+", x)) { n.n1 = parse_value<uint64_t>(x); sub = 1; return; } } catch(...) {} try { if(regex_match("[+-]?[0-9]+", x)) { n.n2 = parse_value<int64_t>(x); sub = 2; return; } } catch(...) {} try { n.n0 = parse_value<double>(x); sub = 0; return; } catch(...) {} bad: throw error(ERR_INVALID_NUMBER, PARSE_NUMBER, tmp2); }