pub fn nat_lex_byte_cmp(a: &[u8], b: &[u8]) -> OrderingExpand description
A hybrid comparator for byte slices:
- If the two slices have the same length, performs a standard lexicographical (byte-wise) comparison.
- Otherwise, attempts a natural order comparison suitable for ASCII text with embedded numbers.
Note: The natural comparison logic here is specialized:
- It iterates through bytes.
- When ASCII digits are found in both slices, it compares the numeric values:
- Leading zeros are skipped.
- Numbers with more significant digits are considered greater.
- If the number of significant digits is the same, compares digit bytes lexicographically.
- Non-digit bytes are compared lexicographically.
- Assumes ASCII encoding for digits and case handling. Non-ASCII bytes are compared bytewise.
- If the custom comparison results in equality up to the length of the shorter slice,
the final result is determined by
a.cmp(b)(effectively comparing remaining bytes or lengths).
§Arguments
a: The first byte slice.b: The second byte slice.
§Returns
An Ordering.