Changeset View
Changeset View
Standalone View
Standalone View
src/lib/definition.cpp
Show First 20 Lines • Show All 320 Lines • ▼ Show 20 Line(s) | |||||
321 | Context* DefinitionData::initialContext() const | 321 | Context* DefinitionData::initialContext() const | ||
322 | { | 322 | { | ||
323 | Q_ASSERT(!contexts.isEmpty()); | 323 | Q_ASSERT(!contexts.isEmpty()); | ||
324 | return contexts.first(); | 324 | return contexts.first(); | ||
325 | } | 325 | } | ||
326 | 326 | | |||
327 | Context* DefinitionData::contextByName(const QString& name) const | 327 | Context* DefinitionData::contextByName(const QString& name) const | ||
328 | { | 328 | { | ||
329 | foreach (auto context, contexts) { | 329 | for (const auto context : contexts) { | ||
330 | if (context->name() == name) | 330 | if (context->name() == name) | ||
331 | return context; | 331 | return context; | ||
332 | } | 332 | } | ||
333 | return nullptr; | 333 | return nullptr; | ||
334 | } | 334 | } | ||
335 | 335 | | |||
336 | KeywordList *DefinitionData::keywordList(const QString& name) | 336 | KeywordList *DefinitionData::keywordList(const QString& name) | ||
337 | { | 337 | { | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 377 | while (!reader.atEnd()) { | |||
389 | else if (reader.name() == QLatin1String("general")) | 389 | else if (reader.name() == QLatin1String("general")) | ||
390 | loadGeneral(reader); | 390 | loadGeneral(reader); | ||
391 | } | 391 | } | ||
392 | 392 | | |||
393 | for (auto it = keywordLists.begin(); it != keywordLists.end(); ++it) { | 393 | for (auto it = keywordLists.begin(); it != keywordLists.end(); ++it) { | ||
394 | it->setCaseSensitivity(caseSensitive); | 394 | it->setCaseSensitivity(caseSensitive); | ||
395 | } | 395 | } | ||
396 | 396 | | |||
397 | foreach (auto context, contexts) { | 397 | for (const auto context : qAsConst(contexts)) { | ||
398 | context->resolveContexts(); | 398 | context->resolveContexts(); | ||
399 | context->resolveIncludes(); | 399 | context->resolveIncludes(); | ||
400 | context->resolveAttributeFormat(); | 400 | context->resolveAttributeFormat(); | ||
401 | } | 401 | } | ||
402 | 402 | | |||
403 | Q_ASSERT(std::is_sorted(wordDelimiters.constBegin(), wordDelimiters.constEnd())); | 403 | Q_ASSERT(std::is_sorted(wordDelimiters.constBegin(), wordDelimiters.constEnd())); | ||
404 | return true; | 404 | return true; | ||
405 | } | 405 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 453 | { | |||
458 | style = obj.value(QLatin1String("style")).toString(); | 458 | style = obj.value(QLatin1String("style")).toString(); | ||
459 | author = obj.value(QLatin1String("author")).toString(); | 459 | author = obj.value(QLatin1String("author")).toString(); | ||
460 | license = obj.value(QLatin1String("license")).toString(); | 460 | license = obj.value(QLatin1String("license")).toString(); | ||
461 | indenter = obj.value(QLatin1String("indenter")).toString(); | 461 | indenter = obj.value(QLatin1String("indenter")).toString(); | ||
462 | hidden = obj.value(QLatin1String("hidden")).toBool(); | 462 | hidden = obj.value(QLatin1String("hidden")).toBool(); | ||
463 | fileName = file; | 463 | fileName = file; | ||
464 | 464 | | |||
465 | const auto exts = obj.value(QLatin1String("extensions")).toString(); | 465 | const auto exts = obj.value(QLatin1String("extensions")).toString(); | ||
466 | foreach (const auto &ext, exts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | 466 | for (const auto &ext : exts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||
467 | extensions.push_back(ext); | 467 | extensions.push_back(ext); | ||
468 | const auto mts = obj.value(QLatin1String("mimetype")).toString(); | 468 | const auto mts = obj.value(QLatin1String("mimetype")).toString(); | ||
469 | foreach (const auto &mt, mts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | 469 | for (const auto &mt : mts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||
470 | mimetypes.push_back(mt); | 470 | mimetypes.push_back(mt); | ||
471 | 471 | | |||
472 | return true; | 472 | return true; | ||
473 | } | 473 | } | ||
474 | 474 | | |||
475 | bool DefinitionData::loadLanguage(QXmlStreamReader &reader) | 475 | bool DefinitionData::loadLanguage(QXmlStreamReader &reader) | ||
476 | { | 476 | { | ||
477 | Q_ASSERT(reader.name() == QLatin1String("language")); | 477 | Q_ASSERT(reader.name() == QLatin1String("language")); | ||
478 | Q_ASSERT(reader.tokenType() == QXmlStreamReader::StartElement); | 478 | Q_ASSERT(reader.tokenType() == QXmlStreamReader::StartElement); | ||
479 | 479 | | |||
480 | if (!checkKateVersion(reader.attributes().value(QStringLiteral("kateversion")))) | 480 | if (!checkKateVersion(reader.attributes().value(QStringLiteral("kateversion")))) | ||
481 | return false; | 481 | return false; | ||
482 | 482 | | |||
483 | name = reader.attributes().value(QStringLiteral("name")).toString(); | 483 | name = reader.attributes().value(QStringLiteral("name")).toString(); | ||
484 | section = reader.attributes().value(QStringLiteral("section")).toString(); | 484 | section = reader.attributes().value(QStringLiteral("section")).toString(); | ||
485 | // toFloat instead of toInt for backward compatibility with old Kate files | 485 | // toFloat instead of toInt for backward compatibility with old Kate files | ||
486 | version = reader.attributes().value(QStringLiteral("version")).toFloat(); | 486 | version = reader.attributes().value(QStringLiteral("version")).toFloat(); | ||
487 | priority = reader.attributes().value(QStringLiteral("priority")).toInt(); | 487 | priority = reader.attributes().value(QStringLiteral("priority")).toInt(); | ||
488 | hidden = Xml::attrToBool(reader.attributes().value(QStringLiteral("hidden"))); | 488 | hidden = Xml::attrToBool(reader.attributes().value(QStringLiteral("hidden"))); | ||
489 | style = reader.attributes().value(QStringLiteral("style")).toString(); | 489 | style = reader.attributes().value(QStringLiteral("style")).toString(); | ||
490 | indenter = reader.attributes().value(QStringLiteral("indenter")).toString(); | 490 | indenter = reader.attributes().value(QStringLiteral("indenter")).toString(); | ||
491 | author = reader.attributes().value(QStringLiteral("author")).toString(); | 491 | author = reader.attributes().value(QStringLiteral("author")).toString(); | ||
492 | license = reader.attributes().value(QStringLiteral("license")).toString(); | 492 | license = reader.attributes().value(QStringLiteral("license")).toString(); | ||
493 | const auto exts = reader.attributes().value(QStringLiteral("extensions")).toString(); | 493 | const auto exts = reader.attributes().value(QStringLiteral("extensions")).toString(); | ||
494 | foreach (const auto &ext, exts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | 494 | for (const auto &ext : exts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||
495 | extensions.push_back(ext); | 495 | extensions.push_back(ext); | ||
496 | const auto mts = reader.attributes().value(QStringLiteral("mimetype")).toString(); | 496 | const auto mts = reader.attributes().value(QStringLiteral("mimetype")).toString(); | ||
497 | foreach (const auto &mt, mts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | 497 | for (const auto &mt : mts.split(QLatin1Char(';'), QString::SkipEmptyParts)) | ||
498 | mimetypes.push_back(mt); | 498 | mimetypes.push_back(mt); | ||
499 | if (reader.attributes().hasAttribute(QStringLiteral("casesensitive"))) | 499 | if (reader.attributes().hasAttribute(QStringLiteral("casesensitive"))) | ||
500 | caseSensitive = Xml::attrToBool(reader.attributes().value(QStringLiteral("casesensitive"))) ? Qt::CaseSensitive : Qt::CaseInsensitive; | 500 | caseSensitive = Xml::attrToBool(reader.attributes().value(QStringLiteral("casesensitive"))) ? Qt::CaseSensitive : Qt::CaseInsensitive; | ||
501 | return true; | 501 | return true; | ||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | void DefinitionData::loadHighlighting(QXmlStreamReader& reader, OnlyKeywords onlyKeywords) | 504 | void DefinitionData::loadHighlighting(QXmlStreamReader& reader, OnlyKeywords onlyKeywords) | ||
505 | { | 505 | { | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 627 | if (reader.name() == QLatin1String("keywords")) { | |||
628 | if (reader.attributes().hasAttribute(QStringLiteral("casesensitive"))) | 628 | if (reader.attributes().hasAttribute(QStringLiteral("casesensitive"))) | ||
629 | caseSensitive = Xml::attrToBool(reader.attributes().value(QStringLiteral("casesensitive"))) ? Qt::CaseSensitive : Qt::CaseInsensitive; | 629 | caseSensitive = Xml::attrToBool(reader.attributes().value(QStringLiteral("casesensitive"))) ? Qt::CaseSensitive : Qt::CaseInsensitive; | ||
630 | 630 | | |||
631 | // adapt sorted wordDelimiters | 631 | // adapt sorted wordDelimiters | ||
632 | wordDelimiters += reader.attributes().value(QStringLiteral("additionalDeliminator")); | 632 | wordDelimiters += reader.attributes().value(QStringLiteral("additionalDeliminator")); | ||
633 | std::sort(wordDelimiters.begin(), wordDelimiters.end()); | 633 | std::sort(wordDelimiters.begin(), wordDelimiters.end()); | ||
634 | auto it = std::unique(wordDelimiters.begin(), wordDelimiters.end()); | 634 | auto it = std::unique(wordDelimiters.begin(), wordDelimiters.end()); | ||
635 | wordDelimiters.truncate(std::distance(wordDelimiters.begin(), it)); | 635 | wordDelimiters.truncate(std::distance(wordDelimiters.begin(), it)); | ||
636 | foreach (const auto c, reader.attributes().value(QLatin1String("weakDeliminator"))) | 636 | for (const auto c : reader.attributes().value(QLatin1String("weakDeliminator"))) | ||
637 | wordDelimiters.remove(c); | 637 | wordDelimiters.remove(c); | ||
638 | 638 | | |||
639 | // adaptWordWrapDelimiters, and sort | 639 | // adaptWordWrapDelimiters, and sort | ||
640 | wordWrapDelimiters = reader.attributes().value(QStringLiteral("wordWrapDeliminator")).toString(); | 640 | wordWrapDelimiters = reader.attributes().value(QStringLiteral("wordWrapDeliminator")).toString(); | ||
641 | std::sort(wordWrapDelimiters.begin(), wordWrapDelimiters.end()); | 641 | std::sort(wordWrapDelimiters.begin(), wordWrapDelimiters.end()); | ||
642 | if (wordWrapDelimiters.isEmpty()) | 642 | if (wordWrapDelimiters.isEmpty()) | ||
643 | wordWrapDelimiters = wordDelimiters; | 643 | wordWrapDelimiters = wordDelimiters; | ||
644 | } else if (reader.name() == QLatin1String("folding")) { | 644 | } else if (reader.name() == QLatin1String("folding")) { | ||
▲ Show 20 Lines • Show All 189 Lines • Show Last 20 Lines |