MCPcopy Create free account
hub / github.com/NazaraEngine/NazaraEngine / Count

Method Count

src/Nazara/Core/String.cpp:354–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352 */
353
354 unsigned int String::Count(char character, std::intmax_t start, UInt32 flags) const
355 {
356 if (character == '\0' || m_sharedString->size == 0)
357 return 0;
358
359 if (start < 0)
360 start = std::max<std::size_t>(m_sharedString->size + start, 0);
361
362 std::size_t pos = static_cast<std::size_t>(start);
363 if (pos >= m_sharedString->size)
364 return 0;
365
366 char* str = &m_sharedString->string[pos];
367 unsigned int count = 0;
368 if (flags & CaseInsensitive)
369 {
370 char character_lower = Detail::ToLower(character);
371 char character_upper = Detail::ToUpper(character);
372 do
373 {
374 if (*str == character_lower || *str == character_upper)
375 count++;
376 }
377 while (*++str);
378 }
379 else
380 {
381 while ((str = std::strchr(str, character)) != nullptr)
382 {
383 count++;
384 str++;
385 }
386 }
387
388 return count;
389 }
390
391 /*!
392 * \brief Counts the number of occurrences in the string

Callers 3

HasAlphaMethod · 0.80
ParseMethod · 0.80
String.cppFile · 0.80

Calls 3

ToLowerFunction · 0.85
ToUpperFunction · 0.85
GetConstBufferMethod · 0.80

Tested by

no test coverage detected