nat_lex_byte_cmp

Function nat_lex_byte_cmp 

Source
pub fn nat_lex_byte_cmp(a: &[u8], b: &[u8]) -> Ordering
Expand 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:

  1. It iterates through bytes.
  2. 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.
  3. Non-digit bytes are compared lexicographically.
  4. Assumes ASCII encoding for digits and case handling. Non-ASCII bytes are compared bytewise.
  5. 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.