| 60 | } |
| 61 | |
| 62 | bool 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--> |
| 104 | bool isArrowOperator(QStringView str, int pos) |
no test coverage detected