list<Item*> Parser::parseItems() { Item* item = parseItem(); list<Item*> itemRest = parseItemsRest(); itemRest.push_front( item ); return itemRest; }
void ArgMap::parseLongOption( const string& keyvalue, bool strict ) { string::size_type pos, begin, end; string name; if( ( pos = keyvalue.find( "=" ) ) == string::npos ) { parseItem( keyvalue, strict ); return; } begin = keyvalue.find_first_not_of( " \t", 0 ); end = keyvalue.find_last_not_of( " \t", pos - 1 ); name = keyvalue.substr( begin, end - begin + 1 ); if( strict && !m_long.count( name ) ) { throw ArgException( "ArgMap: Undefined parameter '" + name + "'" ); } begin = keyvalue.find_first_not_of( " \t", pos + 1 ); end = keyvalue.find_last_not_of( " \t", string::npos ); keyvalue[begin] == '"' ? begin++ : begin; keyvalue[end] == '"' ? end-- : end; if( begin != string::npos ) { m_arg[m_long[name]].value = keyvalue.substr( begin, end - begin + 1 ); } }
void SWParse::parsePage(ScribusDoc* doc, int page) { uint cnt = 0; uint docItemsCount=doc->Items->count(); if (docItemsCount == 0) return; for (uint a = 0; a < docItemsCount; ++a) { PageItem* b = doc->Items->at(a); if (b->OwnPage == page) ++cnt; } doc->scMW()->mainWindowProgressBar->setMaximum(cnt); doc->view()->GotoPage(page); uint i = 0; for (uint a = 0; a < docItemsCount; ++a) { PageItem* b = doc->Items->at(a); if (b->OwnPage == page) { doc->scMW()->mainWindowProgressBar->setValue(++i); parseItem(b); } } doc->scMW()->mainWindowProgressBar->setValue(cnt); }
Internal::RssItemList parse(QNetworkReply *reply) { QUrl source = reply->request().url(); requestUrl = source.toString(); streamReader.setDevice(reply); Internal::RssItemList list; while (!streamReader.atEnd()) { switch (streamReader.readNext()) { case QXmlStreamReader::StartElement: if (streamReader.name() == QLatin1String("item")) list.append(parseItem()); else if (streamReader.name() == QLatin1String("title")) blogName = streamReader.readElementText(); else if (streamReader.name() == QLatin1String("link")) { if (!streamReader.namespaceUri().isEmpty()) break; QString favIconString(streamReader.readElementText()); QUrl favIconUrl(favIconString); favIconUrl.setPath(QLatin1String("favicon.ico")); blogIcon = favIconUrl.toString(); } break; default: break; } } return list; }
void AISUpdate::parseEmbeddedItem(const LLSD& item) { // a single item (_embedded in a link) if (item.has("item_id")) { if (mItemIds.end() != mItemIds.find(item["item_id"].asUUID())) { parseItem(item); } } }
XmlTree::XmlTree( const std::string &xmlString, ParseOptions parseOptions ) { std::string strCopy( xmlString ); rapidxml::xml_document<> doc; // character type defaults to char if( parseOptions.getParseComments() ) doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( &strCopy[0] ); else doc.parse<rapidxml::parse_doctype_node>( &strCopy[0] ); parseItem( doc, NULL, this, parseOptions ); setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it }
PFILE_INFO_NODE ResponseParser::parseListRoot(char* json) { json_error_t error; json_t* root = json_loads(json,0, &error); if(!root) { fprintf(stderr, "error: on line %d: %s\n", error.line, error.text); //return 1; } json_t* items = json_object_get(root,"items"); if(!json_is_array(items)) { fprintf(stderr, "error: items is not an array\n"); //return 1; } PFILE_INFO_NODE start,current,end; start = current = end = NULL; for(int i = 0; i < json_array_size(items); i++) { json_t* data = json_array_get(items, i); json_t* parents = json_object_get(data, "parents"); PFILE_INFO_NODE node = NULL; if (parents != NULL) { json_t* parent = json_array_get(parents,0); json_t* is_root_json = json_object_get(parent,"isRoot"); if ( is_root_json == json_true()) { PFILE_INFO info = parseItem(data); if (info != NULL) { PFILE_INFO_NODE node = new FILE_INFO_NODE(); node->info = info; node->next = NULL; if (start == NULL) { start = end = current = node; } else { current->next = node; end = node; current = current->next; } } } } } return start; }
bool Settings::load() { XOJ_CHECK_TYPE(Settings); xmlKeepBlanksDefault(0); if (!g_file_test(filename.c_str(), G_FILE_TEST_EXISTS)) { g_warning("configfile does not exist %s\n", filename.c_str()); return false; } xmlDocPtr doc = xmlParseFile(filename.c_str()); if (doc == NULL) { g_warning("Settings::load:: doc == null, could not load Settings!\n"); return false; } xmlNodePtr cur = xmlDocGetRootElement(doc); if (cur == NULL) { g_message("The settings file \"%s\" is empty", filename.c_str()); xmlFreeDoc(doc); return false; } if (xmlStrcmp(cur->name, (const xmlChar*) "settings")) { g_message("File \"%s\" is of the wrong type", filename.c_str()); xmlFreeDoc(doc); return false; } cur = xmlDocGetRootElement(doc); cur = cur->xmlChildrenNode; while (cur != NULL) { parseItem(doc, cur); cur = cur->next; } xmlFreeDoc(doc); loadButtonConfig(); return true; }
void SWParse::parseSelection(ScribusDoc* doc) { uint docSelectionCount = doc->m_Selection->count(); if (docSelectionCount == 0) return; doc->scMW()->mainWindowProgressBar->setMaximum(docSelectionCount); for (uint i=0; i < docSelectionCount; ++i) { doc->scMW()->mainWindowProgressBar->setValue(i); parseItem(doc->m_Selection->itemAt(i)); } // for items doc->scMW()->mainWindowProgressBar->setValue(docSelectionCount); }
void XmlTree::loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const XmlTree::ParseOptions &parseOptions ) { auto buf = dataSource->getBuffer(); size_t dataSize = buf->getSize(); unique_ptr<char[]> bufString( new char[dataSize+1] ); memcpy( bufString.get(), buf->getData(), buf->getSize() ); bufString.get()[dataSize] = 0; rapidxml::xml_document<> doc; // character type defaults to char if( parseOptions.getParseComments() ) doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( bufString.get() ); else doc.parse<rapidxml::parse_doctype_node>( bufString.get() ); parseItem( doc, NULL, result, parseOptions ); result->setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it }
void parseItem( const rapidxml::xml_node<> &node, XmlTree *parent, XmlTree *result, const XmlTree::ParseOptions &options ) { *result = XmlTree( node.name(), node.value(), parent ); for( const rapidxml::xml_node<> *item = node.first_node(); item; item = item->next_sibling() ) { XmlTree::NodeType type; switch( item->type() ) { case rapidxml::node_element: type = XmlTree::NODE_ELEMENT; break; case rapidxml::node_cdata: { if( options.getCollapseCData() ) { result->setValue( result->getValue() + item->value() ); continue; } else { type = XmlTree::NODE_CDATA; } } break; case rapidxml::node_comment: type = XmlTree::NODE_COMMENT; break; case rapidxml::node_doctype: { result->setDocType( item->value() ); continue; } case rapidxml::node_data: { if( ! options.getIgnoreDataChildren() ) type = XmlTree::NODE_DATA; else continue; } break; default: continue; } result->getChildren().push_back( unique_ptr<XmlTree>( new XmlTree ) ); parseItem( *item, result, result->getChildren().back().get(), options ); result->getChildren().back()->setNodeType( type ); } for( rapidxml::xml_attribute<> *attr = node.first_attribute(); attr; attr = attr->next_attribute() ) result->getAttributes().push_back( XmlTree::Attr( result, attr->name(), attr->value() ) ); }
void AISUpdate::parseEmbeddedItems(const LLSD& items) { // a map of items (_embedded in a category) for(LLSD::map_const_iterator itemit = items.beginMap(), itemend = items.endMap(); itemit != itemend; ++itemit) { const LLUUID item_id((*itemit).first); const LLSD& item_map = (*itemit).second; if (mItemIds.end() == mItemIds.find(item_id)) { LL_DEBUGS("Inventory") << "Ignoring item not in items list " << item_id << LL_ENDL; } else { parseItem(item_map); } } }
QList<BillItem::Ptr> DBItemDAO::getAll() { qCDebug(lcPersistence) << "Entering DBItemDAO::getAll"; QList<BillItem::Ptr> items; QSqlQuery query(m_database); query.prepare("SELECT * FROM ITEM WHERE DELETED = 0"); if (!query.exec()) { qCCritical(lcPersistence) << "retrieving billItems failed" + query.lastError().text(); throw new PersistenceException("retrieving billItems failed" + query.lastError().text()); } while(query.next()) { items.append(parseItem(query.record())); } return items; }
BillItem::Ptr DBItemDAO::get(int id) { qCDebug(lcPersistence) << "Entering DBItemDAO::get with id " + QString::number(id); QSqlQuery query(m_database); query.prepare("SELECT * FROM ITEM WHERE ID = ?"); query.addBindValue(id); if (!query.exec()) { qCCritical(lcPersistence) << "retrieving billItem failed" + query.lastError().text(); throw new PersistenceException("retrieving billItem failed" + query.lastError().text()); } if (!query.next()) { qCDebug(lcPersistence) << "no billItem with id'" + QString::number(id) + "' found"; throw new PersistenceException("no billItem with id'" + QString::number(id) + "' found"); } return parseItem(query.record()); }
QList<BillItem::Ptr> DBOfferItemDAO::getItemsOfOffer(int offerID) { qCDebug(lcPersistence) << "Entering DBOfferItemDAO::getItemsOfBill"; QList<BillItem::Ptr> items; QSqlQuery query(m_database); query.prepare("SELECT * FROM OFFER_ITEM NATURAL JOIN ITEM WHERE DELETED = 0 AND BILL = ?"); query.addBindValue(offerID); if (!query.exec()) { qCCritical(lcPersistence) << "retrieving offerItems failed" + query.lastError().text(); throw new PersistenceException("retrieving offerItems failed" + query.lastError().text()); } while(query.next()) { items.append(parseItem(query.record())); } return items; }
bool RSS10Parser::parseXmlDoc(xmlDocPtr doc) { if (!doc) return false; xmlNode* node = xmlDocGetRootElement(doc); if (!node) { xmlFreeDoc(doc); return false; } for (; node; node = node->next) { String name(reinterpret_cast<const char*>(node->name)); if (name == "RDF") { xmlNode* childnode = node->children; for (; childnode; childnode = childnode->next) { if (childnode->type == XML_ELEMENT_NODE) { name = String(reinterpret_cast<const char*>(childnode->name)); name.makeLower(); if (name == "channel") { BLACKBERRY_ASSERT(!m_root); if (!m_root) m_root = parseFeed(childnode->children); } else if (name == "item") { BLACKBERRY_ASSERT(m_root); if (m_root) { RSSItem* item = parseItem(childnode->children); if (item) m_root->m_items.append(item); } } } } } } xmlFreeDoc(doc); return m_root; }
YT3ListParser::YT3ListParser(const QByteArray &bytes) { QScriptEngine engine; QScriptValue json = engine.evaluate("(" + QString::fromUtf8(bytes) + ")"); nextPageToken = json.property("nextPageToken").toString(); QScriptValue items = json.property("items"); videos.reserve(items.property("length").toInt32() - 1); if (items.isArray()) { QScriptValueIterator it(items); while (it.hasNext()) { it.next(); QScriptValue item = it.value(); // For some reason the array has an additional element containing its size. if (item.isObject()) parseItem(item); } } // TODO suggestions! }
int main(void) { bool isRunning = true; char* pUserInput; char* userInput = NULL; item* it = NULL; userInput = malloc(sizeof(char)*1024); assert(userInput != NULL); pUserInput = userInput; performRotCheck(); system(CALL_DOWNLOAD_SCRIPT); while(isRunning) { printf(">>"); char command = 0; fgets(userInput, MAX_COMMAND_LEN-1, stdin); if(!decodeCommand(userInput, &command)) { printf("\tCommand error.\n"); continue; } else if(command != 0) { it = parseItem(userInput); if(it == NULL) { printf("The creation of item you provided was not successful.\n"); continue; } if(!performCommand(command, it)) { fprintf(stderr, "Error.\n"); } } else { isRunning = false; } releaseItem(&it); } free(pUserInput); }
void AISUpdate::parseContent(const LLSD& update) { if (update.has("linked_id")) { parseLink(update); } else if (update.has("item_id")) { parseItem(update); } if (update.has("category_id")) { parseCategory(update); } else { if (update.has("_embedded")) { parseEmbedded(update["_embedded"]); } } }
Bencode *Bencode::fromRaw(const QByteArray &raw) { int pos = 0; Bencode *res = parseItem(raw, pos); return res; }
void Item::initializeStaticData() { if (s_initialized) return; s_initialized = true; { // grab the materials lookup table QFile materials_file(":/game/materials.txt"); materials_file.open(QFile::ReadOnly); QTextStream stream(&materials_file); while (! stream.atEnd()) { QString line = stream.readLine().trimmed(); if (line.isEmpty() || line.startsWith("#")) continue; QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts); Q_ASSERT(parts.size() == 2); int part_index = 0; QString name = parts.at(part_index++); Material value = static_cast<Material>(parts.at(part_index++).toInt()); s_materials.insert(name, value); Q_ASSERT(parts.size() == part_index); } materials_file.close(); } { // grab the item data from resources QFile item_data_file(":/game/items.txt"); item_data_file.open(QFile::ReadOnly); QTextStream stream(&item_data_file); while (! stream.atEnd()) { QString line = stream.readLine().trimmed(); if (line.isEmpty() || line.startsWith("#")) continue; QStringList parts = line.split(QRegExp("\\s+"), QString::SkipEmptyParts); Q_ASSERT(parts.size() == 11); int part_index = 0; ItemData * item_data = new ItemData; // ID bool ok; item_data->id = (ItemType)parts.at(part_index++).toInt(&ok, 0); Q_ASSERT(ok); item_data->name = parts.at(part_index++); item_data->stack_height = parts.at(part_index++).toInt(); item_data->placeable = static_cast<bool>(parts.at(part_index++).toInt()); item_data->item_activatable = static_cast<bool>(parts.at(part_index++).toInt()); item_data->physical = static_cast<bool>(parts.at(part_index++).toInt()); item_data->diggable = static_cast<bool>(parts.at(part_index++).toInt()); item_data->block_activatable = static_cast<bool>(parts.at(part_index++).toInt()); item_data->safe = static_cast<bool>(parts.at(part_index++).toInt()); item_data->hardness = static_cast<float>(parts.at(part_index++).toFloat()); // material QString material_name = parts.at(part_index++); Q_ASSERT(s_materials.contains(material_name)); item_data->material = s_materials.value(material_name); Q_ASSERT(parts.size() == part_index); s_item_data.insert(item_data->id, item_data); } item_data_file.close(); } // create an indexing using name for (QHash<Item::ItemType, Item::ItemData*>::iterator it = s_item_data.begin(); it != s_item_data.end(); ++it) { Item::ItemData * item_data = it.value(); s_item_by_name.insert(item_data->name, item_data); } { // grab the recipe data from resources QFile recipe_file(":/game/recipes.txt"); recipe_file.open(QFile::ReadOnly); QTextStream stream(&recipe_file); bool recipe_start = true; bool done_parsing_design = false; _Item::Recipe * recipe = NULL; QStringList design; while (! stream.atEnd()) { QString line = stream.readLine().trimmed(); if (line.isEmpty() || line.startsWith("#")) { if (! recipe_start) { Q_ASSERT(recipe != NULL); if (recipe->size.width() == 0) { qSort(recipe->ingredients); } s_recipes.insert(*recipe, recipe); recipe = NULL; recipe_start = true; } continue; } if (recipe_start) { // get the result information Q_ASSERT(recipe == NULL); recipe = new _Item::Recipe; recipe->result = parseItem(line); recipe_start = false; done_parsing_design = false; design.clear(); } else if (line.contains("=")) { if (! done_parsing_design) { done_parsing_design = true; // handle completed design if (design.size() == 0) recipe->size = QSize(0, 0); else recipe->size = QSize(design.at(0).size(), design.size()); recipe->design.resize(recipe->size.width() * recipe->size.height()); for (int y = 0; y < design.size(); y++) { QString design_line = design.at(y); for (int x = 0; x < design_line.size(); x++) { int palette_index_plus_one = design_line.mid(x, 1).toInt(); recipe->design.replace(y*recipe->size.width()+x, palette_index_plus_one-1); } } } // this line is ingredient palette QStringList parts = line.split("=", QString::KeepEmptyParts); int part_index = 0; int ingredient_count = parts.at(part_index++).toInt(); QStringList ingredient_parts = parts.at(part_index++).split(","); _Item::Ingredient ingredient; ingredient.item = parseItem(ingredient_parts.at(0), &ingredient.metadata_matters); ingredient.result = (ingredient_parts.size() > 1) ? parseItem(ingredient_parts.at(1)) : Item(); Q_ASSERT(part_index == parts.size()); recipe->ingredients.append(ingredient); Q_ASSERT(ingredient_count == recipe->ingredients.size()); Q_UNUSED(ingredient_count); } else { Q_ASSERT(! done_parsing_design); // design design << line; } } recipe_file.close(); } // create mapping from item type for (QHash<_Item::Recipe, _Item::Recipe *>::iterator it = s_recipes.begin(); it != s_recipes.end(); ++it) { _Item::Recipe * recipe = it.value(); s_item_recipe.insert(recipe->result, recipe); } }
void XMLBackgroundParser::loadBackground(const std::string &fileName, Background* background) { if(validateSchema("textures/backgrounds/backgrounds.xsd", fileName.c_str()) == 0) parseItem(fileName, background); }