std::list<std::string> tokenizeStringByOperators(const std::string &originalString) { std::list<std::string> tokens; std::string delimiter = "*/+-)(^"; size_t prev = 0; size_t next = 0; while ((next = originalString.find_first_of(delimiter, prev)) != std::string::npos) { if (next - prev != 0) { // trim and push back number std::string number = originalString.substr(prev, next - prev); leftTrim(number); rightTrim(number); if (number != " ") { tokens.push_back(number); } // trim and push back operator std::string oper = originalString.substr(next, 1); leftTrim(oper); rightTrim(oper); if (oper != " ") { tokens.push_back(oper); } // increment by operator length prev = next + 1; } else { // leading operator if (originalString.substr(next, 1) == "-") { // if leading op is "-" we need to check if we need to parse a negative number // check if this is the first token in stream, or the previous token is not a number if (tokens.size() == 0 || !isANumber(tokens.back())) { next = originalString.find_first_of(delimiter, prev + 1); std::string negativeNumber = originalString.substr(prev, next - prev); // trim and push back negative number leftTrim(negativeNumber); rightTrim(negativeNumber); if (negativeNumber != " ") { tokens.push_back(negativeNumber); } // increment by operator length prev = next; } } else { // parse the operator tokens.push_back(originalString.substr(next, 1)); // increment by operator length prev = next + 1; } } } if (prev < originalString.size()) { // trim and push back last token std::string last = originalString.substr(prev); leftTrim(last); rightTrim(last); tokens.push_back(last); } return tokens; }
string trim (string str) { return rightTrim (leftTrim (str)); }
void StringEx::trim() { rightTrim(); leftTrim(); }
char* StringEx::trim(char* s) { rightTrim(s); return leftTrim(s); }
bool RESGen::LoadExludeFile(std::string &listfile) { if (listfile.empty()) { // Was called without a proper argument, fail return false; } if (CompareStrEndNoCase(listfile, ".rfa")) { // .rfa extension missing, add it listfile += ".rfa"; } File f(listfile, "rt"); // Text mode if (f == NULL) { // Error opening file, abort printf("Error: Could not open the specified exclude list %s!\n", listfile.c_str()); return false; } checkforexcludes = true; // We want to check for excludes // loop to read file.. each line is an exclude std::string line; char linebuf[1024]; // optimal size for VString allocs while (fgets(linebuf, 1024, f)) { line += linebuf; if (line[line.length() - 1] == '\n') { leftTrim(line); rightTrim(line); if (line.compare(0, 2, "//") && line.length() != 0) { // Convert backslashes to slashes replaceCharAll(line, '\\', '/'); // Not a comment or empty line excludelist[strToLowerCopy(line)] = line; } line.clear(); } } if (line.length() > 0) { leftTrim(line); rightTrim(line); if (line.compare(0, 2, "//") && line.length() != 0) { // Convert backslashes to slashes replaceCharAll(line, '\\', '/'); // Not a comment or empty line excludelist[strToLowerCopy(line)] = line; } } return true; }