blob: c93d63ec73c8bfd9274865ee237f584d47def784 (
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
44
45
|
import std/unicode
import utils/charcategory
import utils/luwrap
import utils/strwidth
type BreakCategory* = enum
bcAlpha, bcSpace, bcSymbol, bcHan, bcHiragana, bcKatakana, bcHangul
func isDigitAscii(r: Rune): bool =
return uint32(r) < 128 and char(r) in AsciiDigit
proc breaksWord*(ctx: LUContext; r: Rune): bool =
return not r.isDigitAscii() and r.width() != 0 and not ctx.isAlphaLU(r)
proc breaksViWordCat*(ctx: LUContext; r: Rune): BreakCategory =
if int32(r) < 0x80: # ASCII
let c = char(r)
if c in AsciiAlphaNumeric + {'_'}:
return bcAlpha
elif c in AsciiWhitespace:
return bcSpace
elif ctx.isWhiteSpaceLU(r):
return bcSpace
elif ctx.isAlphaLU(r):
if ctx.isHiragana(r):
return bcHiragana
elif ctx.isKatakana(r):
return bcKatakana
elif ctx.isHangul(r):
return bcHangul
elif ctx.isHan(r):
return bcHan
return bcAlpha
return bcSymbol
proc breaksWordCat*(ctx: LUContext; r: Rune): BreakCategory =
if not ctx.breaksWord(r):
return bcAlpha
return bcSpace
proc breaksBigWordCat*(ctx: LUContext; r: Rune): BreakCategory =
if not ctx.isWhiteSpaceLU(r):
return bcAlpha
return bcSpace
|