/** * \en * clears all tags from pattern * \_en * \ru * Удаляет все теги из документа, а также строки, в которых содержится тег секции * \_ru */ void aMSOTemplate::cleanUpTags() { QDomNode n = docTpl.lastChild(); while( !n.isNull() ) { clearTags(n,false); //clearRow(n); n = n.previousSibling(); } n = docTpl.lastChild(); while( !n.isNull() ) { //clearTags(n,false); clearRow(n); n = n.previousSibling(); } n = docTpl.lastChild(); while (!n.isNull()) { clearAttributes(n, "Table", "ss:ExpandedRowCount"); n = n.previousSibling(); } }
bool ComponentNode::resetComponent( const std::string& componentId ) { bool wasEnabled = isEnabled(); if ( wasEnabled ) { disable(); } // remove old component clearAttributes(); delete _component; _component = 0; _componentId = componentId; // set new component if ( !_componentId.empty() ) { _component = getFactory().createComponent( _componentId ); if ( !_component || !_component->init( *this ) ) { if ( _component ) { COCA_ERROR( "Could not initialize component with id '" << _componentId << "'" ); delete _component; _component = 0; } _componentId = ""; } } if ( wasEnabled ) { enable(); } getEventManager().sendEvent( E_NODE_COMPONENT_CHANGED_EVENT, *this ); return ( _componentId == componentId ); }
/** * Parse the body of the requesting message and create key/value * pairs for each attribute * * @param body The body of the requesting message containing the attributes * * @return None */ void initializeAttributes(char* body) { char *key, *value; Attribute *new_attr; size_t size; clearAttributes(); key = strtok(body, "="); do { value = strtok(0, ";"); if(!(new_attr = malloc(sizeof(Attribute)))) _terminate(1); bzero((char *)new_attr, sizeof(Attribute)); size = strlen(key); if(!(new_attr->key = malloc(size+1))) _terminate(1); bzero(new_attr->key, size+1); memcpy(new_attr->key, key, size); size = strlen(value); if(!(new_attr->value = malloc(size+1))) _terminate(1); bzero(new_attr->value, size+1); memcpy(new_attr->value, value, size); new_attr->next = attributes; attributes = new_attr; } while((key = strtok(0, "="))); }
virtual bool incrementToken() { if (i == TOKENS.size()) return false; clearAttributes(); termAtt->setTermBuffer(TOKENS[i]); offsetAtt->setOffset(i, i); posIncrAtt->setPositionIncrement(INCREMENTS[i]); ++i; return true; }
void CompositeNode::clearChildren() { // clear added attributes from children clearAttributes(); // clear children NodeVector::iterator it; for ( it = _children.begin(); it != _children.end(); ) { NodePtr child( *it ); // scoped reference count child->setParent( 0 ); it = _children.erase( it ); getEventManager().sendEvent( E_NODE_CHILD_REMOVED_EVENT, *this, *child ); } }
uint8 BodyPart::changeHealth(int16 delta) { mHealth = max(0, mHealth + delta); if(mHealth <= 0) { if(hasAttribute(BodyPartAttribute::Necessary)) { getBody()->die(); return 2; } else { clearAttributes(); setAttribute(BodyPartAttribute::Dead); return 1; } } return 0; }
bool CharTokenizer::incrementToken() { clearAttributes(); int32_t length = 0; int32_t start = bufferIndex; CharArray buffer(termAtt->termBuffer()); while (true) { if (bufferIndex >= dataLen) { offset += dataLen; dataLen = input->read(ioBuffer.get(), 0, ioBuffer.size()); if (dataLen == -1) { dataLen = 0; // so next offset += dataLen won't decrement offset if (length > 0) break; else return false; } bufferIndex = 0; } wchar_t c = ioBuffer[bufferIndex++]; if (isTokenChar(c)) // if it's a token char { if (length == 0) start = offset + bufferIndex - 1; else if (length == buffer.size()) buffer = termAtt->resizeTermBuffer(1 + length); buffer[length++] = normalize(c); // buffer it, normalized if (length == MAX_WORD_LEN) // buffer overflow! break; } else if (length > 0) // at non-Letter with chars break; // return them } termAtt->setTermLength(length); offsetAtt->setOffset(correctOffset(start), correctOffset(start + length)); return true; }
/** * \en * Deletes from node attribute * \_en * \ru * Рекурсивная функция. Удаляет из узла атрибут * \_ru * \param node - \en context \_en \ru узел из которого нужно удалить атрибут \_ru * \param nodename - \en node name \_en \ru имя узла \_ru * \param attr - \en attribut name \_en \ru имя атрибута,который нужно удалить \_ru */ void aMSOTemplate::clearAttributes(QDomNode node, const QString nodename, const QString attr) { QDomNode n = node.lastChild(); while( !n.isNull() ) { if( n.parentNode().nodeName()==nodename ) { n.parentNode().toElement().removeAttribute(attr); break; } else { clearAttributes(n, nodename, attr); } n = n.previousSibling(); } }
void ElementAttributeData::cloneDataFrom(const ElementAttributeData& sourceData, const Element& sourceElement, Element& targetElement) { // FIXME: Cloned elements could start out with immutable attribute data. ASSERT(isMutable()); const AtomicString& oldID = targetElement.getIdAttribute(); const AtomicString& newID = sourceElement.getIdAttribute(); if (!oldID.isNull() || !newID.isNull()) targetElement.updateId(oldID, newID); const AtomicString& oldName = targetElement.getNameAttribute(); const AtomicString& newName = sourceElement.getNameAttribute(); if (!oldName.isNull() || !newName.isNull()) targetElement.updateName(oldName, newName); clearAttributes(); if (sourceData.isMutable()) mutableAttributeVector() = sourceData.mutableAttributeVector(); else { mutableAttributeVector().reserveInitialCapacity(sourceData.m_arraySize); for (unsigned i = 0; i < sourceData.m_arraySize; ++i) mutableAttributeVector().uncheckedAppend(sourceData.immutableAttributeArray()[i]); } for (unsigned i = 0; i < length(); ++i) { const Attribute& attribute = mutableAttributeVector().at(i); if (targetElement.isStyledElement() && attribute.name() == HTMLNames::styleAttr) { static_cast<StyledElement&>(targetElement).styleAttributeChanged(attribute.value(), StyledElement::DoNotReparseStyleAttribute); continue; } targetElement.attributeChanged(attribute.name(), attribute.value()); } if (targetElement.isStyledElement() && sourceData.m_inlineStyleDecl) { m_inlineStyleDecl = sourceData.m_inlineStyleDecl->immutableCopyIfNeeded(); targetElement.setIsStyleAttributeValid(sourceElement.isStyleAttributeValid()); } }
void ElementAttributeData::setAttributes(const ElementAttributeData& other, Element* element) { ASSERT(element); // If assigning the map changes the id attribute, we need to call // updateId. Attribute* oldId = getAttributeItem(element->document()->idAttributeName()); Attribute* newId = other.getAttributeItem(element->document()->idAttributeName()); if (oldId || newId) element->updateId(oldId ? oldId->value() : nullAtom, newId ? newId->value() : nullAtom); Attribute* oldName = getAttributeItem(HTMLNames::nameAttr); Attribute* newName = other.getAttributeItem(HTMLNames::nameAttr); if (oldName || newName) element->updateName(oldName ? oldName->value() : nullAtom, newName ? newName->value() : nullAtom); clearAttributes(element); m_attributes = other.m_attributes; for (unsigned i = 0; i < m_attributes.size(); ++i) element->attributeChanged(&m_attributes[i]); }
bool StandardTokenizer::incrementToken() { clearAttributes(); int32_t posIncr = 1; while (true) { int32_t tokenType = scanner->getNextToken(); if (tokenType == StandardTokenizerImpl::YYEOF) { return false; } if (scanner->yylength() <= maxTokenLength) { posIncrAtt->setPositionIncrement(posIncr); scanner->getText(termAtt); int32_t start = scanner->yychar(); offsetAtt->setOffset(correctOffset(start), correctOffset(start + termAtt->termLength())); // This 'if' should be removed in the next release. For now, it converts invalid acronyms to HOST. /// When removed, only the 'else' part should remain. if (tokenType == ACRONYM_DEP) { if (replaceInvalidAcronym) { typeAtt->setType(TOKEN_TYPES()[HOST]); termAtt->setTermLength(termAtt->termLength() - 1); // remove extra '.' } else { typeAtt->setType(TOKEN_TYPES()[ACRONYM]); } } else { typeAtt->setType(TOKEN_TYPES()[tokenType]); } return true; } else { // When we skip a too-long term, we still increment the position increment ++posIncr; } } }
QString BaseObject::getCodeDefinition(unsigned def_type, bool reduced_form) { QString code_def; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_RELATIONSHIP && obj_type!=BASE_TABLE && obj_type!=OBJ_TEXTBOX) || (def_type==SchemaParser::XML_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_TABLE)) { bool format=false; schparser.setPgSQLVersion(BaseObject::pgsql_ver); attributes[ParsersAttributes::SQL_DISABLED]=(sql_disabled ? ParsersAttributes::_TRUE_ : QString()); //Formats the object's name in case the SQL definition is being generated format=((def_type==SchemaParser::SQL_DEFINITION) || (def_type==SchemaParser::XML_DEFINITION && reduced_form && obj_type!=OBJ_TEXTBOX && obj_type!=OBJ_RELATIONSHIP)); setBasicAttributes(format); if(schema) { if(def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::SCHEMA]=schema->getCodeDefinition(def_type, true); else attributes[ParsersAttributes::SCHEMA]=schema->getName(format); } if(def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::PROTECTED]=(is_protected ? ParsersAttributes::_TRUE_ : QString()); if(tablespace) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::TABLESPACE]=tablespace->getName(format); else attributes[ParsersAttributes::TABLESPACE]=tablespace->getCodeDefinition(def_type, true); } if(collation && attributes[ParsersAttributes::COLLATION].isEmpty()) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::COLLATION]=collation->getName(format); else attributes[ParsersAttributes::COLLATION]=collation->getCodeDefinition(def_type, true); } if(owner) { if(def_type==SchemaParser::SQL_DEFINITION) { attributes[ParsersAttributes::OWNER]=owner->getName(format); /** Only tablespaces and database do not have an ALTER OWNER SET because the rule says that PostgreSQL tablespaces and database should be created with just a command line isolated from the others **/ if(obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) { SchemaParser sch_parser; QString filename=GlobalAttributes::SCHEMAS_ROOT_DIR + GlobalAttributes::DIR_SEPARATOR + GlobalAttributes::ALTER_SCHEMA_DIR + GlobalAttributes::DIR_SEPARATOR + ParsersAttributes::OWNER + GlobalAttributes::SCHEMA_EXT; sch_parser.ignoreUnkownAttributes(true); attributes[ParsersAttributes::OWNER]=sch_parser.getCodeDefinition(filename, attributes); } } else attributes[ParsersAttributes::OWNER]=owner->getCodeDefinition(def_type, true); } if(!comment.isEmpty()) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::COMMENT]=QString(comment).replace(QString("'"), QString("''")); else attributes[ParsersAttributes::COMMENT]=comment; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) || def_type==SchemaParser::XML_DEFINITION) { schparser.ignoreUnkownAttributes(true); attributes[ParsersAttributes::COMMENT]= schparser.getCodeDefinition(ParsersAttributes::COMMENT, attributes, def_type); } } if(!appended_sql.isEmpty()) { attributes[ParsersAttributes::APPENDED_SQL]=appended_sql; if(def_type==SchemaParser::XML_DEFINITION) { schparser.ignoreUnkownAttributes(true); attributes[ParsersAttributes::APPENDED_SQL]= schparser.getCodeDefinition(QString(ParsersAttributes::APPENDED_SQL).remove('-'), attributes, def_type); } else { attributes[ParsersAttributes::APPENDED_SQL]=QString("\n-- Appended SQL commands --\n") + appended_sql; } } if(!prepended_sql.isEmpty()) { attributes[ParsersAttributes::PREPENDED_SQL]=prepended_sql; if(def_type==SchemaParser::XML_DEFINITION) { schparser.ignoreUnkownAttributes(true); attributes[ParsersAttributes::PREPENDED_SQL]= schparser.getCodeDefinition(QString(ParsersAttributes::PREPENDED_SQL).remove('-'), attributes, def_type); } else { attributes[ParsersAttributes::PREPENDED_SQL]=QString("\n-- Prepended SQL commands --\n") + prepended_sql; } } if(def_type==SchemaParser::SQL_DEFINITION && this->acceptsDropCommand()) { attributes[ParsersAttributes::DROP]=getDropDefinition(true); attributes[ParsersAttributes::DROP].remove(ParsersAttributes::DDL_END_TOKEN + '\n'); } attributes[ParsersAttributes::REDUCED_FORM]=(reduced_form ? ParsersAttributes::_TRUE_ : QString()); try { code_def+=schparser.getCodeDefinition(objs_schemas[obj_type], attributes, def_type); //Internally disabling the SQL definition if(sql_disabled && def_type==SchemaParser::SQL_DEFINITION) { //Creates a text stream and insert an comment start token on each line QTextStream ts(&code_def); QString buf; while(!ts.atEnd()) buf+=QString("-- %1\n").arg(ts.readLine()); //The entire commented buffer will be returned code_def=buf; } clearAttributes(); //Database object doesn't handles cached code. if(use_cached_code && obj_type!=OBJ_DATABASE) { if(def_type==SchemaParser::SQL_DEFINITION || (!reduced_form && def_type==SchemaParser::XML_DEFINITION)) cached_code[def_type]=code_def; else if(reduced_form) cached_reduced_code=code_def; } code_invalidated=false; } catch(Exception &e) { schparser.restartParser(); clearAttributes(); if(e.getErrorType()==ERR_UNDEF_ATTRIB_VALUE) throw Exception(Exception::getErrorMessage(ERR_ASG_OBJ_INV_DEFINITION) .arg(this->getName(true)) .arg(this->getTypeName()), ERR_ASG_OBJ_INV_DEFINITION,__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); else throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } } return(code_def); }
QString BaseObject::getCodeDefinition(unsigned def_type, bool reduced_form) { QString code_def; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_RELATIONSHIP && obj_type!=BASE_TABLE && obj_type!=OBJ_TEXTBOX) || (def_type==SchemaParser::XML_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_TABLE)) { bool format; attributes[ParsersAttributes::SQL_DISABLED]=(sql_disabled ? "1" : ""); //Formats the object's name in case the SQL definition is being generated format=((def_type==SchemaParser::SQL_DEFINITION) || (def_type==SchemaParser::XML_DEFINITION && reduced_form && obj_type!=OBJ_TEXTBOX && obj_type!=OBJ_RELATIONSHIP)); /* Marking the flag that indicates that the comment form to be generated for the object is specific to it, ignoring the default rule. (See SQL schema file for comments) */ switch(obj_type) { case OBJ_COLUMN: case OBJ_AGGREGATE: case OBJ_FUNCTION: case OBJ_CAST: case OBJ_CONSTRAINT: case OBJ_RULE: case OBJ_TRIGGER: case OBJ_OPERATOR: case OBJ_OPCLASS: case OBJ_OPFAMILY: attributes[ParsersAttributes::DIF_SQL]="1"; attributes[objs_schemas[obj_type]]="1"; break; default: attributes[ParsersAttributes::DIF_SQL]=""; break; } if(attributes[ParsersAttributes::NAME].isEmpty()) attributes[ParsersAttributes::NAME]=this->getName(format); attributes[ParsersAttributes::SQL_OBJECT]=objs_sql[this->obj_type]; if(schema) { if(def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::SCHEMA]=schema->getCodeDefinition(def_type, true); else attributes[ParsersAttributes::SCHEMA]=schema->getName(format); } if(def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::PROTECTED]=(is_protected ? "1" : ""); if(tablespace) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::TABLESPACE]=tablespace->getName(format); else attributes[ParsersAttributes::TABLESPACE]=tablespace->getCodeDefinition(def_type, true); } if(collation && attributes[ParsersAttributes::COLLATION].isEmpty()) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::COLLATION]=collation->getName(format); else attributes[ParsersAttributes::COLLATION]=collation->getCodeDefinition(def_type, true); } if(owner) { if(def_type==SchemaParser::SQL_DEFINITION) { attributes[ParsersAttributes::OWNER]=owner->getName(format); /** Only tablespaces and database do not have an ALTER OWNER SET because the rule says that PostgreSQL tablespaces and database should be created with just a command line isolated from the others **/ if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) || def_type==SchemaParser::XML_DEFINITION) { SchemaParser::setIgnoreUnkownAttributes(true); attributes[ParsersAttributes::OWNER]= SchemaParser::getCodeDefinition(ParsersAttributes::OWNER, attributes, def_type); } } else attributes[ParsersAttributes::OWNER]=owner->getCodeDefinition(def_type, true); } if(comment!="") { attributes[ParsersAttributes::COMMENT]=comment; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) || def_type==SchemaParser::XML_DEFINITION) { SchemaParser::setIgnoreUnkownAttributes(true); attributes[ParsersAttributes::COMMENT]= SchemaParser::getCodeDefinition(ParsersAttributes::COMMENT, attributes, def_type); } } if(!appended_sql.isEmpty()) { attributes[ParsersAttributes::APPENDED_SQL]=appended_sql; if(def_type==SchemaParser::XML_DEFINITION) { SchemaParser::setIgnoreUnkownAttributes(true); attributes[ParsersAttributes::APPENDED_SQL]= SchemaParser::getCodeDefinition(QString(ParsersAttributes::APPENDED_SQL).remove("-"), attributes, def_type); } else { attributes[ParsersAttributes::APPENDED_SQL]="-- Appended SQL commands --\n" + appended_sql + "\n"; } } if(reduced_form) attributes[ParsersAttributes::REDUCED_FORM]="1"; else attributes[ParsersAttributes::REDUCED_FORM]=""; try { code_def+=SchemaParser::getCodeDefinition(objs_schemas[obj_type], attributes, def_type); //Internally disabling the SQL definition if(sql_disabled && def_type==SchemaParser::SQL_DEFINITION) { //Creates a text stream and insert an comment start token on each line QTextStream ts(&code_def); QString buf; while(!ts.atEnd()) buf+="-- " + ts.readLine() + "\n"; //The entire commented buffer will be returned code_def=buf; } clearAttributes(); } catch(Exception &e) { SchemaParser::restartParser(); clearAttributes(); if(e.getErrorType()==ERR_UNDEF_ATTRIB_VALUE) throw Exception(Exception::getErrorMessage(ERR_ASG_OBJ_INV_DEFINITION) .arg(Utf8String::create(this->getName(true))) .arg(this->getTypeName()), ERR_ASG_OBJ_INV_DEFINITION,__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); else throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } } return(code_def); }
void ossimXmlNode::setAttributes(ossimXmlNode::AttributeListType& children) { clearAttributes(); addAttributes(children); }
PaObject::~PaObject() { clearAttributes(); }
QString BaseObject::getCodeDefinition(unsigned def_type, bool reduced_form) { QString code_def; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_RELATIONSHIP && obj_type!=BASE_TABLE && obj_type!=OBJ_TEXTBOX) || (def_type==SchemaParser::XML_DEFINITION && obj_type!=BASE_OBJECT && obj_type!=BASE_TABLE)) { bool format; attributes[ParsersAttributes::SQL_DISABLED]=(sql_disabled ? "1" : ""); //Formats the object's name in case the SQL definition is being generated format=(def_type==SchemaParser::SQL_DEFINITION || (def_type==SchemaParser::XML_DEFINITION && reduced_form && obj_type!=OBJ_TEXTBOX && obj_type!=OBJ_RELATIONSHIP && obj_type!=BASE_RELATIONSHIP)); attributes[objs_schemas[obj_type]]="1"; /* Marking the flag that indicates that the comment form to be generated for the object is specific to it, ignoring the default rule. (See SQL schema file for comments) */ switch(obj_type) { case OBJ_COLUMN: case OBJ_AGGREGATE: case OBJ_FUNCTION: case OBJ_CAST: case OBJ_CONSTRAINT: case OBJ_RULE: case OBJ_TRIGGER: case OBJ_OPERATOR: case OBJ_OPCLASS: case OBJ_OPFAMILY: attributes[ParsersAttributes::DIF_SQL]="1"; break; default: attributes[ParsersAttributes::DIF_SQL]=""; break; } attributes[ParsersAttributes::NAME]=this->getName(format); attributes[ParsersAttributes::SQL_OBJECT]=objs_sql[this->obj_type]; if(def_type==SchemaParser::XML_DEFINITION && schema) { attributes[ParsersAttributes::SCHEMA]=schema->getCodeDefinition(def_type, true); } if(def_type==SchemaParser::XML_DEFINITION) attributes[ParsersAttributes::PROTECTED]=(is_protected ? "1" : ""); if(comment!="") { attributes[ParsersAttributes::COMMENT]=comment; if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) || def_type==SchemaParser::XML_DEFINITION) { SchemaParser::setIgnoreUnkownAttributes(true); attributes[ParsersAttributes::COMMENT]= SchemaParser::getCodeDefinition(ParsersAttributes::COMMENT, attributes, def_type); } } if(tablespace) { if(def_type==SchemaParser::SQL_DEFINITION) attributes[ParsersAttributes::TABLESPACE]=tablespace->getName(format); else attributes[ParsersAttributes::TABLESPACE]=tablespace->getCodeDefinition(def_type, true); } if(owner) { if(def_type==SchemaParser::SQL_DEFINITION) { attributes[ParsersAttributes::OWNER]=owner->getName(format); /** Only tablespaces and database do not have an ALTER OWNER SET because the rule says that PostgreSQL tablespaces and database should be created with just a command line isolated from the others **/ if((def_type==SchemaParser::SQL_DEFINITION && obj_type!=OBJ_TABLESPACE && obj_type!=OBJ_DATABASE) || def_type==SchemaParser::XML_DEFINITION) { SchemaParser::setIgnoreUnkownAttributes(true); attributes[ParsersAttributes::OWNER]= SchemaParser::getCodeDefinition(ParsersAttributes::OWNER, attributes, def_type); } } else attributes[ParsersAttributes::OWNER]=owner->getCodeDefinition(def_type, true); } if(reduced_form) attributes[ParsersAttributes::REDUCED_FORM]="1"; else attributes[ParsersAttributes::REDUCED_FORM]=""; try { code_def=SchemaParser::getCodeDefinition(objs_schemas[obj_type], attributes, def_type); clearAttributes(); } catch(Exception &e) { SchemaParser::restartParser(); clearAttributes(); throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } } return(code_def); }
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e) { bool ok = true; clearAttributes(e); switch (v.type()) { case QVariant::String: e.setTagName("string"); e.setAttribute("value", v.toString().utf8()); break; case QVariant::CString: e.setTagName("string"); e.setAttribute("value", v.toCString()); break; case QVariant::Int: e.setTagName("int"); e.setAttribute("value", v.toInt()); break; case QVariant::UInt: e.setTagName("uint"); e.setAttribute("value", v.toUInt()); break; case QVariant::Double: e.setTagName("double"); e.setAttribute("value", v.toDouble()); break; case QVariant::Bool: e.setTagName("bool"); e.setAttribute("value", boolString(v.toBool())); break; case QVariant::Color: { e.setTagName("color"); QColor color = v.toColor(); e.setAttribute("red", color.red()); e.setAttribute("green", color.green()); e.setAttribute("blue", color.blue()); } break; case QVariant::Pen: { e.setTagName("pen"); QPen pen = v.toPen(); e.setAttribute("red", pen.color().red()); e.setAttribute("green", pen.color().green()); e.setAttribute("blue", pen.color().blue()); e.setAttribute("style", pen.style()); e.setAttribute("cap", pen.capStyle()); e.setAttribute("join", pen.joinStyle()); } break; case QVariant::Brush: { e.setTagName("brush"); QBrush brush = v.toBrush(); e.setAttribute("red", brush.color().red()); e.setAttribute("green", brush.color().green()); e.setAttribute("blue", brush.color().blue()); e.setAttribute("style", brush.style()); } break; case QVariant::Point: { e.setTagName("point"); QPoint point = v.toPoint(); e.setAttribute("x", point.x()); e.setAttribute("y", point.y()); } break; case QVariant::Rect: { e.setTagName("rect"); QRect rect = v.toRect(); e.setAttribute("x", rect.x()); e.setAttribute("y", rect.y()); e.setAttribute("width", rect.width()); e.setAttribute("height", rect.height()); } break; case QVariant::Size: { e.setTagName("size"); QSize qsize = v.toSize(); e.setAttribute("width", qsize.width()); e.setAttribute("height", qsize.height()); } break; case QVariant::Font: { e.setTagName("font"); QFont f(v.toFont()); e.setAttribute("family", f.family()); e.setAttribute("pointsize", f.pointSize()); e.setAttribute("bold", boolString(f.bold())); e.setAttribute("italic", boolString(f.italic())); e.setAttribute("underline", boolString(f.underline())); e.setAttribute("strikeout", boolString(f.strikeOut())); } break; case QVariant::SizePolicy: { e.setTagName("sizepolicy"); QSizePolicy sp(v.toSizePolicy()); e.setAttribute("hsizetype", sp.horData()); e.setAttribute("vsizetype", sp.verData()); #if (QT_VERSION >= 300) e.setAttribute("horstretch", sp.horStretch()); e.setAttribute("verstretch", sp.verStretch()); #endif } break; case QVariant::Cursor: e.setTagName("cursor"); e.setAttribute("shape", v.toCursor().shape()); break; case QVariant::StringList: { e.setTagName("stringlist"); uint j; QDomNode n; QDomNodeList stringNodeList = e.elementsByTagName("string"); QDomElement stringElem; QStringList stringList = v.toStringList(); QStringList::Iterator it = stringList.begin(); for (j = 0; ((j < stringNodeList.length()) && (it != stringList.end())); j++) { // get the current string element stringElem = stringNodeList.item(j).toElement(); // set it to the current string variantToElement(QVariant(*it), stringElem); // iterate to the next string ++it; } // more nodes in previous stringlist then current, remove excess nodes if (stringNodeList.count() > stringList.count()) { while (j < stringNodeList.count()) e.removeChild(stringNodeList.item(j).toElement()); } else if (j <stringList.count()) { while (it != stringList.end()) { // create a new element stringElem = m_doc.createElement("string"); // set it to the currentstring variantToElement(QVariant(*it), stringElem); // append it to the current element e.appendChild(stringElem); // iterate to the next string ++it; } } } break; #if QT_VERSION >= 300 case QVariant::KeySequence: e.setTagName("key"); e.setAttribute("sequence", (QString)v.toKeySequence()); break; #endif case QVariant::ByteArray: // this is only for [u]int64_t { e.setTagName("uint64"); QByteArray ba = v.toByteArray(); // make sure this only handles [u]int64_t's if (ba.size() != sizeof(uint64_t)) { qWarning("Don't know how to persist variant of type: %s (%d) (size=%d)!", v.typeName(), v.type(), ba.size()); ok = false; break; } // convert the data back into a uint64_t uint64_t num = *(uint64_t*)ba.data(); QChar buff[33]; QChar* p = &buff[32]; const char* digitSet = "0123456789abcdef"; int len = 0; // construct the string do { *--p = digitSet[((int)(num%16))]; num = num >> 4; // divide by 16 len++; } while ( num ); // store it in a QString QString storage; storage.setUnicode(p, len); // set the value e.setAttribute("value", storage); } break; #if 0 case QVariant::List: case QVaraint::Map: #endif default: qWarning("Don't know how to persist variant of type: %s (%d)!", v.typeName(), v.type()); ok = false; break; } return ok; }
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e) { bool ok = true; clearAttributes(e); switch (v.type()) { case QVariant::String: e.setTagName("string"); e.setAttribute("value", v.toString()); break; #if 0 case QVariant::CString: e.setTagName("string"); e.setAttribute("value", v.toString()); break; #endif case QVariant::Int: e.setTagName("int"); e.setAttribute("value", v.toInt()); break; case QVariant::UInt: e.setTagName("uint"); e.setAttribute("value", v.toUInt()); break; case QVariant::Double: e.setTagName("double"); e.setAttribute("value", v.toDouble()); break; case QVariant::Bool: e.setTagName("bool"); e.setAttribute("value", boolString(v.toBool())); break; case QVariant::Color: { e.setTagName("color"); QColor color = v.value<QColor>(); e.setAttribute("red", color.red()); e.setAttribute("green", color.green()); e.setAttribute("blue", color.blue()); } break; case QVariant::Pen: { e.setTagName("pen"); QPen pen = v.value<QPen>(); e.setAttribute("red", pen.color().red()); e.setAttribute("green", pen.color().green()); e.setAttribute("blue", pen.color().blue()); e.setAttribute("style", pen.style()); e.setAttribute("cap", pen.capStyle()); e.setAttribute("join", pen.joinStyle()); } break; case QVariant::Brush: { e.setTagName("brush"); QBrush brush = v.value<QBrush>(); e.setAttribute("red", brush.color().red()); e.setAttribute("green", brush.color().green()); e.setAttribute("blue", brush.color().blue()); e.setAttribute("style", brush.style()); } break; case QVariant::Point: { e.setTagName("point"); QPoint point = v.toPoint(); e.setAttribute("x", point.x()); e.setAttribute("y", point.y()); } break; case QVariant::Rect: { e.setTagName("rect"); QRect rect = v.toRect(); e.setAttribute("x", rect.x()); e.setAttribute("y", rect.y()); e.setAttribute("width", rect.width()); e.setAttribute("height", rect.height()); } break; case QVariant::Size: { e.setTagName("size"); QSize qsize = v.toSize(); e.setAttribute("width", qsize.width()); e.setAttribute("height", qsize.height()); } break; case QVariant::Font: { e.setTagName("font"); QFont f(v.value<QFont>()); e.setAttribute("family", f.family()); e.setAttribute("pointsize", f.pointSize()); e.setAttribute("bold", boolString(f.bold())); e.setAttribute("italic", boolString(f.italic())); e.setAttribute("underline", boolString(f.underline())); e.setAttribute("strikeout", boolString(f.strikeOut())); } break; case QVariant::SizePolicy: { e.setTagName("sizepolicy"); QSizePolicy sp(v.value<QSizePolicy>()); e.setAttribute("hsizetype", sp.horData()); e.setAttribute("vsizetype", sp.verData()); e.setAttribute("horstretch", sp.horStretch()); e.setAttribute("verstretch", sp.verStretch()); } break; case QVariant::Cursor: e.setTagName("cursor"); e.setAttribute("shape", v.value<QCursor>().shape()); break; case QVariant::StringList: { e.setTagName("stringlist"); int32_t j; QDomNode n; QDomNodeList stringNodeList = e.elementsByTagName("string"); QDomElement stringElem; QStringList stringList = v.toStringList(); QStringList::Iterator it = stringList.begin(); for (j = 0; ((j < (int32_t)stringNodeList.length()) && (it != stringList.end())); j++) { // get the current string element stringElem = stringNodeList.item(j).toElement(); // set it to the current string variantToElement(QVariant(*it), stringElem); // iterate to the next string ++it; } // more nodes in previous stringlist then current, remove excess nodes if (stringNodeList.count() > stringList.count()) { while (j < (int32_t)stringNodeList.count()) e.removeChild(stringNodeList.item(j).toElement()); } else if (j < (int32_t)stringList.count()) { while (it != stringList.end()) { // create a new element stringElem = m_doc.createElement("string"); // set it to the currentstring variantToElement(QVariant(*it), stringElem); // append it to the current element e.appendChild(stringElem); // iterate to the next string ++it; } } } break; case QVariant::KeySequence: e.setTagName("key"); e.setAttribute("sequence", (QString)v.value<QKeySequence>().toString()); break; case QVariant::ByteArray: // this is only for [u]int64_t { e.setTagName("data"); // set the value e.setAttribute("value", getStringFromByteArray(v.toByteArray())); } break; default: qWarning("Don't know how to persist variant of type: %s (%d)!", v.typeName(), v.type()); ok = false; break; } return ok; }
bool CJKTokenizer::incrementToken() { clearAttributes(); while (true) // loop until we find a non-empty token { int32_t length = 0; // the position used to create Token int32_t start = offset; while (true) // loop until we've found a full token { wchar_t c = 0; UnicodeBlock ub = NONE; ++offset; if (bufferIndex >= dataLen) { dataLen = input->read(ioBuffer.get(), 0, ioBuffer.size()); bufferIndex = 0; } if (dataLen == -1) { if (length > 0) { if (preIsTokened == true) { length = 0; preIsTokened = false; } else --offset; break; } else { --offset; return false; } } else { // get current character c = ioBuffer[bufferIndex++]; // get the UnicodeBlock of the current character ub = unicodeBlock(c); } // if the current character is ASCII or Extend ASCII if (ub == BASIC_LATIN || ub == HALFWIDTH_AND_FULLWIDTH_FORMS) { if (ub == HALFWIDTH_AND_FULLWIDTH_FORMS) { int32_t i = (int32_t)c; if (i >= 65281 && i <= 65374) { // convert certain HALFWIDTH_AND_FULLWIDTH_FORMS to BASIC_LATIN i = i - 65248; c = (wchar_t)i; } } // if the current character is a letter or "_" "+" "#" if (UnicodeUtil::isAlnum(c) || c == L'_' || c == L'+' || c == L'#') { if (length == 0) { // "javaC1C2C3C4linux" <br> // ^--: the current character begin to token the ASCII // letter start = offset - 1; } else if (tokenType == DOUBLE_TOKEN_TYPE) { // "javaC1C2C3C4linux" <br> // ^--: the previous non-ASCII // : the current character --offset; --bufferIndex; if (preIsTokened) { // there is only one non-ASCII has been stored length = 0; preIsTokened = false; break; } else break; } // store the LowerCase(c) in the buffer buffer[length++] = CharFolder::toLower(c); tokenType = SINGLE_TOKEN_TYPE; // break the procedure if buffer overflowed! if (length == MAX_WORD_LEN) break; } else if (length > 0) { if (preIsTokened) { length = 0; preIsTokened = false; } else break; } } else { // non-ASCII letter, e.g."C1C2C3C4" if (UnicodeUtil::isAlpha(c)) { if (length == 0) { start = offset - 1; buffer[length++] = c; tokenType = DOUBLE_TOKEN_TYPE; } else { if (tokenType == SINGLE_TOKEN_TYPE) { --offset; --bufferIndex; // return the previous ASCII characters break; } else { buffer[length++] = c; tokenType = DOUBLE_TOKEN_TYPE; if (length == 2) { --offset; --bufferIndex; preIsTokened = true; break; } } } } else if (length > 0) { if (preIsTokened) { // empty the buffer length = 0; preIsTokened = false; } else break; } } } if (length > 0) { termAtt->setTermBuffer(buffer.get(), 0, length); offsetAtt->setOffset(correctOffset(start), correctOffset(start + length)); typeAtt->setType(TOKEN_TYPE_NAMES[tokenType]); return true; } else if (dataLen == -1) { --offset; return false; } // Cycle back and try for the next token (don't return an empty string) } }