@@ -4,67 +4,65 @@ Released under Apache 2.0 license as described in the file LICENSE.
44-/
55module
66
7- public section
8-
97namespace Unicode.Hangul
108
11- def shortNameL : Array String :=
9+ public def shortNameL : Array String :=
1210 #["G" , "GG" , "N" , "D" , "DD" , "R" , "M" , "B" , "BB" , "S" ,
1311 "SS" , "" , "J" , "JJ" , "C" , "K" , "T" , "P" , "H" ]
1412
15- def shortNameV : Array String :=
13+ public def shortNameV : Array String :=
1614 #["A" , "AE" , "YA" , "YAE" , "EO" , "E" , "YEO" , "YE" , "O" , "WA" ,
1715 "WAE" , "OE" , "YO" , "U" , "WEO" , "WE" , "WI" , "YU" , "EU" , "YI" ,
1816 "I" ]
1917
20- def shortNameT : Array String :=
18+ public def shortNameT : Array String :=
2119 #["" , "G" , "GG" , "GS" , "N" , "NJ" , "NH" , "D" , "L" , "LG" ,
2220 "LM" , "LB" , "LS" , "LT" , "LP" , "LH" , "M" , "B" , "BS" , "S" ,
2321 "SS" , "NG" , "J" , "C" , "K" , "T" , "P" , "H" ]
2422
25- abbrev sizeL := shortNameL.size -- 19
26- abbrev sizeV := shortNameV.size -- 21
27- abbrev sizeT := shortNameT.size -- 28
28- abbrev sizeLV := sizeL * sizeV -- 399
29- abbrev sizeVT := sizeV * sizeT -- 588
30- abbrev sizeLVT := sizeL * sizeV * sizeT -- 11172
23+ public abbrev sizeL := shortNameL.size -- 19
24+ public abbrev sizeV := shortNameV.size -- 21
25+ public abbrev sizeT := shortNameT.size -- 28
26+ public abbrev sizeLV := sizeL * sizeV -- 399
27+ public abbrev sizeVT := sizeV * sizeT -- 588
28+ public abbrev sizeLVT := sizeL * sizeV * sizeT -- 11172
3129
32- abbrev baseL : UInt32 := 0x1100
33- abbrev baseV : UInt32 := 0x1161
34- abbrev baseT : UInt32 := 0x11A7
30+ public abbrev baseL : UInt32 := 0x1100
31+ public abbrev baseV : UInt32 := 0x1161
32+ public abbrev baseT : UInt32 := 0x11A7
3533
3634/-- Number of Hangul syllables -/
37- def Syllable.size := sizeLVT
35+ public def Syllable.size := sizeLVT
3836
3937/-- Starting code point for Hangul syllables -/
40- def Syllable.base : UInt32 := 0xAC00
38+ public def Syllable.base : UInt32 := 0xAC00
4139
4240/-- Stopping code point for Hangul syllables -/
43- def Syllable.last : UInt32 := ⟨0xAC00 + Syllable.size - 1 , by decide⟩
41+ public def Syllable.last : UInt32 := ⟨0xAC00 + Syllable.size - 1 , by decide⟩
4442
4543/-- Hangul syllable type -/
46- structure Syllable where
44+ public structure Syllable where
4745 /-- L part of syllable -/
48- toL : Fin sizeL
46+ public toL : Fin sizeL
4947 /-- V part of syllable -/
50- toV : Fin sizeV
48+ public toV : Fin sizeV
5149 /-- T part of syllable (0 means none) -/
52- toT : Fin sizeT := ⟨0 , by decide⟩
50+ public toT : Fin sizeT := ⟨0 , by decide⟩
5351deriving DecidableEq, Repr
5452
55- instance : Inhabited Syllable where
53+ public instance : Inhabited Syllable where
5654 default := ⟨⟨0 , by decide⟩, ⟨0 , by decide⟩, ⟨0 , by decide⟩⟩
5755
5856/-- LV part of syllable -/
59- def Syllable.toLV : Syllable → Fin sizeLV
57+ public def Syllable.toLV : Syllable → Fin sizeLV
6058 | ⟨⟨l, hl⟩, ⟨v, hv⟩, _⟩ =>
6159 have : l * sizeV + v < sizeLV := calc
6260 _ < l * sizeV + sizeV := by apply Nat.add_lt_add_left; exact hv
6361 _ = (l + 1 ) * sizeV := by rw [Nat.add_one_mul]
6462 _ ≤ sizeL * sizeV := by apply Nat.mul_le_mul_right; exact hl
6563 ⟨l * sizeV + v, this⟩
6664
67- def Syllable.index (s : Syllable) : Fin Syllable.size :=
65+ public def Syllable.index (s : Syllable) : Fin Syllable.size :=
6866 match s.toLV, s.toT with
6967 | ⟨lv, hlv⟩, ⟨t, ht⟩ =>
7068 have : lv * sizeT + t < sizeL * sizeV * sizeT := calc
@@ -75,27 +73,27 @@ def Syllable.index (s : Syllable) : Fin Syllable.size :=
7573
7674/-- Get short name for Hangul syllable -/
7775@[inline]
78- def Syllable.getShortName (s : Syllable) : String := shortNameL[s.toL] ++ shortNameV[s.toV] ++ shortNameT[s.toT]
76+ public def Syllable.getShortName (s : Syllable) : String := shortNameL[s.toL] ++ shortNameV[s.toV] ++ shortNameT[s.toT]
7977
8078/-- Get L part character for syllable -/
81- def Syllable.getLChar (s : Syllable) : Char :=
79+ public def Syllable.getLChar (s : Syllable) : Char :=
8280 .ofNat (baseL.toNat + s.toL)
8381
8482/-- Get V part character for syllable -/
85- def Syllable.getVChar (s : Syllable) : Char :=
83+ public def Syllable.getVChar (s : Syllable) : Char :=
8684 .ofNat (baseV.toNat + s.toV)
8785
8886/-- Get LV part character for syllable -/
89- def Syllable.getLVChar (s : Syllable) : Char :=
87+ public def Syllable.getLVChar (s : Syllable) : Char :=
9088 .ofNat (base.toNat + sizeT * s.toLV)
9189
9290/-- Get T part character for syllable -/
93- def Syllable.getTChar? (s : Syllable) : Option Char :=
91+ public def Syllable.getTChar? (s : Syllable) : Option Char :=
9492 if s.toT.val == 0 then none else
9593 return .ofNat (baseT.toNat + s.toT)
9694
9795/-- Get Hangul syllable from code point -/
98- def getSyllable? (code : UInt32) : Option Syllable :=
96+ public def getSyllable? (code : UInt32) : Option Syllable :=
9997 if code < 0xAC00 then none else
10098 let index := (code - 0xAC00 ).toNat
10199 if h : index ≥ Syllable.size then none else
@@ -111,7 +109,7 @@ def getSyllable? (code : UInt32) : Option Syllable :=
111109 some ⟨⟨lpart, lislt⟩, ⟨vpart, vislt⟩, ⟨tpart, tislt⟩⟩
112110
113111@ [inherit_doc getSyllable?]
114- def getSyllable! (code : UInt32) : Syllable :=
112+ public def getSyllable! (code : UInt32) : Syllable :=
115113 match getSyllable? code with
116114 | some s => s
117115 | none => panic! "not a Hangul syllable"
0 commit comments