@@ -3,24 +3,28 @@ Copyright © 2024-2025 François G. Dorais. All rights reserved.
33Released under Apache 2.0 license as described in the file LICENSE.
44-/
55
6- import UnicodeBasic.CharacterDatabase
7- import UnicodeBasic.Hangul
8- import UnicodeBasic.Types
6+ module
7+
8+ import all UnicodeBasic.CharacterDatabase
9+ import all UnicodeBasic.Hangul
10+ import all UnicodeBasic.Types
11+
12+ public import UnicodeBasic.Types
913
1014namespace Unicode
1115
1216namespace CLib
1317
1418@[extern " unicode_case_lookup" ]
15- protected opaque lookupCase (c : UInt32) : UInt64
19+ public protected opaque lookupCase (c : UInt32) : UInt64
1620
1721protected abbrev oUpper : UInt64 := 0x100000000
1822protected abbrev oLower : UInt64 := 0x200000000
1923protected abbrev oAlpha : UInt64 := 0x400000000
2024protected abbrev oMath : UInt64 := 0x800000000
2125
2226@[extern " unicode_prop_lookup" ]
23- protected opaque lookupProp (c : UInt32) : UInt64
27+ public protected opaque lookupProp (c : UInt32) : UInt64
2428
2529end CLib
2630
@@ -69,7 +73,7 @@ private def parsePropTable (s : String) : Thunk <| Array (UInt32 × UInt32) := I
6973/-- Get bidirectional class using lookup table
7074
7175 Unicode property: `Bidi_Class` -/
72- def lookupBidiClass (c : UInt32) : BidiClass :=
76+ public def lookupBidiClass (c : UInt32) : BidiClass :=
7377 let table := table.get
7478 if c < table[0 ]!.1 then .BN else
7579 match table[find c (fun i => table[i]!.1 ) 0 table.size.toUSize]! with
8286/-- Get canonical combining class using lookup table
8387
8488 Unicode property: `Canonical_Combining_Class` -/
85- def lookupCanonicalCombiningClass (c : UInt32) : Nat :=
89+ public def lookupCanonicalCombiningClass (c : UInt32) : Nat :=
8690 let t := table.get
8791 if c < t[0 ]!.1 then 0 else
8892 match t[find c (fun i => t[i]!.1 ) 0 t.size.toUSize]! with
97101 Unicode properties:
98102 `Decomposition_Mapping`
99103 `Decomposition_Type=Canonical` -/
100- def lookupCanonicalDecompositionMapping (c : UInt32) : List UInt32 :=
104+ public def lookupCanonicalDecompositionMapping (c : UInt32) : List UInt32 :=
101105 -- Hangul syllables
102106 if Hangul.Syllable.base ≤ c && c ≤ Hangul.Syllable.last then
103107 let s := Hangul.getSyllable! c
@@ -120,7 +124,7 @@ where
120124 `Simple_Lowercase_Mapping`
121125 `Simple_Uppercase_Mapping`
122126 `Simple_Titlecase_Mapping` -/
123- def lookupCaseMapping (c : UInt32) : UInt32 × UInt32 × UInt32 :=
127+ public def lookupCaseMapping (c : UInt32) : UInt32 × UInt32 × UInt32 :=
124128 let v : UInt64 := CLib.lookupCase c
125129 if v == 0 then (c, c, c) else
126130 let cu : UInt32 := v.toUInt32 &&& 0x001FFFFF
@@ -133,7 +137,7 @@ def lookupCaseMapping (c : UInt32) : UInt32 × UInt32 × UInt32 :=
133137 Unicode properties:
134138 `Decomposition_Mapping`
135139 `Decomposition_Type` -/
136- def lookupDecompositionMapping? (c : UInt32) : Option DecompositionMapping :=
140+ public def lookupDecompositionMapping ? (c : UInt32) : Option DecompositionMapping :=
137141 -- Hangul syllables
138142 if Hangul.Syllable.base ≤ c && c ≤ Hangul.Syllable.last then
139143 let s := Hangul.getSyllable! c
@@ -178,12 +182,12 @@ where
178182
179183 Unicode property: `General_Category` -/
180184@[inline]
181- def lookupGC (c : UInt32) : GC := CLib.lookupProp c |>.toUInt32
185+ public def lookupGC (c : UInt32) : GC := CLib.lookupProp c |>.toUInt32
182186
183187/-- Get name of a code point using lookup table
184188
185189 Unicode property: `Name` -/
186- def lookupName (c : UInt32) : String :=
190+ public def lookupName (c : UInt32) : String :=
187191 let table := table.get
188192 if c < table[0 ]!.1 then unreachable! else
189193 match table[find c (fun i => table[i]!.1 ) 0 table.size.toUSize]! with
@@ -235,7 +239,7 @@ where
235239 Unicode properties:
236240 `Numeric_Type`
237241 `Numeric_Value` -/
238- def lookupNumericValue (c : UInt32) : Option NumericType :=
242+ public def lookupNumericValue (c : UInt32) : Option NumericType :=
239243 let table := table.get
240244 if c < table[0 ]!.1 then none else
241245 match table[find c (fun i => table[i]!.1 ) 0 table.size.toUSize]! with
@@ -292,15 +296,16 @@ def lookupOther (c : UInt32) : UInt32 :=
292296
293297 Unicode property: `Alphabetic` -/
294298@[inline]
295- def lookupAlphabetic (c : UInt32) : Bool :=
299+ public def lookupAlphabetic (c : UInt32) : Bool :=
296300 let m := CLib.oAlpha ||| (GC.L ||| GC.Nl).toUInt64
297301 CLib.lookupProp c &&& m != 0
298302
299303/-- Check if code point is bidi mirrored using lookup table
300304
301305 Unicode property: `Bidi_Mirrored`
302306-/
303- def lookupBidiMirrored (c : UInt32) : Bool :=
307+ @[inline]
308+ public def lookupBidiMirrored (c : UInt32) : Bool :=
304309 let table := table.get
305310 if c < table[0 ]!.1 then false else
306311 match table[find c (fun i => table[i]!.1 ) 0 table.size.toUSize]! with
@@ -313,15 +318,15 @@ where
313318
314319 Unicode property: `Cased` -/
315320@[inline]
316- def lookupCased (c : UInt32 ) : Bool :=
321+ public def lookupCased (c : UInt32 ) : Bool :=
317322 let m := CLib.oUpper ||| CLib.oLower ||| GC.LC.toUInt64
318323 CLib.lookupProp c &&& m != 0
319324
320325/-- Check if code point is a lowercase letter using lookup table
321326
322327 Unicode property: `Lowercase` -/
323328@[inline]
324- def lookupLowercase (c : UInt32) : Bool :=
329+ public def lookupLowercase (c : UInt32) : Bool :=
325330 let m := CLib.oLower ||| GC.Ll.toUInt64
326331 CLib.lookupProp c &&& m != 0
327332
@@ -330,35 +335,33 @@ def lookupLowercase (c : UInt32) : Bool :=
330335
331336 Unicode property: `Math` -/
332337@[inline]
333- def lookupMath (c : UInt32) : Bool :=
338+ public def lookupMath (c : UInt32) : Bool :=
334339 let m := CLib.oMath ||| GC.Sm.toUInt64
335340 CLib.lookupProp c &&& m != 0
336341
337342/-- Check if code point is a titlecase letter using lookup table
338343
339344 Unicode property: `Titlecase` -/
340345@[inline]
341- def lookupTitlecase (c : UInt32) : Bool :=
346+ public def lookupTitlecase (c : UInt32) : Bool :=
342347 lookupGC c == GC.Lt
343348
344349/-- Check if code point is a uppercase letter using lookup table
345350
346351 Unicode property: `Uppercase` -/
347352@[inline]
348- def lookupUppercase (c : UInt32) : Bool :=
353+ public def lookupUppercase (c : UInt32) : Bool :=
349354 let m := CLib.oUpper ||| GC.Lu.toUInt64
350355 CLib.lookupProp c &&& m != 0
351356
352357/-- Check if code point is a white space character using lookup table
353358
354359 Unicode property: `White_Space` -/
355- def lookupWhiteSpace (c : UInt32) : Bool :=
360+ public def lookupWhiteSpace (c : UInt32) : Bool :=
356361 let table := table.get
357362 if c < table[0 ]!.1 then false else
358363 match table[find c (fun i => table[i]!.1 ) 0 table.size.toUSize]! with
359364 | (_, v) => c ≤ v
360365where
361366 str : String := include_str " ../data/table/White_Space.txt"
362367 table : Thunk <| Array (UInt32 × UInt32) := parsePropTable str
363-
364- end Unicode
0 commit comments