当前位置: 首页>>代码示例>>C++>>正文


C++ QStringRef::constData方法代码示例

本文整理汇总了C++中QStringRef::constData方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::constData方法的具体用法?C++ QStringRef::constData怎么用?C++ QStringRef::constData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QStringRef的用法示例。


在下文中一共展示了QStringRef::constData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processComment

void FindTrCalls::processComment(const AST::SourceLocation &loc)
{
    if (!loc.length)
        return;

    const QStringRef commentStr = engine->midRef(loc.begin(), loc.length);
    const QChar *chars = commentStr.constData();
    const int length = commentStr.length();

    // Try to match the logic of the C++ parser.
    if (*chars == QLatin1Char(':') && chars[1].isSpace()) {
        if (!extracomment.isEmpty())
            extracomment += QLatin1Char(' ');
        extracomment += QString(chars+2, length-2);
    } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) {
        msgid = QString(chars+2, length-2).simplified();
    } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) {
        QString text = QString(chars+2, length-2).trimmed();
        int k = text.indexOf(QLatin1Char(' '));
        if (k > -1)
            extra.insert(text.left(k), text.mid(k + 1).trimmed());
    } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) {
        sourcetext.reserve(sourcetext.length() + length-2);
        ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length();
        int p = 2, c;
        forever {
            if (p >= length)
                break;
            c = chars[p++].unicode();
            if (std::isspace(c))
                continue;
            if (c != '"') {
                yyMsg(loc.startLine) << qPrintable(LU::tr("Unexpected character in meta string\n"));
                break;
            }
            forever {
                if (p >= length) {
                  whoops:
                    yyMsg(loc.startLine) << qPrintable(LU::tr("Unterminated meta string\n"));
                    break;
                }
                c = chars[p++].unicode();
                if (c == '"')
                    break;
                if (c == '\\') {
                    if (p >= length)
                        goto whoops;
                    c = chars[p++].unicode();
                    if (c == '\r' || c == '\n')
                        goto whoops;
                    *ptr++ = '\\';
                }
                *ptr++ = c;
            }
        }
        sourcetext.resize(ptr - (ushort *)sourcetext.data());
    } else {
开发者ID:adenexter,项目名称:qttools,代码行数:57,代码来源:qdeclarative.cpp

示例2: valueAsDouble

double ScXmlStreamAttributes::valueAsDouble (const QString& attrName, double def) const
{
	double retValue = def;
	QStringRef att = value(attrName);
	if (!att.isEmpty())
	{
		QString strVal = QString::fromRawData(att.constData(), att.length());
		retValue = ScCLocale::toDoubleC(strVal, def);
	}
	return retValue;
}
开发者ID:moceap,项目名称:scribus,代码行数:11,代码来源:scxmlstreamreader.cpp

示例3: valueAsUInt

uint ScXmlStreamAttributes::valueAsUInt  (const QString& attrName, uint def) const
{
	uint retValue = def;
	QStringRef att = value(attrName);
	if (!att.isEmpty())
	{
		bool success = false;
		QString strVal = QString::fromRawData(att.constData(), att.length());
		uint intVal = strVal.toUInt(&success);
		if (success)
			retValue = intVal;
	}
	return retValue;
}
开发者ID:moceap,项目名称:scribus,代码行数:14,代码来源:scxmlstreamreader.cpp

示例4: valueAsInt

int ScXmlStreamAttributes::valueAsInt (const char* attrName, int def) const
{
	int retValue = def;
	QStringRef att = value(QLatin1String(attrName));
	if (!att.isEmpty())
	{
		bool success = false;
		QString strVal = QString::fromRawData(att.constData(), att.length());
		int intVal = strVal.toInt(&success);
		if (success)
			retValue = intVal;
	}
	return retValue;
}
开发者ID:moceap,项目名称:scribus,代码行数:14,代码来源:scxmlstreamreader.cpp

示例5: valueAsBool

bool ScXmlStreamAttributes::valueAsBool (const QString& attrName, bool def) const
{
	bool retValue = def;
	QStringRef att = value(attrName);
	if (!att.isEmpty())
	{
		bool success = false;
		QString strVal = QString::fromRawData(att.constData(), att.length());
		int intVal = strVal.toInt(&success);
		if (success)
			retValue = static_cast<bool>(intVal);
	}
	return retValue;
}
开发者ID:moceap,项目名称:scribus,代码行数:14,代码来源:scxmlstreamreader.cpp

示例6: file

	std::tuple<bool, const char*> loadWordStatisticsXml(const std::wstring& filePath, WordsUsageInfo& wordsStat, std::vector<const WordSeqUsage*>& wordSeqOrder)
	{
		QFile file(QString::fromStdWString(filePath));
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return std::make_tuple(false, "Can't open file");

		QXmlStreamReader xml;
		xml.setDevice(&file);

		// got to document root

		xml.readNextStartElement(); // document root

		//
		while (!xml.atEnd())
		{
			xml.readNext();
			if (xml.isStartElement() && xml.name() == "word")
			{
				QXmlStreamAttributes attrs = xml.attributes();
				QStringRef idRef = attrs.value("id");
				bool parseNum;
				int usedCount = attrs.value("usedCount").toInt(&parseNum);
				if (!parseNum)
					return std::make_tuple(false, "usedCount must be integer");

				QString wordQ = QString::fromRawData(idRef.constData(), idRef.size());
				std::wstring wordW((const wchar_t*)wordQ.utf16(), wordQ.size());

				bool wasAdded = false;
				const WordPart* wordPart = wordsStat.getOrAddWordPart(wordW, WordPartSide::WholeWord, &wasAdded);
				if (!wasAdded)
					return std::make_tuple(false, "Error: duplicate words in words statistic");
				
				WordSeqKey wordIds({ wordPart->id() });

				WordSeqUsage* wordUsage = wordsStat.getOrAddWordSequence(wordIds, &wasAdded);
				if (!wasAdded)
					return std::make_tuple(false, "Error: duplicate words in words statistic");

				wordUsage->UsedCount = usedCount;

				wordSeqOrder.push_back(wordUsage);
			}
		}
		if (xml.hasError())
			return std::make_tuple(false, "Error in XML parsing");

		return std::make_tuple(true, nullptr);
	}
开发者ID:tivadj,项目名称:PticaGovorun,代码行数:50,代码来源:RunBuildLanguageModel.cpp

示例7: read

void XmlElementReader::read(MapCoordVector& coords)
{
	namespace literal = XmlStreamLiteral;
	
	coords.clear();
	
	const auto num_coords = attribute<unsigned int>(literal::count);
	coords.reserve(std::min(num_coords, 500000u));
	
	try
	{
		for( xml.readNext(); xml.tokenType() != QXmlStreamReader::EndElement; xml.readNext() )
		{
			const QXmlStreamReader::TokenType token = xml.tokenType();
			if (xml.error() || token == QXmlStreamReader::EndDocument)
			{
				throw FileFormatException(ImportExport::tr("Could not parse the coordinates."));
			}
			else if (token == QXmlStreamReader::Characters && !xml.isWhitespace())
			{
				QStringRef text = xml.text();
				QString data = QString::fromRawData(text.constData(), text.length());
				
				QTextStream stream(&data, QIODevice::ReadOnly);
				stream.setIntegerBase(10);
				while (!stream.atEnd())
				{
					coords.emplace_back();
					stream >> coords.back();
				}
				
				if (stream.status() == QTextStream::ReadCorruptData)
				{
					throw FileFormatException(ImportExport::tr("Could not parse the coordinates."));
				}
			}
			else if (token == QXmlStreamReader::StartElement)
			{
				if (xml.name() == literal::coord)
				{
					coords.emplace_back(MapCoord::load(xml));
				}
				else
				{
					xml.skipCurrentElement();
				}
			}
			// otherwise: ignore element
		}
开发者ID:999999333,项目名称:mapper,代码行数:49,代码来源:xml_stream_util.cpp

示例8: readHumanReadableStream

void CoordXmlTest::readHumanReadableStream()
{
	namespace literal = XmlStreamLiteral;
	
	QFETCH(int, num_coords);
	MapCoordVector coords(num_coords, proto_coord);
	
	buffer.buffer().truncate(0);
	QBuffer header;
	{
		QXmlStreamWriter xml(&header);
		
		header.open(QBuffer::ReadWrite);
		xml.setAutoFormatting(false);
		xml.writeStartDocument();
		xml.writeStartElement("root");
		xml.writeCharacters(""); // flush root start element
		
		buffer.open(QBuffer::ReadWrite);
		xml.setDevice(&buffer);
		xml.writeStartElement("coords");
		// Using the more efficient string implementation.
		writeHumanReadableString_implementation(coords, xml);
		xml.writeEndElement();
		
		xml.setDevice(NULL);
		
		buffer.close();
		header.close();
	}
	
	header.open(QBuffer::ReadOnly);
	buffer.open(QBuffer::ReadOnly);
	QXmlStreamReader xml;
	xml.addData(header.buffer());
	xml.readNextStartElement();
	QCOMPARE(xml.name().toString(), QString("root"));
	
	bool failed = false;
	QBENCHMARK
	{
		// benchmark iteration overhead
		coords.clear();
		xml.addData(buffer.data());
		
		xml.readNextStartElement();
		if (xml.name() != "coords")
		{
			failed = true;
			break;
		}
		
		for( xml.readNext();
		     xml.tokenType() != QXmlStreamReader::EndElement;
		     xml.readNext() )
		{
			if (xml.error())
			{
				qDebug() << xml.errorString();
				failed = true;
				break;
			}
			
			const QXmlStreamReader::TokenType token = xml.tokenType();
			if (token == QXmlStreamReader::EndDocument)
			{
				failed = true;
				break;
			}
			
			if (token == QXmlStreamReader::Characters && !xml.isWhitespace())
			{
				QStringRef text = xml.text();
				QString data = QString::fromRawData(text.constData(), text.length());
				QTextStream stream(&data, QIODevice::ReadOnly);
				stream.setIntegerBase(10);
				while (!stream.atEnd())
				{
					qint32 x, y;
					int flags = 0;
					char separator;
					stream >> x >> y >> separator;
					if (separator != ';')
					{
						stream >> flags >> separator;
					}
					coords.push_back(MapCoord::fromNative(x, y, flags));
				}
				if (stream.status() == QTextStream::ReadCorruptData)
				{
					failed = true;
					break;
				}
			}
			// otherwise: ignore element
		}
开发者ID:999999333,项目名称:mapper,代码行数:96,代码来源:coord_xml_t.cpp

示例9: compare

int QCollator::compare(const QStringRef &s1, const QStringRef &s2) const
{
    return compare(s1.constData(), s1.size(), s2.constData(), s2.size());
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:4,代码来源:qcollator_macx.cpp

示例10: file

	std::tuple<bool, const char*> loadUkrainianWordDeclensionXml(const std::wstring& declensionDictPath, std::unordered_map<std::wstring, std::unique_ptr<WordDeclensionGroup>>& declinedWords)
	{
		QFile file(QString::fromStdWString(declensionDictPath));
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return std::make_tuple(false, "Can't open file for reading");

		QXmlStreamReader xml(&file);

		QTextStream dumpFileStream(&file);
		dumpFileStream.setCodec("UTF-8");

		while (!xml.atEnd())
		{
			xml.readNext();
			if (xml.isStartElement() && xml.name() == "group")
			{
				auto newGroup = std::make_unique<WordDeclensionGroup>();

				const QXmlStreamAttributes& attrs = xml.attributes();
				if (attrs.hasAttribute("name"))
				{
					QStringRef nameStr = attrs.value("name");
					QString nameQ = QString::fromRawData(nameStr.constData(), nameStr.size());
					newGroup->Name = nameQ.toStdWString();
				}
				if (attrs.hasAttribute("class"))
				{
					QStringRef attrStr = attrs.value("class");
					newGroup->WordClass = details::parseWordClass(attrStr);
				}
				if (attrs.hasAttribute("gender"))
				{
					QStringRef attrStr = attrs.value("gender");
					newGroup->Gender = details::parseWordGender(attrStr);
				}
				if (attrs.hasAttribute("number"))
				{
					QStringRef attrStr = attrs.value("number");
					newGroup->NumberCategory = details::parseWordNumber(attrStr);
				}
				if (attrs.hasAttribute("isBeing"))
				{
					QStringRef attrStr = attrs.value("isBeing");
					newGroup->IsBeing = details::parseBool(attrStr);
				}
				if (attrs.hasAttribute("person"))
				{
					QStringRef attrStr = attrs.value("person");
					newGroup->Person = details::parseWordPerson(attrStr);
				}
				if (attrs.hasAttribute("perfective"))
				{
					QStringRef attrStr = attrs.value("perfective");
					newGroup->PerfectiveAspect = details::parseWordPerfectiveAspect(attrStr);
				}
				if (attrs.hasAttribute("transitive"))
				{
					QStringRef attrStr = attrs.value("transitive");
					newGroup->Transitive = details::parseWordTransitive(attrStr);
				}
				details::parseDeclensionDictWordGroup(xml, newGroup.get());
				//declinedWords.re
				
				auto it = declinedWords.find(newGroup->Name);
				if (it == std::end(declinedWords))
				{
					// new word
					declinedWords.insert(std::make_pair(newGroup->Name, std::move(newGroup)));
				}
				else
				{
					// duplicate word
					auto& oldGroup = it->second;
					if (oldGroup->Forms.empty() && !newGroup->Forms.empty())
						declinedWords[newGroup->Name] = std::move(newGroup); // update word
					else
					{
						// ignore if old and new groups are empty
						// ignore if old is not empty and new is empty
						// ignore if old and new groups are not empty and are the same

						if (!oldGroup->Forms.empty() && !newGroup->Forms.empty() &&
							 oldGroup->Forms.size()  != newGroup->Forms.size())
							 return std::make_tuple(false, "Duplicate word groups with different word forms");
					}
				}
			}
		}
		if (xml.hasError()) {
			return std::make_tuple(true, "Error in XML stucture");
		}
		return std::make_tuple(true, nullptr);
	}
开发者ID:tivadj,项目名称:PticaGovorun,代码行数:93,代码来源:TextProcessingSerializationXml.cpp

示例11: parseDeclensionDictWordGroup

		void parseDeclensionDictWordGroup(QXmlStreamReader& xml, WordDeclensionGroup* owningWordGroup)
		{
			while (!xml.atEnd())
			{
				xml.readNext();
				if (xml.isEndElement() && xml.name() == "group")
					break;

				if (xml.isStartElement() && xml.name() == "word")
				{
					WordDeclensionForm wordForm;
					wordForm.OwningWordGroup = owningWordGroup;

					const QXmlStreamAttributes& attrs = xml.attributes();
					if (attrs.hasAttribute("name"))
					{
						QStringRef nameStr = attrs.value("name");
						QString nameQ = QString::fromRawData(nameStr.constData(), nameStr.size());
						wordForm.Name = nameQ.toStdWString();
					}
					if (attrs.hasAttribute("class"))
					{
						QStringRef attrStr = attrs.value("class");
						wordForm.WordClass = details::parseWordClass(attrStr);
					}
					if (attrs.hasAttribute("isInfinitive"))
					{
						QStringRef attrStr = attrs.value("isInfinitive");
						wordForm.IsInfinitive = details::parseBool(attrStr);
					}
					if (attrs.hasAttribute("person"))
					{
						QStringRef attrStr = attrs.value("person");
						wordForm.Person = details::parseWordPerson(attrStr);
					}
					if (attrs.hasAttribute("case"))
					{
						QStringRef attrStr = attrs.value("case");
						wordForm.Case = details::parseWordCase(attrStr);
					}
					if (attrs.hasAttribute("gender"))
					{
						QStringRef attrStr = attrs.value("gender");
						wordForm.Gender = details::parseWordGender(attrStr);
					}
					if (attrs.hasAttribute("tense"))
					{
						QStringRef attrStr = attrs.value("tense");
						wordForm.Tense = details::parseWordTense(attrStr);
					}
					if (attrs.hasAttribute("degree"))
					{
						QStringRef attrStr = attrs.value("degree");
						wordForm.Degree = details::parseWordDegree(attrStr);
					}
					if (attrs.hasAttribute("mandative"))
					{
						QStringRef attrStr = attrs.value("mandative");
						wordForm.Mandative = details::parseBool(attrStr);
					}
					if (attrs.hasAttribute("number"))
					{
						QStringRef attrStr = attrs.value("number");
						wordForm.NumberCategory = details::parseWordNumber(attrStr);
					}
					if (attrs.hasAttribute("active"))
					{
						QStringRef attrStr = attrs.value("active");
						wordForm.ActiveOrPassive = details::parseWordActiveOrPassive(attrStr);
					}

					owningWordGroup->Forms.push_back(wordForm);
				}
			}
		}
开发者ID:tivadj,项目名称:PticaGovorun,代码行数:75,代码来源:TextProcessingSerializationXml.cpp

示例12: file

	std::tuple<bool, const char*> loadStressedSyllableDictionaryXml(boost::wstring_ref dictFilePath, std::unordered_map<std::wstring, int>& wordToStressedSyllableInd)
	{
		QFile file(QString::fromWCharArray(dictFilePath.begin(), dictFilePath.size()));
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return std::make_tuple(false, "Can't open file");

		QXmlStreamReader xmlReader(&file);
		std::wstring wordName;
		while (!xmlReader.atEnd())
		{
			xmlReader.readNext();
			if (xmlReader.isStartElement() && xmlReader.name() == SressDictWordTag)
			{
				wordName.clear();
				int wordStressedSyllableInd = -1;

				const QXmlStreamAttributes& attrs = xmlReader.attributes();
				if (attrs.hasAttribute(SressDictWordName))
				{
					QStringRef nameStr = attrs.value(SressDictWordName);
					QString nameQ = QString::fromRawData(nameStr.constData(), nameStr.size());
					wordName = nameQ.toStdWString();
				}
				if (attrs.hasAttribute(SressDictWordSyllable))
				{
					QStringRef stressStr = attrs.value(SressDictWordSyllable);
					int sepInd = stressStr.indexOf(' ');
					if (sepInd != -1)
						stressStr = stressStr.left(sepInd);

					bool convOp = false;
					wordStressedSyllableInd = stressStr.toInt(&convOp);
					if (!convOp)
						return std::make_tuple(false, "Can't parse stressed syllable definition");
					
					wordStressedSyllableInd -= 1; // dict has 1-based index
				}

				if (wordName.empty() || wordStressedSyllableInd == -1)
					return std::make_tuple(false, "The word stress definition is incomplete");

				auto checkSyllableInd = [](const std::wstring& word, int syllabInd)
				{
					if (syllabInd < 0)
						return false;

					int vowelsCount = vowelsCountUk(word);
					if (syllabInd >= vowelsCount)
						return false;
					return true;
				};
				if (!checkSyllableInd(wordName, wordStressedSyllableInd))
					std::make_tuple(false, "Syllable index is out of range");

				wordToStressedSyllableInd[wordName] = wordStressedSyllableInd;
			}
		}
		if (xmlReader.hasError())
			return std::make_tuple(false, "Error reading XML stressed syllables definitions");

		return std::make_tuple(true, nullptr);
	}
开发者ID:tivadj,项目名称:PticaGovorun,代码行数:62,代码来源:PhoneticStress.cpp


注:本文中的QStringRef::constData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。