Skip to content

Commit 197af14

Browse files
committed
make properties work at ct
1 parent cf65039 commit 197af14

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.7.2
2+
==================
3+
4+
* Make `properties` module work at CT
5+
16
v0.7.1
27
==================
38

src/unicodedb/properties.nim

+32-4
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,38 @@ proc properties*(cp: Rune): UnicodeProps =
195195
## raw data for some of the properties, so one of
196196
## the auxiliary procedures must be used in conjuntion.
197197
assert cp.int <= 0x10FFFF
198-
let
199-
blockOffset = (propsOffsets[cp.int div blockSize]).int * blockSize
200-
idx = propsIndices[blockOffset + cp.int mod blockSize]
201-
result = propsData[idx]
198+
when nimvm:
199+
const N = propsIndices.len
200+
const N2 = N div 4
201+
const t0 = propsIndices[0 ..< N2]
202+
const t1 = propsIndices[N2 ..< 2*N2]
203+
const t2 = propsIndices[2*N2 ..< 3*N2]
204+
const t3 = propsIndices[3*N2 ..< N]
205+
206+
proc getTypeIndex(sub: static[int], ind: int): auto =
207+
when sub == 0: return t0[ind]
208+
elif sub == 1: return t1[ind]
209+
elif sub == 2: return t2[ind]
210+
else: return t3[ind]
211+
let blockOffset = (propsOffsets[cp.int div blockSize]).int * blockSize
212+
block:
213+
let ind = blockOffset + cp.int mod blockSize
214+
let ind2 = ind div N2
215+
let j = ind mod N2
216+
var idx = 0'u8
217+
case ind2
218+
of 0: idx = getTypeIndex(0, j)
219+
of 1: idx = getTypeIndex(1, j)
220+
of 2: idx = getTypeIndex(2, j)
221+
of 3: idx = getTypeIndex(3, j)
222+
else: assert false
223+
result = propsData[idx]
224+
else:
225+
block:
226+
let
227+
blockOffset = (propsOffsets[cp.int div blockSize]).int * blockSize
228+
idx = propsIndices[blockOffset + cp.int mod blockSize]
229+
result = propsData[idx]
202230

203231
proc unicodeCategory*(props: UnicodeProps): UnicodeCategory {.inline.} =
204232
## Return category for a given `UnicodeProps`

src/unicodedb/types.nim

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ proc unicodeTypes*(cp: Rune): int {.inline.} =
5151
of 2: idx = getTypeIndex(2, j)
5252
else: assert false
5353
result = typesData[idx]
54-
5554
else:
5655
block:
5756
let blockOffset = (typesOffsets[cp.int div blockSize]).int * blockSize

tests/tests.nim

+14
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ test "Test some categories":
128128
check unicodeCategory(0x1CF2.Rune) == ctgLo
129129
check unicodeCategory(0xA9BD.Rune) == ctgMn
130130

131+
test "Test some categories at CT":
132+
static:
133+
doAssert unicodeCategory(64110.Rune) == ctgCn
134+
doAssert unicodeCategory(7913.Rune) == ctgLl
135+
doAssert unicodeCategory(0.Rune) == ctgCc
136+
doAssert unicodeCategory(1048576.Rune) == ctgCo
137+
doAssert unicodeCategory(0x860.Rune) == ctgLo
138+
doAssert unicodeCategory(70089.Rune) == ctgMn
139+
doAssert unicodeCategory(72199.Rune) == ctgMn
140+
doAssert unicodeCategory(72200.Rune) == ctgMn
141+
doAssert unicodeCategory(0x166D.Rune) == ctgSo
142+
doAssert unicodeCategory(0x1CF2.Rune) == ctgLo
143+
doAssert unicodeCategory(0xA9BD.Rune) == ctgMn
144+
131145
test "Test bidirectional class":
132146
for cpData in allBidis:
133147
for cp in cpData.cpFirst .. cpData.cpLast:

unicodedb.nimble

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "0.7.1"
3+
version = "0.7.2"
44
author = "Esteban Castro Borsani (@nitely)"
55
description = "Unicode Character Database (UCD) access for Nim"
66
license = "MIT"

0 commit comments

Comments
 (0)