MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / string_count

Function string_count

string/std_string.c:2708–2737  ·  view source on GitHub ↗

* @brief Counts the occurrences of a substring within a String object. * * This function counts how many times a given substring appears within a String object. If the String object, * its data, or the substring is NULL, the function logs an error and returns 0. * * @param str The String object in which to search for the substring. Must not be NULL. * @param substr The substring to count wit

Source from the content-addressed store, hash-verified

2706 * @param str The String object to convert to title case. Must not be NULL.
2707 */
2708void string_to_title(String* str) {
2709 STRING_LOG("[string_to_title]: Function start.");
2710
2711 if (str == NULL) {
2712 STRING_LOG("[string_to_title]: Error - The String object is NULL.");
2713 return;
2714 }
2715 if (str->dataStr == NULL) {
2716 STRING_LOG("[string_to_title]: Error - The dataStr of String object is NULL.");
2717 return;
2718 }
2719
2720 bool capitalize = true;
2721 for (size_t i = 0; i < str->size; i++) {
2722 char c = str->dataStr[i];
2723 if (!sstr_is_word_char(c)) {
2724 capitalize = true;
2725 }
2726 else if (capitalize) {
2727 str->dataStr[i] = sstr_ascii_toupper(c);
2728 capitalize = false;
2729 }
2730 else {
2731 str->dataStr[i] = sstr_ascii_tolower(c);
2732 }
2733 }
2734
2735 STRING_LOG("[string_to_title]: Successfully converted the string to title case.");
2736 STRING_LOG("[string_to_title]: Function end.");
2737}
2738
2739
2740/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected