本文整理汇总了C++中QStringRef::compare方法的典型用法代码示例。如果您正苦于以下问题:C++ QStringRef::compare方法的具体用法?C++ QStringRef::compare怎么用?C++ QStringRef::compare使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QStringRef
的用法示例。
在下文中一共展示了QStringRef::compare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reader
// Convenience to create a Dom Widget from widget box xml code.
DomUI *QDesignerWidgetBox::xmlToUi(const QString &name, const QString &xml, bool insertFakeTopLevel,
QString *errorMessage)
{
QXmlStreamReader reader(xml);
DomUI *ui = 0;
// The xml description must either contain a root element "ui" with a child element "widget"
// or "widget" as the root element (4.3 legacy)
const QString widgetTag = QLatin1String("widget");
while (!reader.atEnd()) {
if (reader.readNext() == QXmlStreamReader::StartElement) {
const QStringRef name = reader.name();
if (ui) {
reader.raiseError(tr("Unexpected element <%1>").arg(name.toString()));
continue;
}
if (name.compare(QLatin1String("widget"), Qt::CaseInsensitive) == 0) { // 4.3 legacy, wrap into DomUI
ui = new DomUI;
DomWidget *widget = new DomWidget;
widget->read(reader);
ui->setElementWidget(widget);
} else if (name.compare(QLatin1String("ui"), Qt::CaseInsensitive) == 0) { // 4.4
ui = new DomUI;
ui->read(reader);
} else {
reader.raiseError(tr("Unexpected element <%1>").arg(name.toString()));
}
}
}
if (reader.hasError()) {
delete ui;
*errorMessage = tr("A parse error occurred at line %1, column %2 of the XML code "
"specified for the widget %3: %4\n%5")
.arg(reader.lineNumber()).arg(reader.columnNumber()).arg(name)
.arg(reader.errorString()).arg(xml);
return 0;
}
if (!ui || !ui->elementWidget()) {
delete ui;
*errorMessage = tr("The XML code specified for the widget %1 does not contain "
"any widget elements.\n%2").arg(name).arg(xml);
return 0;
}
if (insertFakeTopLevel) {
DomWidget *fakeTopLevel = new DomWidget;
fakeTopLevel->setAttributeClass(QLatin1String("QWidget"));
QList<DomWidget *> children;
children.push_back(ui->takeElementWidget());
fakeTopLevel->setElementWidget(children);
ui->setElementWidget(fakeTopLevel);
}
return ui;
}
示例2: parseWordClass
boost::optional<WordClass> parseWordClass(QStringRef text)
{
struct WordClassToStr
{
WordClass WordClass;
const wchar_t* CStr;
};
static std::array<WordClassToStr, 13> classes = {
WordClassToStr{ WordClass::Noun, L"noun" },
WordClassToStr{ WordClass::Pronoun, L"pronoun" },
WordClassToStr{ WordClass::Preposition, L"preposition" },
WordClassToStr{ WordClass::Verb, L"verb" },
WordClassToStr{ WordClass::Adverb, L"adverb" },
WordClassToStr{ WordClass::VerbalAdverb, L"verbalAdverb" },
WordClassToStr{ WordClass::Adjective, L"adjective" },
WordClassToStr{ WordClass::Participle, L"participle" },
WordClassToStr{ WordClass::Numeral, L"numeral" },
WordClassToStr{ WordClass::Conjunction, L"conjunction" },
WordClassToStr{ WordClass::Interjection, L"interjection" },
WordClassToStr{ WordClass::Particle, L"particle" },
WordClassToStr{ WordClass::Irremovable, L"irremovable" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.WordClass;
}
return nullptr;
}
示例3: parseWordPerson
boost::optional<WordPerson> parseWordPerson(QStringRef text)
{
struct WordPersonToStr
{
WordPerson Person;
const wchar_t* CStr;
};
static std::array<WordPersonToStr, 9> classes = {
WordPersonToStr{ WordPerson::Impersonal, L"impersonal" },
WordPersonToStr{ WordPerson::I, L"i" },
WordPersonToStr{ WordPerson::YouFamiliar, L"youFamiliar" },
WordPersonToStr{ WordPerson::He, L"he" },
WordPersonToStr{ WordPerson::She, L"she" },
WordPersonToStr{ WordPerson::It, L"it" },
WordPersonToStr{ WordPerson::We, L"we" },
WordPersonToStr{ WordPerson::YouRespectful, L"youRespectful" },
WordPersonToStr{ WordPerson::They, L"they" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Person;
}
return nullptr;
}
示例4: setContent
/*!
\internal
Parses configuration from \a stream.
*/
void QLoggingSettingsParser::setContent(QTextStream &stream)
{
_rules.clear();
while (!stream.atEnd()) {
QString line = stream.readLine();
// Remove all whitespace from line
line = line.simplified();
line.remove(QLatin1Char(' '));
// comment
if (line.startsWith(QLatin1Char(';')))
continue;
if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) {
// new section
_section = line.mid(1, line.size() - 2);
continue;
}
if (_section == QLatin1String("Rules")) {
int equalPos = line.indexOf(QLatin1Char('='));
if ((equalPos != -1)
&& (line.lastIndexOf(QLatin1Char('=')) == equalPos)) {
const QString pattern = line.left(equalPos);
const QStringRef value = line.midRef(equalPos + 1);
bool enabled = (value.compare(QLatin1String("true"),
Qt::CaseInsensitive) == 0);
_rules.append(QLoggingRule(pattern, enabled));
}
}
}
}
示例5: validateExtension
bool ImageLoader::validateExtension(QString filename) const {
/**
* Assumption OS does not allow an empty filename (excluding exten-
* sion) to be used for files, thus is it pointless to provide only
* the extension to the file.
*/
QStringRef ref = filename.midRef(filename.length()-3,3);
if(ref.compare(".sr",Qt::CaseInsensitive) == 0){
return true;
}
//if filename is smaller than 5 it can not be valid anymore
if(filename.length() < 5) return false;
ref.clear();
ref = filename.midRef(filename.length()-4,4);
if(ref.compare(".bmp",Qt::CaseInsensitive) == 0
|| ref.compare(".dib",Qt::CaseInsensitive) == 0
|| ref.compare(".jpg",Qt::CaseInsensitive) == 0
|| ref.compare(".jpe",Qt::CaseInsensitive) == 0
|| ref.compare(".png",Qt::CaseInsensitive) == 0
|| ref.compare(".pbm",Qt::CaseInsensitive) == 0
|| ref.compare(".pgm",Qt::CaseInsensitive) == 0
|| ref.compare(".ppm",Qt::CaseInsensitive) == 0
|| ref.compare(".ras",Qt::CaseInsensitive) == 0
|| ref.compare(".tif",Qt::CaseInsensitive) == 0 ){
return true;
}
//if filename is smaller than 6 it can not be valid anymore
if(filename.length() < 6) return false;
ref.clear();
ref = filename.midRef(filename.length()-5,5);
if(ref.compare(".jpeg",Qt::CaseInsensitive) == 0
|| ref.compare(".tiff",Qt::CaseInsensitive) == 0 ){
return true;
}
//none of the cases matched.
return false;
}
示例6: nextToken
Token nextToken() {
while (pos < len && data.at(pos).isSpace())
pos++;
if (pos == len)
throw JSONParseException("Unexpected EOF", location());
QChar c = data.at(pos++);
if (c.isLetter()) { // keyword like NULL,TRUE or FALSE
int start = pos - 1;
while (pos < len && data.at(pos).isLetter())
pos++;
QStringRef ref = data.midRef(start, pos - start);
if (ref.compare("null", Qt::CaseInsensitive) == 0)
return TokenNULL;
if (ref.compare("true", Qt::CaseInsensitive) == 0)
return TokenTRUE;
if (ref.compare("false", Qt::CaseInsensitive) == 0)
return TokenFALSE;
throw JSONParseException("Unquoted string", location());
}
if (c.isDigit() || c == '-') { // double or hex
pos--;
return TokenNumber;
}
switch (c.unicode()) {
case '"': return TokenString;
case '{': return TokenObject;
case '}': return TokenObjectClose;
case '[': return TokenArray;
case ']': return TokenArrayClose;
case ':': return TokenKeySeparator;
case ',': return TokenValueSeparator;
default:
throw JSONParseException(QString("Unexpected character: %1").arg(c),
location());
}
}
示例7: parseWordTransitive
boost::optional<WordTransitive> parseWordTransitive(QStringRef text)
{
struct TransitiveToStr
{
WordTransitive Transitive;
const wchar_t* CStr;
};
static std::array<TransitiveToStr, 2> classes = {
TransitiveToStr{ WordTransitive::Transitive, L"transitive" },
TransitiveToStr{ WordTransitive::Intransitive, L"intransitive" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Transitive;
}
return nullptr;
}
示例8: parseWordPerfectiveAspect
boost::optional<WordPerfectiveAspect> parseWordPerfectiveAspect(QStringRef text)
{
struct PerfToStr
{
WordPerfectiveAspect Perf;
const wchar_t* CStr;
};
static std::array<PerfToStr, 2> classes = {
PerfToStr{ WordPerfectiveAspect::Imperfective, L"impersonal" },
PerfToStr{ WordPerfectiveAspect::Perfective, L"perfective" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Perf;
}
return nullptr;
}
示例9: parseWordActiveOrPassive
boost::optional<WordActiveOrPassive> parseWordActiveOrPassive(QStringRef text)
{
struct ActiveToStr
{
WordActiveOrPassive Active;
const wchar_t* CStr;
};
static std::array<ActiveToStr, 3> classes = {
ActiveToStr{ WordActiveOrPassive::Active, L"active" },
ActiveToStr{ WordActiveOrPassive::Passive, L"passive" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Active;
}
return nullptr;
}
示例10: parseBool
boost::optional<bool> parseBool(QStringRef text)
{
struct BoolToStr
{
bool Bool;
const wchar_t* CStr;
};
static std::array<BoolToStr, 2> classes = {
BoolToStr{ false, L"false" },
BoolToStr{ true, L"true" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Bool;
}
return nullptr;
}
示例11: parseWordNumber
boost::optional<WordNumberCategory> parseWordNumber(QStringRef text)
{
struct WordNumberToStr
{
WordNumberCategory WordNumber;
const wchar_t* CStr;
};
static std::array<WordNumberToStr, 2> classes = {
WordNumberToStr{ WordNumberCategory::Singular, L"singular" },
WordNumberToStr{ WordNumberCategory::Plural, L"plural" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.WordNumber;
}
return nullptr;
}
示例12: parseWordGender
boost::optional<WordGender> parseWordGender(QStringRef text)
{
struct WordGenderToStr
{
WordGender WordGender;
const wchar_t* CStr;
};
static std::array<WordGenderToStr, 3> classes = {
WordGenderToStr{ WordGender::Masculine, L"masculine" },
WordGenderToStr{ WordGender::Feminine, L"feminine" },
WordGenderToStr{ WordGender::Neuter, L"neuter" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.WordGender;
}
return nullptr;
}
示例13: parseWordDegree
boost::optional<WordDegree> parseWordDegree(QStringRef text)
{
struct DegreeToStr
{
WordDegree Degree;
const wchar_t* CStr;
};
static std::array<DegreeToStr, 3> classes = {
DegreeToStr{ WordDegree::Positive, L"positive" },
DegreeToStr{ WordDegree::Comparative, L"comparative" },
DegreeToStr{ WordDegree::Superlative, L"superlative" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Degree;
}
return nullptr;
}
示例14: parseWordTense
boost::optional<ActionTense> parseWordTense(QStringRef text)
{
struct TenseToStr
{
ActionTense Tense;
const wchar_t* CStr;
};
static std::array<TenseToStr, 3> classes = {
TenseToStr{ ActionTense::Past, L"past" },
TenseToStr{ ActionTense::Present, L"present" },
TenseToStr{ ActionTense::Future, L"future" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Tense;
}
return nullptr;
}
示例15: parseWordCase
boost::optional<WordCase> parseWordCase(QStringRef text)
{
struct CaseToStr
{
WordCase Case;
const wchar_t* CStr;
};
static std::array<CaseToStr, 9> classes = {
CaseToStr{ WordCase::Nominative, L"nominative" },
CaseToStr{ WordCase::Genitive, L"genitive" },
CaseToStr{ WordCase::Dative, L"dative" },
CaseToStr{ WordCase::Acusative, L"acusative" },
CaseToStr{ WordCase::Instrumental, L"instrumental" },
CaseToStr{ WordCase::Locative, L"locative" },
CaseToStr{ WordCase::Vocative, L"vocative" },
};
for(const auto& pair : classes)
{
const QString wordClassStr = QString::fromWCharArray(pair.CStr);
if (text.compare(wordClassStr, Qt::CaseSensitive) == 0)
return pair.Case;
}
return nullptr;
}