本文整理汇总了C++中QStringRef::indexOf方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::indexOf方法的具体用法?C++ QStringRef::indexOf怎么用?C++ QStringRef::indexOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::indexOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseNextLine
void QLoggingSettingsParser::parseNextLine(QStringRef line)
{
// Remove whitespace at start and end of line:
line = line.trimmed();
// comment
if (line.startsWith(QLatin1Char(';')))
return;
if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) {
// new section
auto sectionName = line.mid(1, line.size() - 2).trimmed();
m_inRulesSection = sectionName.compare(QLatin1String("rules"), Qt::CaseInsensitive) == 0;
return;
}
if (m_inRulesSection) {
int equalPos = line.indexOf(QLatin1Char('='));
if (equalPos != -1) {
if (line.lastIndexOf(QLatin1Char('=')) == equalPos) {
const auto pattern = line.left(equalPos).trimmed();
const auto valueStr = line.mid(equalPos + 1).trimmed();
int value = -1;
if (valueStr == QLatin1String("true"))
value = 1;
else if (valueStr == QLatin1String("false"))
value = 0;
QLoggingRule rule(pattern, (value == 1));
if (rule.flags != 0 && (value != -1))
_rules.append(rule);
else
warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData());
} else {
warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData());
}
}
}
}
示例2: 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);
}