blob: ff607fbe06686fdbefa7b600d112ff7a12d54779 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import utils/charcategory
import utils/luwrap
import utils/strwidth
type BreakCategory* = enum
bcAlpha, bcSpace, bcSymbol, bcHan, bcHiragana, bcKatakana, bcHangul
func isDigitAscii(u: uint32): bool =
return u < 128 and char(u) in AsciiDigit
proc breaksWord*(ctx: LUContext; u: uint32): bool =
return not u.isDigitAscii() and u.width() != 0 and not ctx.isAlphaLU(u)
proc breaksViWordCat*(ctx: LUContext; u: uint32): BreakCategory =
if u < 0x80: # ASCII
let c = char(u)
if c in AsciiAlphaNumeric + {'_'}:
return bcAlpha
elif c in AsciiWhitespace:
return bcSpace
elif ctx.isWhiteSpaceLU(u):
return bcSpace
elif ctx.isAlphaLU(u):
if ctx.isHiragana(u):
return bcHiragana
elif ctx.isKatakana(u):
return bcKatakana
elif ctx.isHangul(u):
return bcHangul
elif ctx.isHan(u):
return bcHan
return bcAlpha
return bcSymbol
proc breaksWordCat*(ctx: LUContext; u: uint32): BreakCategory =
if not ctx.breaksWord(u):
return bcAlpha
return bcSpace
proc breaksBigWordCat*(ctx: LUContext; u: uint32): BreakCategory =
if not ctx.isWhiteSpaceLU(u):
return bcAlpha
return bcSpace
|