Source File
composition.go
Belonging Package
golang.org/x/text/unicode/norm
package norm
import
const (
maxBufferSize = maxNonStarters + 2
maxNFCExpansion = 3 // NFC(0x1D160)
maxNFKCExpansion = 18 // NFKC(0xFDFA)
maxByteBufferSize = utf8.UTFMax * maxBufferSize // 128
)
type streamSafe uint8
func ( *streamSafe) ( Properties) {
* = streamSafe(.nTrailingNonStarters())
}
func ( *streamSafe) ( Properties) ssState {
if * > maxNonStarters {
panic("streamSafe was not reset")
}
:= .nLeadingNonStarters()
if * += streamSafe(); * > maxNonStarters {
* = 0
return ssOverflow
if == 0 {
* = streamSafe(.nTrailingNonStarters())
return ssStarter
}
return ssSuccess
}
func ( *streamSafe) ( Properties) ssState {
if * > maxNonStarters {
panic("streamSafe was not reset")
}
:= * + streamSafe(.nTrailingNonStarters())
if > maxNonStarters {
return ssOverflow
}
* =
if .nLeadingNonStarters() == 0 {
return ssStarter
}
return ssSuccess
}
func ( streamSafe) () bool {
return == maxNonStarters
}
const GraphemeJoiner = "\u034F"
type reorderBuffer struct {
rune [maxBufferSize]Properties // Per character info.
byte [maxByteBufferSize]byte // UTF-8 buffer. Referenced by runeInfo.pos.
nbyte uint8 // Number or bytes.
ss streamSafe // For limiting length of non-starter sequence.
nrune int // Number of runeInfos.
f formInfo
src input
nsrc int
tmpBytes input
out []byte
flushF func(*reorderBuffer) bool
}
func ( *reorderBuffer) ( Form, []byte) {
.f = *formTable[]
.src.setBytes()
.nsrc = len()
.ss = 0
}
func ( *reorderBuffer) ( Form, string) {
.f = *formTable[]
.src.setString()
.nsrc = len()
.ss = 0
}
func ( *reorderBuffer) ( []byte, func(*reorderBuffer) bool) {
.out =
.flushF =
}
func ( *reorderBuffer) () {
.nrune = 0
.nbyte = 0
}
func ( *reorderBuffer) () bool {
if .f.composing {
.compose()
}
:= .flushF()
.reset()
return
}
func ( *reorderBuffer) ( Properties) {
:= .nrune
:= .rune[:]
:= .ccc
func ( *reorderBuffer) ( input, int, Properties) insertErr {
if := .hangul(); != 0 {
.decomposeHangul()
return iSuccess
}
if .hasDecomposition() {
return .insertDecomposed(.Decomposition())
}
.insertSingle(, , )
return iSuccess
}
func ( *reorderBuffer) ( input, int, Properties) {
if := .hangul(); != 0 {
.decomposeHangul()
}
.insertDecomposed(.Decomposition())
} else {
.insertSingle(, , )
}
}
func ( *reorderBuffer) ( []byte) insertErr {
func ( *reorderBuffer) ( input, int, Properties) {
.copySlice(.byte[.nbyte:], , +int(.size))
.insertOrdered()
}
func ( *reorderBuffer) () {
.insertSingle(input{str: GraphemeJoiner}, 0, Properties{size: uint8(len(GraphemeJoiner))})
}
func ( *reorderBuffer) ( int, rune) {
:= .rune[].pos
:= utf8.EncodeRune(.byte[:], rune())
.rune[] = Properties{pos: , size: uint8()}
}
func ( *reorderBuffer) ( int) rune {
:= .rune[]
, := utf8.DecodeRune(.byte[.pos : .pos+.size])
return
}
const (
hangulBase = 0xAC00 // UTF-8(hangulBase) -> EA B0 80
hangulBase0 = 0xEA
hangulBase1 = 0xB0
hangulBase2 = 0x80
hangulEnd = hangulBase + jamoLVTCount // UTF-8(0xD7A4) -> ED 9E A4
hangulEnd0 = 0xED
hangulEnd1 = 0x9E
hangulEnd2 = 0xA4
jamoLBase = 0x1100 // UTF-8(jamoLBase) -> E1 84 00
jamoLBase0 = 0xE1
jamoLBase1 = 0x84
jamoLEnd = 0x1113
jamoVBase = 0x1161
jamoVEnd = 0x1176
jamoTBase = 0x11A7
jamoTEnd = 0x11C3
jamoTCount = 28
jamoVCount = 21
jamoVTCount = 21 * 28
jamoLVTCount = 19 * 21 * 28
)
const hangulUTF8Size = 3
func ( []byte) bool {
if len() < hangulUTF8Size {
return false
}
:= [0]
if < hangulBase0 {
return false
}
:= [1]
switch {
case == hangulBase0:
return >= hangulBase1
case < hangulEnd0:
return true
case > hangulEnd0:
return false
case < hangulEnd1:
return true
}
return == hangulEnd1 && [2] < hangulEnd2
}
func ( string) bool {
if len() < hangulUTF8Size {
return false
}
:= [0]
if < hangulBase0 {
return false
}
:= [1]
switch {
case == hangulBase0:
return >= hangulBase1
case < hangulEnd0:
return true
case > hangulEnd0:
return false
case < hangulEnd1:
return true
}
return == hangulEnd1 && [2] < hangulEnd2
}
return [0] == jamoLBase0 && ([1]&0xFC) == jamoLBase1
}
func ( []byte) bool {
, := utf8.DecodeRune()
-= hangulBase
return < jamoLVTCount && %jamoTCount == 0
}
func ( []byte, rune) int {
const = 3
-= hangulBase
:= % jamoTCount
/= jamoTCount
utf8.EncodeRune(, jamoLBase+/jamoVCount)
utf8.EncodeRune([:], jamoVBase+%jamoVCount)
if != 0 {
utf8.EncodeRune([2*:], jamoTBase+)
return 3 *
}
return 2 *
}
func ( *reorderBuffer) ( rune) {
-= hangulBase
:= % jamoTCount
/= jamoTCount
.appendRune(jamoLBase + /jamoVCount)
.appendRune(jamoVBase + %jamoVCount)
if != 0 {
.appendRune(jamoTBase + )
}
}
.assignRune(, hangulBase+
(-jamoLBase)*jamoVTCount+(-jamoVBase)*jamoTCount)
case hangulBase <= && < hangulEnd &&
jamoTBase < && < jamoTEnd &&
.assignRune(, +-jamoTBase)
default:
[] = []
++
}
}
}
.nrune =
}
.combineHangul(, , )
return
}
if .combinesBackward() {
:= [-1].ccc
:= .ccc
:= false // b[i] blocked by starter or greater or equal CCC?
if == 0 {
= - 1
} else {
= != -1 && >=
}
if ! {
:= combine(.runeAt(), .runeAt())
if != 0 {
.assignRune(, )
continue
}
}
}
[] = []
++
}
.nrune =
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |