| 1352 | */ |
| 1353 | |
| 1354 | std::size_t String::FindLastWord(const char* string, std::intmax_t start, UInt32 flags) const |
| 1355 | { |
| 1356 | if (!string || !string[0] || m_sharedString->size == 0) |
| 1357 | return npos; |
| 1358 | |
| 1359 | if (start < 0) |
| 1360 | start = std::max<std::size_t>(m_sharedString->size + start, 0); |
| 1361 | |
| 1362 | std::size_t pos = static_cast<std::size_t>(start); |
| 1363 | if (pos >= m_sharedString->size) |
| 1364 | return npos; |
| 1365 | |
| 1366 | ///Algo 2.FindLastWord#1 (Size of the pattern unknown) |
| 1367 | const char* ptr = &m_sharedString->string[pos]; |
| 1368 | |
| 1369 | if (flags & HandleUtf8) |
| 1370 | { |
| 1371 | if (utf8::internal::is_trail(*ptr)) |
| 1372 | utf8::unchecked::prior(ptr); // We ensure to have a pointer pointing to the beginning of the string |
| 1373 | |
| 1374 | utf8::unchecked::iterator<const char*> it(ptr); |
| 1375 | |
| 1376 | if (flags & CaseInsensitive) |
| 1377 | { |
| 1378 | const char* t = string; // utf8(::unchecked)::next affects the iterator on argument |
| 1379 | UInt32 c = Unicode::GetLowercase(utf8::unchecked::next(t)); |
| 1380 | do |
| 1381 | { |
| 1382 | if (Unicode::GetLowercase(*it) == c) |
| 1383 | { |
| 1384 | if (it.base() != m_sharedString->string.get()) |
| 1385 | { |
| 1386 | --it; |
| 1387 | if (!Detail::IsSpace(*it++)) |
| 1388 | continue; |
| 1389 | } |
| 1390 | |
| 1391 | utf8::unchecked::iterator<const char*> p(t); |
| 1392 | utf8::unchecked::iterator<const char*> tIt = it; |
| 1393 | ++tIt; |
| 1394 | |
| 1395 | for (;;) |
| 1396 | { |
| 1397 | if (*p == '\0') |
| 1398 | { |
| 1399 | if (*tIt == '\0' || Detail::IsSpace(*tIt)) |
| 1400 | return it.base() - m_sharedString->string.get(); |
| 1401 | else |
| 1402 | break; |
| 1403 | } |
| 1404 | |
| 1405 | if (tIt.base() > &m_sharedString->string[pos]) |
| 1406 | break; |
| 1407 | |
| 1408 | if (Unicode::GetLowercase(*tIt) != Unicode::GetLowercase(*p)) |
| 1409 | break; |
| 1410 | |
| 1411 | ++p; |
nothing calls this directly
no test coverage detected