Fix cmpRunesIgnoreCase on system where sizeof(int) < 4. Fixes #23125. (#23138)

Fixes an issue where importing the `strutils` module, or any other
importing the `strutils` module, ends up with a compile time error on
platforms where ints are less then 32-bit wide.

The fix follows the suggestions made in #23125.

(cherry picked from commit 15c7b76c66)
This commit is contained in:
Gianmarco
2023-12-28 23:41:58 +01:00
committed by narimiran
parent f8d538f4ad
commit 5e22f6ca58

View File

@@ -846,7 +846,12 @@ proc cmpRunesIgnoreCase*(a, b: openArray[char]): int {.rtl, extern: "nuc$1".} =
# slow path:
fastRuneAt(a, i, ar)
fastRuneAt(b, j, br)
result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br))
when sizeof(int) < 4:
const lo = low(int).int32
const hi = high(int).int32
result = clamp(RuneImpl(toLower(ar)) - RuneImpl(toLower(br)), lo, hi).int
else:
result = RuneImpl(toLower(ar)) - RuneImpl(toLower(br))
if result != 0: return
result = a.len - b.len