//*********************************************************** //* Process a node that has the <noteresourceattribute> //*********************************************************** void ImportData::processResourceAttributes(ResourceAttributes &attributes) { bool atEnd = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "cameramake") { attributes.cameraMake = textValue().toStdString(); attributes.__isset.cameraMake = true; } if (name == "cameramodel") { attributes.cameraModel = textValue().toStdString(); attributes.__isset.cameraModel =true; } if (name == "filename") { attributes.fileName = textValue().toStdString(); attributes.__isset.fileName = true; } if (name == "recotype") { attributes.recoType = textValue().toStdString(); attributes.__isset.fileName = true; } if (name == "sourceurl") { attributes.sourceURL = textValue().toStdString(); attributes.__isset.sourceURL = true; } if (name == "altitude") { attributes.altitude = doubleValue(); attributes.__isset.altitude = true; } if (name == "longitude") { attributes.longitude = doubleValue(); attributes.__isset.longitude = true; } if (name == "altitude") { attributes.latitude = doubleValue(); attributes.__isset.latitude = true; } if (name == "timestamp") { attributes.timestamp = longValue(); attributes.__isset.timestamp = true; } if (name == "attachment") { attributes.attachment = booleanValue(); attributes.__isset.attachment = true; } if (name == "clientwillindex") { attributes.clientWillIndex = booleanValue(); attributes.__isset.clientWillIndex =true; } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "noteresourceattribute" && reader->isEndElement()) atEnd = true; } }
void StyleReader::startElementHandler(const char *tag, const char **attributes) { static const std::string BASE = "base"; static const std::string STYLE = "style"; if (BASE == tag) { myCollection.myBaseStyle = new BaseTextStyle(attributeValue(attributes, "family"), intValue(attributes, "fontSize")); } else if (STYLE == tag) { const char *idString = attributeValue(attributes, "id"); const char *name = attributeValue(attributes, "name"); if ((idString != 0) && (name != 0)) { TextKind id = (TextKind)atoi(idString); TextStyleDecoration *decoration; int fontSizeDelta = intValue(attributes, "fontSizeDelta"); Boolean3 bold = b3Value(attributes, "bold"); Boolean3 italic = b3Value(attributes, "italic"); int verticalShift = intValue(attributes, "vShift"); Boolean3 allowHyphenations = b3Value(attributes, "allowHyphenations"); bool isHyperlink = booleanValue(attributes, "isHyperlink"); if (booleanValue(attributes, "partial")) { decoration = new TextStyleDecoration(name, fontSizeDelta, bold, italic, verticalShift, allowHyphenations); } else { int spaceBefore = intValue(attributes, "spaceBefore"); int spaceAfter = intValue(attributes, "spaceAfter"); int leftIndent = intValue(attributes, "leftIndent"); int rightIndent = intValue(attributes, "rightIndent"); int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta"); AlignmentType alignment = ALIGN_UNDEFINED; const char *alignmentString = attributeValue(attributes, "alignment"); if (alignmentString != 0) { if (strcmp(alignmentString, "left") == 0) { alignment = ALIGN_LEFT; } else if (strcmp(alignmentString, "rigth") == 0) { alignment = ALIGN_RIGHT; } else if (strcmp(alignmentString, "center") == 0) { alignment = ALIGN_CENTER; } else if (strcmp(alignmentString, "justify") == 0) { alignment = ALIGN_JUSTIFY; } } double lineSpace = doubleValue(attributes, "lineSpace"); decoration = new FullTextStyleDecoration(name, fontSizeDelta, bold, italic, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpace, allowHyphenations); } if (isHyperlink) { decoration->setHyperlinkStyle(); } myCollection.myDecorationMap.insert(std::pair<TextKind,TextStyleDecoration*>(id, decoration)); } } }
//*********************************************************** //* This will take a <tag> node and parse out the values. //*********************************************************** void ImportData::processTagNode() { QLOG_DEBUG() << "Processing Tag Node"; Tag tag; bool tagIsDirty = false; bool atEnd = false; // Loop through until we are at the end of the </tag> while(!atEnd) { if (backup || importTags) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { tag.guid = textValue(); } if (name == "name") { tag.name = textValue(); } if (name == "updatesequencenumber") { tag.updateSequenceNum = intValue(); } if (name == "parentguid") { tag.parentGuid = textValue(); } if (name == "Dirty") { if (booleanValue()) tagIsDirty = true; else tagIsDirty = false; } } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "tag" && reader->isEndElement()) atEnd = true; } // We have a good tag, now let's save it to the database TagTable tagTable(global.db); QString name(tag.name); // Check if we have a tag by this name already. If we // do then we treat this as an update. qint32 lid = tagTable.findByName(name,0); if (lid <= 0) { lid = tagTable.getLid(tag.guid); } if (lid <= 0) { tagTable.add(0, tag,tagIsDirty, 0); } else { // qint32 oldLid = tagTable.getLid(tag.guid); // if (oldLid != lid) // tagTable.merge(oldLid, lid); tagTable.sync(lid, tag, 0); // notebookTable.updateGuid(lid, notebook.guid); tagTable.setDirty(lid, tagIsDirty); } return; }
void ZLTextStyleReader::startElementHandler(const char *tag, const char **attributes) { static const std::string BASE = "base"; static const std::string STYLE = "style"; if (BASE == tag) { myCollection.myBaseStyle.reset(new ZLTextBaseStyle(attributeValue(attributes, "family"), intValue(attributes, "fontSize"))); } else if (STYLE == tag) { const char *idString = attributeValue(attributes, "id"); const char *name = attributeValue(attributes, "name"); if ((idString != 0) && (name != 0)) { ZLTextKind id = (ZLTextKind)atoi(idString); ZLTextStyleDecoration *decoration; int fontSizeDelta = intValue(attributes, "fontSizeDelta"); ZLBoolean3 bold = b3Value(attributes, "bold"); ZLBoolean3 italic = b3Value(attributes, "italic"); int verticalShift = intValue(attributes, "vShift"); ZLBoolean3 allowHyphenations = b3Value(attributes, "allowHyphenations"); if (booleanValue(attributes, "partial")) { decoration = new ZLTextStyleDecoration(name, fontSizeDelta, bold, italic, verticalShift, allowHyphenations); } else { int spaceBefore = intValue(attributes, "spaceBefore"); int spaceAfter = intValue(attributes, "spaceAfter"); int leftIndent = intValue(attributes, "leftIndent"); int rightIndent = intValue(attributes, "rightIndent"); int firstLineIndentDelta = intValue(attributes, "firstLineIndentDelta"); ZLTextAlignmentType alignment = ALIGN_UNDEFINED; const char *alignmentString = attributeValue(attributes, "alignment"); if (alignmentString != 0) { if (strcmp(alignmentString, "left") == 0) { alignment = ALIGN_LEFT; } else if (strcmp(alignmentString, "rigth") == 0) { alignment = ALIGN_RIGHT; } else if (strcmp(alignmentString, "center") == 0) { alignment = ALIGN_CENTER; } else if (strcmp(alignmentString, "justify") == 0) { alignment = ALIGN_JUSTIFY; } } const int lineSpacingPercent = intValue(attributes, "lineSpacingPercent", -1); const double lineSpace = (lineSpacingPercent == -1) ? 0.0 : (lineSpacingPercent / 100.0); decoration = new ZLTextFullStyleDecoration(name, fontSizeDelta, bold, italic, spaceBefore, spaceAfter, leftIndent, rightIndent, firstLineIndentDelta, verticalShift, alignment, lineSpace, allowHyphenations); } const char *hyperlink = attributeValue(attributes, "hyperlink"); if (hyperlink != 0) { decoration->setHyperlinkStyle(hyperlink); } const char *fontFamily = attributeValue(attributes, "family"); if (fontFamily != 0) { decoration->FontFamilyOption.setValue(fontFamily); } myCollection.myDecorationMap.insert(std::pair<ZLTextKind,ZLTextStyleDecoration*>(id, decoration)); } } }
JSValue* BalInstance::defaultValue(ExecState* exec, JSType hint) const { if (hint == (JSType)StringType) return stringValue(exec); if (hint == (JSType)NumberType) return numberValue(exec); if (hint == (JSType)BooleanType) return booleanValue(); return valueOf(exec); }
JSValue* CInstance::defaultValue(JSType hint) const { if (hint == StringType) return stringValue(); if (hint == NumberType) return numberValue(); if (hint == BooleanType) return booleanValue(); return valueOf(); }
//*********************************************************** //* Process a <noteresource> node. //*********************************************************** void ImportEnex::processResource(Resource &resource) { bool atEnd = false; resource.active = true; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); QUuid uuid; QString g = uuid.createUuid().toString().replace("{","").replace("}",""); resource.guid = g; if (name == "active") { resource.active = booleanValue(); } if (name == "mime") { resource.mime = textValue(); } if (name == "duration") { resource.duration = shortValue(); } if (name == "height") { resource.height = shortValue(); } if (name == "width") { resource.width = shortValue(); } if (name == "data") { Data d; resource.data = d; processData("Data", resource.data); } if (name == "alternate-data") { Data d; resource.alternateData = d; processData("AlternateData", resource.data); } if (name == "recognition-data") { Data d; resource.recognition = d; processData("RecognitionData", resource.recognition); } if (name == "resource-attributes") { ResourceAttributes ra; resource.attributes = ra; processResourceAttributes(resource.attributes); } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "resource" && reader->isEndElement()) atEnd = true; } }
//*********************************************************** //* Import a shared notebook //*********************************************************** void ImportData::processSharedNotebookNode() { SharedNotebook sharedNotebook; bool sharedNotebookIsDirty = false; QLOG_ERROR() << "Shared notebook database support not implemented yet"; bool atEnd = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "id") { sharedNotebook.id = intValue(); sharedNotebook.__isset.id = true; } if (name == "userid") { sharedNotebook.userId = intValue(); sharedNotebook.__isset.userId = true; } if (name == "email") { sharedNotebook.email = textValue().toStdString(); sharedNotebook.__isset.email =true; } if (name == "notebookguid") { sharedNotebook.notebookGuid = textValue().toStdString(); sharedNotebook.__isset.notebookGuid = true; } if (name == "sharekey") { sharedNotebook.shareKey = textValue().toStdString(); sharedNotebook.__isset.shareKey = true; } if (name == "username") { sharedNotebook.username = textValue().toStdString(); sharedNotebook.__isset.username = true; } if (name == "servicecreated") { sharedNotebook.serviceCreated = longValue(); sharedNotebook.__isset.serviceCreated = true; } if (name == "dirty") { if (booleanValue()) sharedNotebookIsDirty = true; else sharedNotebookIsDirty = false; } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "sharednotebook" && reader->isEndElement()) atEnd = true; } return; }
void RepoParams::writeInfoFile(const std::string& fileName) const { logMsg(LOG_DEBUG, "Saving info file in \'%s\'", fileName.c_str()); StringToStringMap params; switch(formatType) { case FormatTypeText: params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_TEXT)); break; case FormatTypeBinary: params.insert(StringToStringMap::value_type(INFO_FILE_FORMAT_TYPE, INFO_FILE_FORMAT_TYPE_BINARY)); break; default: assert(0); }; //switch(formatType); switch(compressionType) { case CompressionTypeNone: params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_NONE)); break; case CompressionTypeGzip: params.insert(StringToStringMap::value_type(INFO_FILE_COMPRESSION_TYPE, INFO_FILE_COMPRESSION_TYPE_GZIP)); break; default: assert(0); }; //switch(compressionType); params.insert(StringToStringMap::value_type(INFO_FILE_VERSION, version)); params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs))); params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_DIRS, saveStringVector(filterProvidesByDirs))); params.insert(StringToStringMap::value_type(INFO_FILE_FILTER_PROVIDES_BY_REFS, booleanValue(filterProvidesByRefs))); params.insert(StringToStringMap::value_type(INFO_FILE_EXCLUDE_REQUIRES, saveStringVector(excludeRequiresRegExp))); params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_BINARY, booleanValue(changeLogBinary))); params.insert(StringToStringMap::value_type(INFO_FILE_CHANGELOG_SOURCES, booleanValue(changeLogSources))); params.insert(StringToStringMap::value_type(INFO_FILE_MD5SUM, REPO_INDEX_MD5SUM_FILE)); for(StringToStringMap::const_iterator it = userParams.begin();it != userParams.end();it++) params.insert(*it); writeInfoFileParamsToDisk(fileName, params); }
//*********************************************************** //* Process a shared notebook //*********************************************************** void ImportData::processLinkedNotebookNode() { LinkedNotebook linkedNotebook; bool linkedNotebookIsDirty=false; QLOG_ERROR() << "Linked notebook database support not implemented yet"; bool atEnd = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { linkedNotebook.guid = textValue().toStdString(); linkedNotebook.__isset.guid = true; } if (name == "shardid") { linkedNotebook.shardId = textValue().toStdString(); linkedNotebook.__isset.shardId = true; } if (name == "updatesequencenumber") { linkedNotebook.updateSequenceNum = intValue(); linkedNotebook.__isset.updateSequenceNum = true; } if (name == "sharekey") { linkedNotebook.shareKey = textValue().toStdString(); linkedNotebook.__isset.shareKey = true; } if (name == "sharename") { linkedNotebook.shareName = textValue().toStdString(); linkedNotebook.__isset.shareName = true; } if (name == "uri") { linkedNotebook.uri = textValue().toStdString(); linkedNotebook.__isset.uri = true; } if (name == "username") { linkedNotebook.username = textValue().toStdString(); linkedNotebook.__isset.username = true; } if (name == "dirty") { if (booleanValue()) linkedNotebookIsDirty = true; } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "linkednotebook" && reader->isEndElement()) atEnd = true; } return; }
//*********************************************************** //* Process a node that has the <noteresourceattribute> //*********************************************************** void ImportEnex::processResourceAttributes(ResourceAttributes &attributes) { bool atEnd = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "camera-make") { attributes.cameraMake = textValue(); } if (name == "camera-model") { attributes.cameraModel = textValue(); } if (name == "file-name") { attributes.fileName = textValue(); } if (name == "reco-type") { attributes.recoType = textValue(); } if (name == "source-url") { attributes.sourceURL = textValue(); } if (name == "altitude") { attributes.altitude = doubleValue(); } if (name == "longitude") { attributes.longitude = doubleValue(); } if (name == "altitude") { attributes.latitude = doubleValue(); } if (name == "timestamp") { attributes.timestamp = longValue(); } if (name == "attachment") { attributes.attachment = booleanValue(); } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "resource-attributes" && reader->isEndElement()) atEnd = true; } }
//*********************************************************** //* Process a <savedsearch> node. //*********************************************************** void ImportData::processSavedSearchNode() { SavedSearch search; bool searchIsDirty = false; SearchTable searchTable; bool atEnd = false; // Keep going until we hit </savedsearch> while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { search.guid = textValue().toStdString(); search.__isset.guid = true; } if (name == "name") { search.name = textValue().toStdString(); search.__isset.name = true; } if (name == "updatesequencenumber") { search.updateSequenceNum = intValue(); search.__isset.updateSequenceNum = true; } if (name == "query") { search.query = textValue().toStdString(); search.__isset.query = true; } if (name == "dirty") { if (booleanValue()) searchIsDirty = true; } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "savedsearch" && reader->isEndElement()) atEnd = true; } // Add this search to the table searchTable.add(0,search, searchIsDirty); return; }
std::string FlowLexer::tokenString() const { switch (token()) { case FlowToken::Ident: return std::string("ident:") + stringValue_; case FlowToken::IP: return ipValue_.str(); case FlowToken::RegExp: return "/" + stringValue_ + "/"; case FlowToken::RawString: case FlowToken::String: return "string:'" + stringValue_ + "'"; case FlowToken::Number: { char buf[64]; snprintf(buf, sizeof(buf), "%lld", numberValue_); return buf; } case FlowToken::Boolean: return booleanValue() ? "true" : "false"; default: return tokenToString(token()); } }
//*********************************************************** //* Process a <note> tag //*********************************************************** void ImportEnex::processNoteNode() { Note note; QUuid uuid; QString newGuid = uuid.createUuid().toString().replace("{", "").replace("}", ""); note.guid = newGuid; note.active = true; QList<Resource> resources; //QList<QString> tagNames; bool atEnd = false; while(!atEnd) { QString name = reader->name().toString().toLower(); if (name == "title" && !reader->isEndElement()) { note.title = textValue(); } if (name == "created" && !reader->isEndElement()) { note.created = datetimeValue(); } if (name == "updated" && !reader->isEndElement()) { note.updated = datetimeValue(); } if (name == "deleted" && !reader->isEndElement()) { note.deleted = datetimeValue(); } if (name == "active" && !reader->isEndElement()) { note.active = booleanValue(); } if (name == "content" && !reader->isEndElement()) { note.content = textValue(); } if (name == "note-attributes" && !reader->isEndElement()) { NoteAttributes na; note.attributes = na; processNoteAttributes(note.attributes); } if (name == "resource" && !reader->isEndElement()) { Resource newRes; processResource(newRes); newRes.noteGuid = note.guid; newRes.updateSequenceNum = 0; resources.append(newRes); } if (name == "tag" && !reader->isEndElement()) { if (!note.tagNames.isSet()) note.tagNames = QStringList(); note.tagNames->append(textValue()); } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "note" && reader->isEndElement()) atEnd = true; } // Loop through the resources & make sure they all have the // proper guid for this note for (int i=0; i<resources.size(); i++) { Resource *r = &resources[i]; r->noteGuid = note.guid; } // Loop through the tag names & find any matching tags. if (note.tagNames.isSet()) { note.tagGuids = QList< Guid >(); for (int i=0; i<note.tagNames->size(); i++) { QString tagGuid = tagList[note.tagNames->at(i)]; if (tagGuid != "") { note.tagGuids->append(tagGuid); } else { QUuid uuid; QString g = uuid.createUuid().toString().replace("{","").replace("}",""); Tag newTag; newTag.name = note.tagNames->at(i); newTag.guid = g; TagTable tt(global.db); tt.add(0, newTag, true, 0); tagList.insert(note.tagNames->at(i), g); note.tagGuids->append(g); } } } note.resources = resources; // note.tagNames = tagNames; NoteTable noteTable(global.db); note.updateSequenceNum = 0; note.notebookGuid = notebookGuid; if (note.created.isSet() == false) { note.created = QDateTime::currentDateTime().toMSecsSinceEpoch(); } if (note.updated.isSet() == false) { note.updated = note.created; } if (metaData.contains(note.guid)) { QLOG_ERROR() << "ERROR IN IMPORTING DATA: Metadata not yet supported"; } noteTable.add(0,note, true); return; }
//*********************************************************** //* Process a <notebook> node //*********************************************************** void ImportData::processNotebookNode() { QLOG_DEBUG() << "Processing Notebook Node"; Notebook notebook; bool notebookIsDirty = false; bool notebookIsLocal = false; Publishing publishing; // bool notebookIsReadOnly = false; // notebookIcon = null; bool atEnd = false; // Loop through until we hit </notebook> while(!atEnd) { if (backup || importNotebooks) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { notebook.guid = textValue(); } if (name == "name") { notebook.name = textValue(); } if (name == "updatesequencenumber") { notebook.updateSequenceNum = intValue(); } if (name == "servicecreated") { notebook.serviceCreated = longValue(); } if (name == "serviceupdated") { notebook.serviceUpdated = longValue(); } if (name == "defaultnotebook") { notebook.defaultNotebook = booleanValue(); } if (name == "dirty") { if (booleanValue()) notebookIsDirty = true; } if (name == "localnotebook") { if (booleanValue()) notebookIsLocal = true; } if (name == "publishingpublicdescription") { publishing.publicDescription = textValue(); } if (name == "publishinguri") { publishing.uri = textValue(); } if (name == "publishingorder") { //notebook->publishing.order = // NoteSortOrder.; QLOG_DEBUG() << "!!!!!!!!!!!! PublishingOrder not completed in import"; } if (name == "PublishingAscending") { if (booleanValue()) publishing.ascending = true; else publishing.ascending = false; } if (name == "icon") { //byte[] b = textValue().getBytes(); // data binary //QByteArray hexData = new QByteArray(b); //QByteArray binData = new QByteArray(QByteArray.fromHex(hexData)); //notebookIcon = new QIcon(QPixmap.fromImage(QImage.fromData(binData))); } if (name == "stack") { notebook.stack = textValue(); } } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "notebook" && reader->isEndElement()) atEnd = true; } notebook.publishing = publishing; // We are at the end. We should have a valid notebook now NotebookTable notebookTable(global.db); // Check if there is a notebook by this name already. // If one exists, we treat this as an update qint32 lid = notebookTable.findByName(notebook.name); if (lid <= 0) { lid = notebookTable.getLid(notebook.guid); } if (lid <= 0) { notebookTable.add(lid,notebook,notebookIsDirty, notebookIsLocal); } else { qint32 oldLid = notebookTable.getLid(notebook.guid); if (oldLid != lid) notebookTable.merge(oldLid, lid); notebookTable.sync(lid, notebook); // notebookTable.updateGuid(lid, notebook.guid); notebookTable.setDirty(lid, notebookIsDirty); } return; }
//*********************************************************** //* Process a <noteresource> node. //*********************************************************** void ImportData::processResource(Resource &resource) { QLOG_DEBUG() << "Processing Resource Node"; bool atEnd = false; //bool isDirty = false; while(!atEnd) { if (reader->isStartElement()) { QString name = reader->name().toString().toLower(); if (name == "guid") { resource.guid = textValue(); } if (!backup) { QUuid uuid; QString g = uuid.createUuid().toString().replace("{","").replace("}",""); resource.guid = g; } if (name == "noteguid") { QString tx = textValue(); resource.noteGuid = tx; } if (name == "updatesequencenumber") { resource.updateSequenceNum = intValue(); } if (name == "active") { resource.active = booleanValue(); } if (name == "mime") { resource.mime = textValue(); } if (name == "duration") { resource.duration = shortValue(); } if (name == "height") { resource.height = shortValue(); } if (name == "width") { resource.width = shortValue(); } // if (name == "dirty") // isDirty = booleanValue(); if (name == "data") { Data data; resource.data = data; processData("Data", resource.data); } if (name == "alternatedata") { processData("AlternateData", resource.data); } if (name == "recognitiondata") { processData("RecognitionData", resource.recognition); } if (name == "noteresourceattributes") { processResourceAttributes(resource.attributes); } } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "noteresource" && reader->isEndElement()) atEnd = true; } }
//*********************************************************** //* Process a <note> tag //*********************************************************** void ImportData::processNoteNode() { QLOG_DEBUG() << "Processing Note Node"; Note note; QUuid uuid; QString newGuid = uuid.createUuid().toString().replace("{", "").replace("}", ""); note.guid = newGuid; NoteMetaData meta; bool noteIsDirty = false; bool atEnd = false; while(!atEnd) { QString name = reader->name().toString().toLower(); if (name == "guid" && !reader->isEndElement() && backup) { note.guid = textValue(); noteList.append(note.guid); } if (name == "updatesequencenumber" && !reader->isEndElement()) { note.updateSequenceNum = textValue().toLong(); } if (name == "title" && !reader->isEndElement()) { note.title = textValue(); } if (name == "created" && !reader->isEndElement()) { note.created = longLongValue(); } if (name == "updated" && !reader->isEndElement()) { note.updated = longLongValue(); } if (name == "deleted" && !reader->isEndElement()) { note.deleted = longLongValue(); } if (name == "active" && !reader->isEndElement()) { note.active = booleanValue(); } if (name == "notebookguid" && !reader->isEndElement()) { note.notebookGuid = textValue(); } if (name == "dirty" && !reader->isEndElement()) { noteIsDirty = booleanValue(); } if (name == "content" && !reader->isEndElement()) { note.content = textValue(); } if (name == "titlecolor" && !reader->isEndElement()) { meta.setColor(intValue()); } if (name == "notetags" && (createTags || backup) && !reader->isEndElement()) { QStringList names, guids; processNoteTagList(guids, names); QList<QString> tagGuids; QList<QString> tagNames; for (qint32 i=0; i<guids.size(); i++) { tagGuids.append(guids[i]); tagNames.append(names[i]); } note.tagNames = tagNames; note.tagGuids = tagGuids; } if (name == "noteattributes" && !reader->isEndElement()) { processNoteAttributes(note.attributes); } if (name == "noteresource" && !reader->isEndElement()) { Resource newRes; processResource(newRes); newRes.noteGuid = note.guid; if (!backup) newRes.updateSequenceNum = 0; QList<Resource> resources; if (note.resources.isSet()) resources = note.resources; resources.append(newRes); note.resources = resources; } reader->readNext(); QString endName = reader->name().toString().toLower(); if (endName == "note" && reader->isEndElement()) atEnd = true; } // Loop through the resources & make sure they all have the // proper guid for this note QList<Resource> resources; if (note.resources.isSet()) resources = note.resources; for (int i=0; i<resources.size(); i++) { resources[i].noteGuid = note.guid; } note.resources = resources; NoteTable noteTable(global.db); if (backup) noteTable.add(0,note, noteIsDirty); else { note.updateSequenceNum = 0; if (notebookGuid != NULL) note.notebookGuid = notebookGuid; noteTable.add(0,note, true); if (metaData.contains(note.guid)) { QLOG_ERROR() << "ERROR IN IMPORTING DATA: Metadata not yet supported"; } } return; }
void JsonPrinter::booleanProperty(Print& printer, char* name, boolean value) { property(printer, name); booleanValue(printer, value); }
TEST(JsonValuesTest, JsonValuesToStringBooleanTest){ bool value = false; json_handler::Value<bool> booleanValue(value); ASSERT_EQ("false", booleanValue.toString()); }
TEST(JsonValuesTest, JsonValuesBooleanTest){ bool value = false; json_handler::Value<bool> booleanValue(value); ASSERT_FALSE(booleanValue.getValue()); }
/* ** Run a script. */ static void runScript( int iClient, /* The client number, or 0 for the master */ int taskId, /* The task ID for clients. 0 for master */ char *zScript, /* Text of the script */ char *zFilename /* File from which script was read. */ ){ int lineno = 1; int prevLine = 1; int ii = 0; int iBegin = 0; int n, c, j; int len; int nArg; String sResult; char zCmd[30]; char zError[1000]; char azArg[MX_ARG][100]; memset(&sResult, 0, sizeof(sResult)); stringReset(&sResult); while( (c = zScript[ii])!=0 ){ prevLine = lineno; len = tokenLength(zScript+ii, &lineno); if( isspace(c) || (c=='/' && zScript[ii+1]=='*') ){ ii += len; continue; } if( c!='-' || zScript[ii+1]!='-' || !isalpha(zScript[ii+2]) ){ ii += len; continue; } /* Run any prior SQL before processing the new --command */ if( ii>iBegin ){ char *zSql = sqlite3_mprintf("%.*s", ii-iBegin, zScript+iBegin); evalSql(&sResult, zSql); sqlite3_free(zSql); iBegin = ii + len; } /* Parse the --command */ if( g.iTrace>=2 ) logMessage("%.*s", len, zScript+ii); n = extractToken(zScript+ii+2, len-2, zCmd, sizeof(zCmd)); for(nArg=0; n<len-2 && nArg<MX_ARG; nArg++){ while( n<len-2 && isspace(zScript[ii+2+n]) ){ n++; } if( n>=len-2 ) break; n += extractToken(zScript+ii+2+n, len-2-n, azArg[nArg], sizeof(azArg[nArg])); } for(j=nArg; j<MX_ARG; j++) azArg[j++][0] = 0; /* ** --sleep N ** ** Pause for N milliseconds */ if( strcmp(zCmd, "sleep")==0 ){ sqlite3_sleep(atoi(azArg[0])); }else /* ** --exit N ** ** Exit this process. If N>0 then exit without shutting down ** SQLite. (In other words, simulate a crash.) */ if( strcmp(zCmd, "exit")==0 ){ int rc = atoi(azArg[0]); finishScript(iClient, taskId, 1); if( rc==0 ) sqlite3_close(g.db); exit(rc); }else /* ** --testcase NAME ** ** Begin a new test case. Announce in the log that the test case ** has begun. */ if( strcmp(zCmd, "testcase")==0 ){ if( g.iTrace==1 ) logMessage("%.*s", len - 1, zScript+ii); stringReset(&sResult); }else /* ** --finish ** ** Mark the current task as having finished, even if it is not. ** This can be used in conjunction with --exit to simulate a crash. */ if( strcmp(zCmd, "finish")==0 && iClient>0 ){ finishScript(iClient, taskId, 1); }else /* ** --reset ** ** Reset accumulated results back to an empty string */ if( strcmp(zCmd, "reset")==0 ){ stringReset(&sResult); }else /* ** --match ANSWER... ** ** Check to see if output matches ANSWER. Report an error if not. */ if( strcmp(zCmd, "match")==0 ){ int jj; char *zAns = zScript+ii; for(jj=7; jj<len-1 && isspace(zAns[jj]); jj++){} zAns += jj; if( len-jj-1!=sResult.n || strncmp(sResult.z, zAns, len-jj-1) ){ errorMessage("line %d of %s:\nExpected [%.*s]\n Got [%s]", prevLine, zFilename, len-jj-1, zAns, sResult.z); } g.nTest++; stringReset(&sResult); }else /* ** --glob ANSWER... ** --notglob ANSWER.... ** ** Check to see if output does or does not match the glob pattern ** ANSWER. */ if( strcmp(zCmd, "glob")==0 || strcmp(zCmd, "notglob")==0 ){ int jj; char *zAns = zScript+ii; char *zCopy; int isGlob = (zCmd[0]=='g'); for(jj=9-3*isGlob; jj<len-1 && isspace(zAns[jj]); jj++){} zAns += jj; zCopy = sqlite3_mprintf("%.*s", len-jj-1, zAns); if( (sqlite3_strglob(zCopy, sResult.z)==0)^isGlob ){ errorMessage("line %d of %s:\nExpected [%s]\n Got [%s]", prevLine, zFilename, zCopy, sResult.z); } sqlite3_free(zCopy); g.nTest++; stringReset(&sResult); }else /* ** --output ** ** Output the result of the previous SQL. */ if( strcmp(zCmd, "output")==0 ){ logMessage("%s", sResult.z); }else /* ** --source FILENAME ** ** Run a subscript from a separate file. */ if( strcmp(zCmd, "source")==0 ){ char *zNewFile, *zNewScript; char *zToDel = 0; zNewFile = azArg[0]; if( zNewFile[0]!='/' ){ int k; for(k=(int)strlen(zFilename)-1; k>=0 && zFilename[k]!='/'; k--){} if( k>0 ){ zNewFile = zToDel = sqlite3_mprintf("%.*s/%s", k,zFilename,zNewFile); } } zNewScript = readFile(zNewFile); if( g.iTrace ) logMessage("begin script [%s]\n", zNewFile); runScript(0, 0, zNewScript, zNewFile); sqlite3_free(zNewScript); if( g.iTrace ) logMessage("end script [%s]\n", zNewFile); sqlite3_free(zToDel); }else /* ** --print MESSAGE.... ** ** Output the remainder of the line to the log file */ if( strcmp(zCmd, "print")==0 ){ int jj; for(jj=7; jj<len && isspace(zScript[ii+jj]); jj++){} logMessage("%.*s", len-jj, zScript+ii+jj); }else /* ** --if EXPR ** ** Skip forward to the next matching --endif or --else if EXPR is false. */ if( strcmp(zCmd, "if")==0 ){ int jj, rc; sqlite3_stmt *pStmt; for(jj=4; jj<len && isspace(zScript[ii+jj]); jj++){} pStmt = prepareSql("SELECT %.*s", len-jj, zScript+ii+jj); rc = sqlite3_step(pStmt); if( rc!=SQLITE_ROW || sqlite3_column_int(pStmt, 0)==0 ){ ii += findEndif(zScript+ii+len, 1, &lineno); } sqlite3_finalize(pStmt); }else /* ** --else ** ** This command can only be encountered if currently inside an --if that ** is true. Skip forward to the next matching --endif. */ if( strcmp(zCmd, "else")==0 ){ ii += findEndif(zScript+ii+len, 0, &lineno); }else /* ** --endif ** ** This command can only be encountered if currently inside an --if that ** is true or an --else of a false if. This is a no-op. */ if( strcmp(zCmd, "endif")==0 ){ /* no-op */ }else /* ** --start CLIENT ** ** Start up the given client. */ if( strcmp(zCmd, "start")==0 && iClient==0 ){ int iNewClient = atoi(azArg[0]); if( iNewClient>0 ){ startClient(iNewClient); } }else /* ** --wait CLIENT TIMEOUT ** ** Wait until all tasks complete for the given client. If CLIENT is ** "all" then wait for all clients to complete. Wait no longer than ** TIMEOUT milliseconds (default 10,000) */ if( strcmp(zCmd, "wait")==0 && iClient==0 ){ int iTimeout = nArg>=2 ? atoi(azArg[1]) : 10000; sqlite3_snprintf(sizeof(zError),zError,"line %d of %s\n", prevLine, zFilename); waitForClient(atoi(azArg[0]), iTimeout, zError); }else /* ** --task CLIENT ** <task-content-here> ** --end ** ** Assign work to a client. Start the client if it is not running ** already. */ if( strcmp(zCmd, "task")==0 && iClient==0 ){ int iTarget = atoi(azArg[0]); int iEnd; char *zTask; char *zTName; iEnd = findEnd(zScript+ii+len, &lineno); if( iTarget<0 ){ errorMessage("line %d of %s: bad client number: %d", prevLine, zFilename, iTarget); }else{ zTask = sqlite3_mprintf("%.*s", iEnd, zScript+ii+len); if( nArg>1 ){ zTName = sqlite3_mprintf("%s", azArg[1]); }else{ zTName = sqlite3_mprintf("%s:%d", filenameTail(zFilename), prevLine); } startClient(iTarget); runSql("INSERT INTO task(client,script,name)" " VALUES(%d,'%q',%Q)", iTarget, zTask, zTName); sqlite3_free(zTask); sqlite3_free(zTName); } iEnd += tokenLength(zScript+ii+len+iEnd, &lineno); len += iEnd; iBegin = ii+len; }else /* ** --breakpoint ** ** This command calls "test_breakpoint()" which is a routine provided ** as a convenient place to set a debugger breakpoint. */ if( strcmp(zCmd, "breakpoint")==0 ){ test_breakpoint(); }else /* ** --show-sql-errors BOOLEAN ** ** Turn display of SQL errors on and off. */ if( strcmp(zCmd, "show-sql-errors")==0 ){ g.bIgnoreSqlErrors = nArg>=1 ? !booleanValue(azArg[0]) : 1; }else /* error */{ errorMessage("line %d of %s: unknown command --%s", prevLine, zFilename, zCmd); } ii += len; } if( iBegin<ii ){ char *zSql = sqlite3_mprintf("%.*s", ii-iBegin, zScript+iBegin); runSql(zSql); sqlite3_free(zSql); } stringFree(&sResult); }
// primaryExpr ::= NUMBER // | STRING // | variable // | function '(' exprList ')' // | '(' expr ')' std::unique_ptr<Expr> FlowParser::primaryExpr() { FNTRACE(); static struct { const char* ident; long long nominator; long long denominator; } units[] = { { "byte", 1, 1 }, { "kbyte", 1024llu, 1 }, { "mbyte", 1024llu * 1024, 1 }, { "gbyte", 1024llu * 1024 * 1024, 1 }, { "tbyte", 1024llu * 1024 * 1024 * 1024, 1 }, { "bit", 1, 8 }, { "kbit", 1024llu, 8 }, { "mbit", 1024llu * 1024, 8 }, { "gbit", 1024llu * 1024 * 1024, 8 }, { "tbit", 1024llu * 1024 * 1024 * 1024, 8 }, { "sec", 1, 1 }, { "min", 60llu, 1 }, { "hour", 60llu * 60, 1 }, { "day", 60llu * 60 * 24, 1 }, { "week", 60llu * 60 * 24 * 7, 1 }, { "month", 60llu * 60 * 24 * 30, 1 }, { "year", 60llu * 60 * 24 * 365, 1 }, { nullptr, 1, 1 } }; FlowLocation loc(location()); switch (token()) { case FlowToken::Ident: { std::string name = stringValue(); nextToken(); Symbol* symbol = scope()->lookup(name, Lookup::All); if (!symbol) { // XXX assume that given symbol is a auto forward-declared handler. Handler* href = (Handler*) globalScope()->appendSymbol(std::make_unique<Handler>(name, loc)); return std::make_unique<HandlerRefExpr>(href, loc); } if (auto variable = dynamic_cast<Variable*>(symbol)) return std::make_unique<VariableExpr>(variable, loc); if (auto handler = dynamic_cast<Handler*>(symbol)) return std::make_unique<HandlerRefExpr>(handler, loc); if (symbol->type() == Symbol::BuiltinFunction) { if (token() != FlowToken::RndOpen) return std::make_unique<FunctionCallExpr>((BuiltinFunction*) symbol, ExprList()/*args*/, loc); nextToken(); ExprList args; bool rv = listExpr(args); consume(FlowToken::RndClose); if (!rv) return nullptr; return std::make_unique<FunctionCallExpr>((BuiltinFunction*) symbol, std::move(args), loc); } reportError("Unsupported symbol type of '%s' in expression.", name.c_str()); return nullptr; } case FlowToken::Boolean: { std::unique_ptr<BoolExpr> e = std::make_unique<BoolExpr>(booleanValue(), loc); nextToken(); return std::move(e); } case FlowToken::RegExp: { std::unique_ptr<RegExpExpr> e = std::make_unique<RegExpExpr>(RegExp(stringValue()), loc); nextToken(); return std::move(e); } case FlowToken::InterpolatedStringFragment: return interpolatedStr(); case FlowToken::String: case FlowToken::RawString: { std::unique_ptr<StringExpr> e = std::make_unique<StringExpr>(stringValue(), loc); nextToken(); return std::move(e); } case FlowToken::Number: { // NUMBER [UNIT] auto number = numberValue(); nextToken(); if (token() == FlowToken::Ident) { std::string sv(stringValue()); for (size_t i = 0; units[i].ident; ++i) { if (sv == units[i].ident || (sv[sv.size() - 1] == 's' && sv.substr(0, sv.size() - 1) == units[i].ident)) { nextToken(); // UNIT number = number * units[i].nominator / units[i].denominator; loc.update(end()); break; } } } return std::make_unique<NumberExpr>(number, loc); } case FlowToken::IP: { std::unique_ptr<IPAddressExpr> e = std::make_unique<IPAddressExpr>(lexer_->ipValue(), loc); nextToken(); return std::move(e); } case FlowToken::Cidr: { std::unique_ptr<CidrExpr> e = std::make_unique<CidrExpr>(lexer_->cidr(), loc); nextToken(); return std::move(e); } case FlowToken::StringType: case FlowToken::NumberType: case FlowToken::BoolType: return castExpr(); case FlowToken::Begin: { // lambda-like inline function ref char name[64]; static unsigned long i = 0; ++i; snprintf(name, sizeof(name), "__lambda_%lu", i); FlowLocation loc = location(); auto st = std::make_unique<SymbolTable>(scope(), name); enter(st.get()); std::unique_ptr<Stmt> body = compoundStmt(); leave(); if (!body) return nullptr; loc.update(body->location().end); Handler* handler = new Handler(name, std::move(st), std::move(body), loc); // TODO (memory leak): add handler to unit's global scope, i.e. via: // - scope()->rootScope()->insert(handler); // - unit_->scope()->insert(handler); // to get free'd return std::make_unique<HandlerRefExpr>(handler, loc); } case FlowToken::RndOpen: { nextToken(); std::unique_ptr<Expr> e = expr(); consume(FlowToken::RndClose); e->setLocation(loc.update(end())); return e; } default: TRACE(1, "Expected primary expression. Got something... else."); reportUnexpectedToken(); return nullptr; } }