* @brief Compares two String objects lexicographically. * * This function compares two String objects lexicographically. * If either string is NULL, the NULL string is considered less than the non-NULL string. * If both are NULL, they are considered equal. * * @param str1 The first String object to compare. Can be NULL. * @param str2 The second String object to compare. Can be NULL. *
| 590 | * - A value greater than 0 if str1 is greater than str2 |
| 591 | */ |
| 592 | int string_compare(const String* str1, const String* str2) { |
| 593 | STRING_LOG("[string_compare]: Comparing two strings.\n"); |
| 594 | |
| 595 | if (str1 == NULL || str2 == NULL) { |
| 596 | if (str1 == str2) { |
| 597 | STRING_LOG("[string_compare]: Both strings are NULL. Returning 0 (equal).\n"); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | STRING_LOG("[string_compare]: One or both String objects are NULL.\n"); |
| 602 | return (str1 == NULL) ? -1 : 1; |
| 603 | } |
| 604 | int result = strcmp(str1->dataStr, str2->dataStr); |
| 605 | STRING_LOG("[string_compare]: Comparison result is %d.\n", result); |
| 606 | |
| 607 | return result; |
| 608 | } |
| 609 | |
| 610 | |
| 611 | /** |
no outgoing calls
no test coverage detected