MCPcopy Create free account
hub / github.com/KDE/kdevelop / isOperator

Function isOperator

kdevplatform/language/duchain/stringhelpers.cpp:62–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62bool isOperator(QStringView str, int pos)
63{
64 Q_ASSERT(pos >= 0 && pos < str.size());
65
66 if (isOperatorSurroundedWithSpaces(str, pos)) {
67 return true;
68 }
69
70 const auto op = QLatin1String("operator");
71 if (pos < op.size()) {
72 return false;
73 }
74
75 const auto c = str[pos];
76 Q_ASSERT(c == QLatin1Char('<') || c == QLatin1Char('>'));
77
78 --pos;
79
80 // note: due to the `pos < op.size()` check above, the below conditionals don't need to check boundaries
81 if (str[pos] == c) {
82 // handle `operator<<` and `operator>>`
83 --pos;
84 } else if (c == QLatin1Char('>') && str[pos] == QLatin1Char('=') && str[pos - 1] == QLatin1Char('<')) {
85 // handle `operator<=>`
86 pos -= 2;
87 }
88
89 // skip spaces, e.g. `operator <`
90 while (pos > 0 && str[pos].isSpace()) {
91 --pos;
92 }
93
94 auto prefix = str.first(pos + 1);
95 if (!prefix.endsWith(op)) {
96 return false;
97 }
98
99 prefix.chop(op.size());
100 return endsWithWordBoundary(prefix);
101}
102
103// check for operator-> but don't get confused by operator-->
104bool isArrowOperator(QStringView str, int pos)

Callers 4

findClosingAngleBracketFunction · 0.85
findOpeningBracketOrEndFunction · 0.85
findCommaOrEndFunction · 0.85

Calls 5

endsWithWordBoundaryFunction · 0.85
endsWithMethod · 0.80
sizeMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected