diff options
author | bptato <nincsnevem662@gmail.com> | 2024-09-07 20:23:27 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-09-07 20:23:50 +0200 |
commit | 5a64e3193924c7e503dddb10a99989148b26e922 (patch) | |
tree | 3c328bf3b5dbedbb3b2a1b308906665ca23e192c | |
parent | e88886243f2282e913d44006916397e076a76425 (diff) | |
download | chawan-5a64e3193924c7e503dddb10a99989148b26e922.tar.gz |
Fix 1.6.14 compilation
Wait, why does std fastRuneAt try to decode UCS-32? Hmm...
-rw-r--r-- | src/utils/sandbox.nim | 2 | ||||
-rw-r--r-- | src/utils/strwidth.nim | 30 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/utils/sandbox.nim b/src/utils/sandbox.nim index 6f42f638..1e3558e0 100644 --- a/src/utils/sandbox.nim +++ b/src/utils/sandbox.nim @@ -136,7 +136,7 @@ elif SandboxMode == stLibSeccomp: # # The offending function is _IO_file_doallocate; it doesn't actually # look at errno, so EPERM should work fine. - const err = SCMP_ACT_ERRNO(uint16(EPERM)) + const err = SCMP_ACT_ERRNO(1u16) const fstatList = [ cstring"fstat", "fstat64", diff --git a/src/utils/strwidth.nim b/src/utils/strwidth.nim index 90784890..8c367991 100644 --- a/src/utils/strwidth.nim +++ b/src/utils/strwidth.nim @@ -52,9 +52,37 @@ func width*(s: string; start, len: int): int = fastRuneAt(s, i, r) result += r.twidth(result) +when NimMajor < 2: + template ones(n: untyped): untyped = ((1 shl n)-1) + template fastRuneAt(s: openArray[char]; i: int; result: untyped) = + result = Rune(0xFFFD) + if uint32(s[i]) <= 127: + result = Rune(uint32(s[i])) + elif uint32(s[i]) shr 5 == 0b110: + if i <= s.len - 2: + result = Rune((uint32(s[i]) and (ones(5))) shl 6 or + (uint32(s[i+1]) and ones(6))) + i += 1 + elif uint32(s[i]) shr 4 == 0b1110: + if i <= s.len - 3: + result = Rune((uint32(s[i]) and ones(4)) shl 12 or + (uint32(s[i+1]) and ones(6)) shl 6 or (uint32(s[i+2]) and ones(6))) + i += 2 + elif uint32(s[i]) shr 3 == 0b11110: + if i <= s.len - 4: + result = Rune((uint32(s[i]) and ones(3)) shl 18 or + (uint32(s[i+1]) and ones(6)) shl 12 or + (uint32(s[i+2]) and ones(6)) shl 6 or + (uint32(s[i+3]) and ones(6))) + i += 3 + inc i + func notwidth*(s: openArray[char]): int = result = 0 - for r in s.runes: + var i = 0 + while i < s.len: + var r: Rune + fastRuneAt(s, i, r) result += r.width() func twidth*(s: string; w: int): int = |