/** * @brief VoiceEndpoint::sendDictationResults * Important: Pebble accepts only 1 sentence currently, hence need to choose the best one here */ void VoiceEndpoint::sendDictationResults() { if(m_sessId>0) { if(m_sesTimer) { killTimer(m_sesTimer); m_sesTimer = 0; m_sesPhase = PhResultSent; } quint32 flags = m_appUuid.isNull()?0:FlagAppInitiated; quint8 result = (m_sesResult.sentences.count()>0)?ResSuccess:ResInvalidRecognizerResponse; qDebug() << "Sending session recognition result" << result << "for session" << m_sessId << "with content" << m_sesResult.sentences.count() << "for app" << m_appUuid << m_appUuid.isNull(); QByteArray pkt; WatchDataWriter writer(&pkt); writer.write<quint8>(CmdDictatResult); writer.writeLE<quint32>(flags); writer.writeLE<quint16>(m_sessId); writer.write<quint8>(result); AttributeList al; if(!m_appUuid.isNull()) al.append(Attribute(m_appUuid)); m_sesResult.sort(1); if(result==ResSuccess) al.append(Attribute(Transcription(m_sesResult))); al.writerWrite(writer); m_watchConnection->writeToPebble(WatchConnection::EndpointVoiceControl,pkt); qDebug() << "Sent" << pkt.toHex(); } }
bool HTMLMetaCharsetParser::processMeta(HTMLToken& token) { AttributeList attributes; for (auto& attribute : token.attributes()) { String attributeName = StringImpl::create8BitIfPossible(attribute.name); String attributeValue = StringImpl::create8BitIfPossible(attribute.value); attributes.append(std::make_pair(attributeName, attributeValue)); } m_encoding = encodingFromMetaAttributes(attributes); return m_encoding.isValid(); }
bool HTMLMetaCharsetParser::processMeta() { const HTMLToken::AttributeList& tokenAttributes = m_token.attributes(); AttributeList attributes; for (HTMLToken::AttributeList::const_iterator iter = tokenAttributes.begin(); iter != tokenAttributes.end(); ++iter) { String attributeName = StringImpl::create8BitIfPossible(iter->m_name.data(), iter->m_name.size()); String attributeValue = StringImpl::create8BitIfPossible(iter->m_value.data(), iter->m_value.size()); attributes.append(std::make_pair(attributeName, attributeValue)); } m_encoding = encodingFromMetaAttributes(attributes); return m_encoding.isValid(); }
void DTD::parseTagAttributeValues(const QString &name, QString *value) { AttributeList *attributes = new AttributeList(); QStringList attrLines = QStringList::split("\\end",*value); QStringList::Iterator lineIt = attrLines.begin(); while (lineIt != attrLines.end()) //iterate through the attribute lines { //split the attribute line QStringList all = QStringList::split(" ", *lineIt); QStringList::Iterator it = all.begin(); while(it != all.end()) { Attribute *attr = new Attribute(); attr->name = *it; //kdDebug() << "Inserting for tag " << name << ": " << *it << endl; ++it; QString values = *it; //list of possible values if ( values.startsWith("(") && values.endsWith(")") ) { values.remove(0,1); values.remove(values.length()-1,1); attr->values = QStringList::split("|", values); QString s = (attr->values[0]+attr->values[1]).lower(); stripSpaces(&s); if ((s == "truefalse") || (s == "falsetrue")) { attr->type = "check"; } else { attr->type = "list"; } } else { attr->values = values; attr->type = "input"; } //kdDebug() << " --- values: " << *it << endl; if (it != all.end()) { ++it; QString s=*it; if (s.startsWith("\"") && s.endsWith("\"") && it!=all.end()) { s.remove(0,1); s.remove(s.length()-1,1); attr->defaultValue = s; } if (s.startsWith("#") && it != all.end()) { s.remove(0,1); attr->status = s.lower(); } if (*it == "#FIXED" && it != all.end()) { ++it; attr->values.append(*it); } } if (it != all.end()) { ++it; } attributes->append(attr); } ++lineIt; } tagAttributes.insert(name, attributes); }
void ASF::Tag::setAttribute(const String &name, const Attribute &attribute) { AttributeList value; value.append(attribute); d->attributeListMap.insert(name, value); }
void saveElement(xmlElementPtr elem, xmlBufferPtr buf) { Q_UNUSED(buf); if (elem) { QString elemName = QString((const char*)elem->name); QFile file( DTD::dirName + elemName + ".tag" ); if ( file.open( IO_WriteOnly ) ) { QTextStream stream( &file ); stream.setEncoding(QTextStream::UnicodeUTF8); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; stream << "<!DOCTYPE TAGS>" << endl << "<TAGS>" << endl << "<tag name=\"" << elemName << "\">" << endl << endl; xmlElementPtr el_ptr; /* Pointer to an element description */ xmlAttributePtr at_ptr; el_ptr = xmlGetDtdElementDesc(DTD::dtd_ptr, elem->name); AttributeList attributes; attributes.setAutoDelete(true); if (el_ptr) { at_ptr = el_ptr->attributes; while (at_ptr) { Attribute *attr = new Attribute; attr->name = QString((const char*)at_ptr->name); switch (at_ptr->def) { case 1: {attr->status = "optional"; break;} //NONE case 2: {attr->status = "required"; break;} //REQUIRED case 3: {attr->status = "implied"; break;} //IMPLIED case 4: {attr->status = "fixed"; break;} //FIXED } attr->defaultValue = QString((const char*)at_ptr->defaultValue); xmlEnumerationPtr enum_ptr; enum_ptr = at_ptr->tree; while (enum_ptr) { attr->values += QString((const char*)enum_ptr->name); enum_ptr = enum_ptr->next; } QString attrtype; switch (at_ptr->atype) { case 9: {attrtype = "list"; break;} default: {attrtype = "input"; break;} //TODO handle the rest of types } attr->type = attrtype; attributes.append(attr); at_ptr = at_ptr->nexth; } } if (!attributes.isEmpty()) stream << QuantaCommon::xmlFromAttributes(&attributes); const xmlChar *list_ptr[MAX_CHILD_ELEMENTS]; int childNum = 0; childNum = xmlValidGetPotentialChildren(el_ptr->content, list_ptr, &childNum, MAX_CHILD_ELEMENTS); if (childNum > 0) { stream << "<children>" << endl; for( int i = 0; i < childNum; i++ ) { stream << " <child name=\"" << QString((const char*)list_ptr[i]) << "\""; xmlElementPtr child_ptr = xmlGetDtdElementDesc(DTD::dtd_ptr, list_ptr[i]); if (child_ptr && child_ptr->content && child_ptr->content->ocur) { //if (child_ptr->content->ocur == XML_ELEMENT_CONTENT_PLUS) //{ // stream << " usage=\"required\""; // } QString ocur; switch (child_ptr->content->ocur) { case 1: {ocur = "once"; break;} case 2: {ocur = "opt"; break;} case 3: {ocur = "mult"; break;} case 4: {ocur = "plus"; break;} } stream << " usage=\"" << ocur << "\""; QString name = QString((const char*)child_ptr->content->name); if (name == "#PCDATA") name == "#text"; stream << " name2=\"" << name << "\""; } stream << " />" << endl; } stream << "</children>" << endl; stream << endl; } /* xmlElementContentPtr content_ptr = el_ptr->content; if (content_ptr) { stream << "<children>" << endl; while (content_ptr) { if (!QString((const char*)content_ptr->name).isEmpty()) { stream << " <child name=\"" << QString((const char*)content_ptr->name) << "\""; QString ocur; switch (content_ptr->ocur) { case 1: {ocur = "once"; break;} case 2: {ocur = "opt"; break;} case 3: {ocur = "mult"; break;} case 4: {ocur = "plus"; break;} } stream << " usage=\"" << ocur << "\""; stream << " />" << endl; } if (content_ptr->c1) content_ptr = content_ptr->c1; else if (content_ptr->c2) content_ptr = content_ptr->c2; else { if (content_ptr == el_ptr->content) break; if (content_ptr->parent) { if (content_ptr == content_ptr->parent->c1) content_ptr->c1 = 0L; else content_ptr->c2 = 0L; } content_ptr = content_ptr->parent; } } stream << "</children>" << endl; } */ stream << "</tag>" << endl << "</TAGS>" << endl; file.close(); } } }