The scanner consumed every digit following a backslash as part of an
octal escape. A digit right after an escape was therefore swallowed:
"\0337" (ESC 7) became the single byte 0o337 instead of ESC followed by
"7", and "\0338" (ESC 8) failed to parse and became a NUL byte.
Stop after three digits, as in C and other languages with octal string
escapes. Escapes of up to three digits are read as before.
Co-authored-by: ybai08 <271969568+ybai08@users.noreply.github.com>
naturalCmp parsed digit runs with strconv.Atoi and fell back to a plain
string comparison when parsing failed. Numbers that do not fit in an int
(20 digits or more on 64-bit platforms) were therefore compared
lexicographically, so '10000000000000000000' sorted before '9'. This also
made the comparison non-transitive ('9' < '10' < '10000000000000000000'
< '9'), which slices.SortStableFunc does not support.
Compare the digit runs directly instead: strip leading zeros, compare by
length, then by digits, keeping the existing tie-break on the length of
the original run.
Co-authored-by: ybai08 <271969568+ybai08@users.noreply.github.com>