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

Function MacOSStringContains

src/os/macosx/string_osx.cpp:355–370  ·  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

353 * @return 1 if value was found, 0 if it was not found, or -1 if not supported by the OS.
354 */
355int MacOSStringContains(std::string_view str, std::string_view value, bool case_insensitive)
356{
357 static const bool supported = MacOSVersionIsAtLeast(10, 5, 0);
358 if (!supported) return -1;
359
360 CFStringCompareFlags flags = kCFCompareLocalized | kCFCompareWidthInsensitive;
361 if (case_insensitive) flags |= kCFCompareCaseInsensitive;
362
363 CFAutoRelease<CFStringRef> cf_str(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)str.data(), str.size(), kCFStringEncodingUTF8, false));
364 CFAutoRelease<CFStringRef> cf_value(CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)value.data(), value.size(), kCFStringEncodingUTF8, false));
365
366 /* If any CFString could not be created (e.g., due to UTF8 invalid chars), return OS unsupported functionality */
367 if (cf_str == nullptr || cf_value == nullptr) return -1;
368
369 return CFStringFindWithOptionsAndLocale(cf_str.get(), cf_value.get(), CFRangeMake(0, CFStringGetLength(cf_str.get())), flags, _osx_locale.get(), nullptr) ? 1 : 0;
370}
371
372
373/* virtual */ void OSXStringIterator::SetString(std::string_view s)

Callers 2

StrNaturalContainsFunction · 0.85

Calls 4

MacOSVersionIsAtLeastFunction · 0.85
dataMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected