MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ICUStringContains

Function ICUStringContains

src/string.cpp:466–486  ·  view source on GitHub ↗

* Search if a string is contained in another string using the current locale. * * @param str String to search in. * @param value String to search for. * @param case_insensitive Search case-insensitive. * @return 1 if value was found, 0 if it was not found, or -1 if not supported by the OS. */

Source from the content-addressed store, hash-verified

464 * @return 1 if value was found, 0 if it was not found, or -1 if not supported by the OS.
465 */
466static int ICUStringContains(std::string_view str, std::string_view value, bool case_insensitive)
467{
468 if (_current_collator) {
469 std::unique_ptr<icu::RuleBasedCollator> coll(dynamic_cast<icu::RuleBasedCollator *>(_current_collator->clone()));
470 if (coll) {
471 UErrorCode status = U_ZERO_ERROR;
472 coll->setStrength(case_insensitive ? icu::Collator::SECONDARY : icu::Collator::TERTIARY);
473 coll->setAttribute(UCOL_NUMERIC_COLLATION, UCOL_OFF, status);
474
475 auto u_str = icu::UnicodeString::fromUTF8(icu::StringPiece(str.data(), str.size()));
476 auto u_value = icu::UnicodeString::fromUTF8(icu::StringPiece(value.data(), value.size()));
477 icu::StringSearch u_searcher(u_value, u_str, coll.get(), nullptr, status);
478 if (U_SUCCESS(status)) {
479 auto pos = u_searcher.first(status);
480 if (U_SUCCESS(status)) return pos != USEARCH_DONE ? 1 : 0;
481 }
482 }
483 }
484
485 return -1;
486}
487#endif /* WITH_ICU_I18N */
488
489/**

Callers 2

StrNaturalContainsFunction · 0.85

Calls 4

cloneMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected