37 auto endOffset = m_code.indexOf(onCmd, offset) + onCmd.size();
38 if (endOffset < onCmd.size())
39 endOffset = m_code.size();
43 while (endOffset + newLine.size() <= m_code.size() &&
44 m_code.mid(endOffset, newLine.size()) == newLine && newlineCount < 2) {
45 endOffset += newLine.size();
48 return quint32(endOffset);
52 const QQmlJS::SourceLocation &on, QLatin1StringView newline)
54 const auto startOffset = findLineStartOffset(code, off.offset, newline);
55 const auto endOffset = findDirectiveEndOffset(code, on.offset, newline);
56 return QQmlJS::SourceLocation{ startOffset, endOffset - startOffset, 0, 0 };
67 const auto newline = detectNewLine(code);
68 const auto isOffDirective = [&code, newline](
const QQmlJS::SourceLocation &loc) {
69 const auto commentLineString = commentLineFromLoc(code, loc, newline);
70 const auto directive = directiveFromComment(commentLineString);
71 return directive && *directive == Directive::Off;
74 const auto isOnDirective = [&code, newline](
const QQmlJS::SourceLocation &loc) {
75 const auto commentLineString = commentLineFromLoc(code, loc, newline);
76 const auto directive = directiveFromComment(commentLineString);
77 return directive && *directive == Directive::On;
80 DisabledRegions result;
81 auto it = comments.begin();
82 const auto end = comments.end();
86 it = std::find_if(it, end, isOffDirective);
89 const auto& off = *it;
92 it = std::find_if(it, end, isOnDirective);
97 auto &&on = QQmlJS::SourceLocation(code.size(), 0, 0, 0);
100 formRegion(code, off, std::move(on), newline));
103 const auto& on = *it;
104 result.insert(off.offset, formRegion(code, off, on, newline));
116 const auto words = commentLine.trimmed().split(u' ', Qt::SkipEmptyParts);
117 if (words.size() != 3)
121 if (words.at(0) != commentStartString || words.at(1) != directive)
124 return (words.at(2) == onCmd) ? std::make_optional(Directive::On)
125 : (words.at(2) == offCmd) ? std::make_optional(Directive::Off)