Finds in @p str the position of a fitting closing bracket for the opening bracket @p str[@p pos], e.g. ')' for '('. @return the position of a fitting closing bracket or str.size() if not found. @warning This function does not support angle brackets. Use findClosingAngleBracket() for that.
| 230 | /// @return the position of a fitting closing bracket or str.size() if not found. |
| 231 | /// @warning This function does not support angle brackets. Use findClosingAngleBracket() for that. |
| 232 | int findClosingNonAngleBracket(QStringView str, int pos) |
| 233 | { |
| 234 | Q_ASSERT(pos >= 0 && pos < str.size()); |
| 235 | Q_ASSERT(str[pos] == QLatin1Char{'('} || str[pos] == QLatin1Char{'['} || str[pos] == QLatin1Char{'{'}); |
| 236 | |
| 237 | const auto openingBracket = str[pos]; |
| 238 | const auto closingBracket = fittingClosingNonAngleBracket(openingBracket); |
| 239 | |
| 240 | int depth = 1; |
| 241 | |
| 242 | for (++pos; pos < str.size(); ++pos) { |
| 243 | if (str[pos] == openingBracket) { |
| 244 | ++depth; |
| 245 | } else if (str[pos] == closingBracket) { |
| 246 | if (--depth == 0) { |
| 247 | return pos; |
| 248 | } |
| 249 | } else { |
| 250 | pos = trySkipStringOrCharLiteralOrComment(str, pos); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | Q_ASSERT(depth > 0); |
| 255 | return str.size(); |
| 256 | } |
| 257 | |
| 258 | /// Finds in @p str the position of a fitting closing angle bracket for the opening angle bracket @p str[@p pos] == '<'. |
| 259 | /// @return the position of a fitting closing bracket or str.size() if not found. |
no test coverage detected