diff options
author | bptato <nincsnevem662@gmail.com> | 2024-04-16 15:08:44 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-04-17 23:19:09 +0200 |
commit | 66b9574b165be62e76c7397cf0eaa8d229d42675 (patch) | |
tree | adb8a9719cc70f2b577706aaa4e30bb0d5d629a6 /src/utils/luwrap.nim | |
parent | d86f1939204eee771a30f47e4cbe71fd8d9a4f5f (diff) | |
download | chawan-66b9574b165be62e76c7397cf0eaa8d229d42675.tar.gz |
Update code style
* separate params with ; (semicolon) instead of , (colon) * reduce screaming snake case use * wrap long lines
Diffstat (limited to 'src/utils/luwrap.nim')
-rw-r--r-- | src/utils/luwrap.nim | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/utils/luwrap.nim b/src/utils/luwrap.nim index 41a58701..330a5d1e 100644 --- a/src/utils/luwrap.nim +++ b/src/utils/luwrap.nim @@ -4,23 +4,23 @@ import std/unicode import bindings/libunicode import utils/charcategory -proc passRealloc(opaque: pointer, p: pointer, size: csize_t): pointer - {.cdecl.} = +proc passRealloc(opaque, p: pointer; size: csize_t): pointer {.cdecl.} = return realloc(p, size) -proc mnormalize*(rs: var seq[Rune], form = UNICODE_NFC) = {.cast(noSideEffect).}: - if rs.len == 0: return - var outbuf: ptr uint32 - let p = cast[ptr uint32](unsafeAddr rs[0]) - let out_len = unicode_normalize(addr outbuf, p, cint(rs.len), form, nil, - passRealloc) - if out_len < 0: - raise newException(Defect, "Unicode normalization failed") - if out_len == 0: - return - rs = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) - copyMem(addr rs[0], outbuf, out_len * sizeof(uint32)) - dealloc(outbuf) +proc mnormalize*(rs: var seq[Rune]; form = UNICODE_NFC) = + {.cast(noSideEffect).}: + if rs.len == 0: return + var outbuf: ptr uint32 + let p = cast[ptr uint32](unsafeAddr rs[0]) + let out_len = unicode_normalize(addr outbuf, p, cint(rs.len), form, nil, + passRealloc) + if out_len < 0: + raise newException(Defect, "Unicode normalization failed") + if out_len == 0: + return + rs = cast[seq[Rune]](newSeqUninitialized[uint32](out_len)) + copyMem(addr rs[0], outbuf, out_len * sizeof(uint32)) + dealloc(outbuf) #TODO maybe a utf8 normalization procedure? proc mnormalize*(s: var string) = @@ -30,7 +30,7 @@ proc mnormalize*(s: var string) = rs.mnormalize() s = $rs -func normalize*(rs: seq[Rune], form = UNICODE_NFC): seq[Rune] = +func normalize*(rs: seq[Rune]; form = UNICODE_NFC): seq[Rune] = {.cast(noSideEffect).}: if rs.len == 0: return var outbuf: ptr uint32 |