std::map<std::string, std::string> parseMap(const std::string &str) { std::map<std::string, std::string> config; ParseState state; state.str = &str; state.pos = 0; std::pair<std::string, std::string> pair; while (parsePair(state, pair)) { config[pair.first] = pair.second; } return config; }
void Database::parseData( map<string,string>& data ) { data.clear(); string name; string value; if ( _currentKeyValue.length() ) { data[ _key ] = _currentKeyValue; _currentKeyValue.clear(); } while ( !parsePair( name, value ) ) { if ( name == _key ) { _currentKeyValue = value; break; } data[ name ] = value; } }
void JsonParser::parseMembers( JsonScanner & scanner, std::vector<JsonValue *> * members ) { JsonValue * value; try { value = parsePair( scanner ); } catch ( const std::exception & e ) { throw; } members->push_back( value ); JsonToken token; try { token = scanner.getNextToken(); } catch ( const std::exception & e ) { throw; } switch( token.getType() ) { case JsonTypes::COMMA: try { parseMembers( scanner, members ); } catch ( const std::exception & e ) { throw; } break; case JsonTypes::CLOSE_BRACE: return; default: throw MemberParsingException(); break; } }
bool GwfObjectInfoReader::read(const QDomDocument& document) { if (mIsOwner) del(); mLastError.clear(); QDomElement root = document.documentElement(); if (root.tagName() != "GWF") { mLastError = QString(QObject::tr("Given document has unsupported format %1").arg(root.tagName())); return false; } else { QStringList v_list = root.attribute("version").split("."); mVersion.first = v_list.first().toInt(); mVersion.second = v_list.last().toInt(); if (mVersion != qMakePair(1, 6) && mVersion != qMakePair(2, 0)) { mLastError = QString(QObject::tr("Version %1 of GWF files not supported.\n" "Just 1.6 and 2.0 versions supported.")).arg(root.attribute("version")); return false; } } // get static sector QDomElement staticSector = root.firstChildElement("staticSector"); // parse nodes QDomElement element = staticSector.firstChildElement("node"); while (!element.isNull()) { if (!parseNode(element)) return false; element = element.nextSiblingElement("node"); } // parse arcs element = staticSector.firstChildElement("arc"); while (!element.isNull()) { if (!parsePair(element)) return false; element = element.nextSiblingElement("arc"); } // parse pairs element = staticSector.firstChildElement("pair"); while (!element.isNull()) { if (!parsePair(element)) return false; element = element.nextSiblingElement("pair"); } // parse bus element = staticSector.firstChildElement("bus"); while (!element.isNull()) { if (!parseBus(element)) return false; element = element.nextSiblingElement("bus"); } // parse contour element = staticSector.firstChildElement("contour"); while (!element.isNull()) { if (!parseContour(element)) return false; element = element.nextSiblingElement("contour"); } return true; }