Skip to content

Commit 636403f

Browse files
str: dedupe StrCmp -- alias the canonical str_compare
StrCmp was its own implementation: ZstrCompare((str)->data, (ostr)->data) -- a NUL-scan that ignores Str's explicit length. str_compare added in commit 88950a9 already does the correct length-aware compare (MemCompare over min(len) + length tiebreaker). Make StrCmp a thin alias so there's one implementation, and Strs carrying embedded NULs compare correctly through both entry points.
1 parent 8067efe commit 636403f

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • Include/Misra/Std/Container/Str

Include/Misra/Std/Container/Str/Ops.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,22 @@ extern "C" {
4646
//
4747

4848
///
49-
/// Compare two Str objects
49+
/// Compare two Str objects lexicographically, length-aware.
5050
///
51-
/// str[in] : First string
52-
/// ostr[in] : Other string
51+
/// Thin alias for `str_compare` above (the generic-callback shape).
52+
/// Both arms are read through `StrBegin` / `StrLen`, so a Str with an
53+
/// embedded NUL still compares correctly -- unlike a `Zstr`-based
54+
/// compare that would stop at the first NUL byte.
5355
///
54-
/// RETURN : +ve or -ve depending on above or below in lexical ordering
55-
/// RETURN : 0 if both are equal
56+
/// str[in] : First string.
57+
/// ostr[in] : Other string.
58+
///
59+
/// SUCCESS : Returns `0` when equal, `<0` when `str < ostr`, `>0` when
60+
/// `str > ostr`. Neither string is modified.
61+
///
62+
/// TAGS: Str, Compare
5663
///
57-
#define StrCmp(str, ostr) ZstrCompare((str)->data, (ostr)->data)
64+
#define StrCmp(str, ostr) str_compare((str), (ostr))
5865

5966
///
6067
/// Compare string with another const char* of specified length

0 commit comments

Comments
 (0)