Removes the next Rune from the StringPiece and stores it in *r. Returns number of bytes removed from sp. Behaves as though there is a terminating NUL at the end of sp. Argument order is backwards from usual Google style but consistent with chartorune.
| 1389 | // Argument order is backwards from usual Google style |
| 1390 | // but consistent with chartorune. |
| 1391 | static int StringPieceToRune(Rune *r, StringPiece *sp, RegexpStatus* status) { |
| 1392 | // fullrune() takes int, not size_t. However, it just looks |
| 1393 | // at the leading byte and treats any length >= 4 the same. |
| 1394 | if (fullrune(sp->data(), static_cast<int>(std::min(size_t{4}, sp->size())))) { |
| 1395 | int n = chartorune(r, sp->data()); |
| 1396 | // Some copies of chartorune have a bug that accepts |
| 1397 | // encodings of values in (10FFFF, 1FFFFF] as valid. |
| 1398 | // Those values break the character class algorithm, |
| 1399 | // which assumes Runemax is the largest rune. |
| 1400 | if (*r > Runemax) { |
| 1401 | n = 1; |
| 1402 | *r = Runeerror; |
| 1403 | } |
| 1404 | if (!(n == 1 && *r == Runeerror)) { // no decoding error |
| 1405 | sp->remove_prefix(n); |
| 1406 | return n; |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | status->set_code(kRegexpBadUTF8); |
| 1411 | status->set_error_arg(StringPiece()); |
| 1412 | return -1; |
| 1413 | } |
| 1414 | |
| 1415 | // Return whether name is valid UTF-8. |
| 1416 | // If not, set status to kRegexpBadUTF8. |
no test coverage detected