Source File
core.go
Belonging Package
vendor/golang.org/x/text/unicode/bidi
package bidi
import
type level int8
const implicitLevel level = -1
type paragraph struct {
initialTypes []Class
pairTypes []bracketType // paired Bracket types for paragraph
pairValues []rune // rune for opening bracket or pbOpen and pbClose; 0 for pbNone
embeddingLevel level // default: = implicitLevel;
func ( []Class, []bracketType, []rune, level) *paragraph {
validateTypes()
validatePbTypes()
validatePbValues(, )
validateParagraphEmbeddingLevel()
:= ¶graph{
initialTypes: append([]Class(nil), ...),
embeddingLevel: ,
pairTypes: ,
pairValues: ,
resultTypes: append([]Class(nil), ...),
}
.run()
return
}
func ( *paragraph) () int { return len(.initialTypes) }
func ( *paragraph) () {
.determineMatchingIsolates()
if .embeddingLevel == implicitLevel {
.embeddingLevel = .determineParagraphEmbeddingLevel(0, .Len())
}
.resultLevels = make([]level, .Len())
setLevels(.resultLevels, .embeddingLevel)
.applyLevelsAndTypes()
}
func ( *paragraph) () {
.matchingPDI = make([]int, .Len())
.matchingIsolateInitiator = make([]int, .Len())
for := range .matchingIsolateInitiator {
.matchingIsolateInitiator[] = -1
}
for := range .matchingPDI {
.matchingPDI[] = -1
if := .resultTypes[]; .in(LRI, RLI, FSI) {
:= 1
for := + 1; < .Len(); ++ {
if := .resultTypes[]; .in(LRI, RLI, FSI) {
++
} else if == PDI {
if --; == 0 {
.matchingPDI[] =
.matchingIsolateInitiator[] =
break
}
}
}
if .matchingPDI[] == -1 {
.matchingPDI[] = .Len()
}
}
}
}
func ( *paragraph) (, int) level {
var Class = unknownClass
switch {
type directionalStatusStack struct {
stackCounter int
embeddingLevelStack [maxDepth + 1]level
overrideStatusStack [maxDepth + 1]Class
isolateStatusStack [maxDepth + 1]bool
}
func ( *directionalStatusStack) () { .stackCounter = 0 }
func ( *directionalStatusStack) () { .stackCounter-- }
func ( *directionalStatusStack) () int { return .stackCounter }
func ( *directionalStatusStack) ( level, Class, bool) {
.embeddingLevelStack[.stackCounter] =
.overrideStatusStack[.stackCounter] =
.isolateStatusStack[.stackCounter] =
.stackCounter++
}
func ( *directionalStatusStack) () level {
return .embeddingLevelStack[.stackCounter-1]
}
func ( *directionalStatusStack) () Class {
return .overrideStatusStack[.stackCounter-1]
}
func ( *directionalStatusStack) () bool {
return .isolateStatusStack[.stackCounter-1]
}
func ( *paragraph) () {
var directionalStatusStack
var , , int
.push(.embeddingLevel, ON, false)
if == FSI {
= (.determineParagraphEmbeddingLevel(+1, .matchingPDI[]) == 1)
}
if {
.resultLevels[] = .lastEmbeddingLevel()
if .lastDirectionalOverrideStatus() != ON {
.resultTypes[] = .lastDirectionalOverrideStatus()
}
}
var level
= (.lastEmbeddingLevel() + 1) | 1
= (.lastEmbeddingLevel() + 2) &^ 1
}
if <= maxDepth && == 0 && == 0 {
if {
++
if ! {
.resultLevels[] =
}
if {
++
} else { // !isIsolate
if == 0 {
++
}
}
}
case PDI:
if > 0 {
--
} else {
= 0
for !.lastDirectionalIsolateStatus() {
.pop()
}
.pop()
--
}
.resultLevels[] = .lastEmbeddingLevel()
.resultLevels[] = .lastEmbeddingLevel()
} else if > 0 {
--
} else if !.lastDirectionalIsolateStatus() && .depth() >= 2 {
.pop()
}
.empty()
= 0
= 0
= 0
.resultLevels[] = .embeddingLevel
default:
.resultLevels[] = .lastEmbeddingLevel()
if .lastDirectionalOverrideStatus() != ON {
.resultTypes[] = .lastDirectionalOverrideStatus()
}
}
}
}
type isolatingRunSequence struct {
p *paragraph
indexes []int // indexes to the original string
types []Class // type of each character using the index
resolvedLevels []level // resolved levels after application of rules
level level
sos, eos Class
}
func ( *isolatingRunSequence) () int { return len(.indexes) }
func (, level) level {
if > {
return
}
return
}
func ( *paragraph) ( []int) *isolatingRunSequence {
:= len()
:= make([]Class, )
for , := range {
[] = .resultTypes[]
}
:= [0] - 1
for >= 0 && isRemovedByX9(.initialTypes[]) {
--
}
:= .embeddingLevel
if >= 0 {
= .resultLevels[]
}
var level
:= [-1]
if .in(LRI, RLI, FSI) {
= .embeddingLevel
:= [-1] + 1
for ; < .Len() && isRemovedByX9(.initialTypes[]); ++ {
}
= .embeddingLevel
if < .Len() {
= .resultLevels[]
}
}
:= .resultLevels[[0]]
return &isolatingRunSequence{
p: ,
indexes: ,
types: ,
level: ,
sos: typeForLevel(maxLevel(, )),
eos: typeForLevel(maxLevel(, )),
}
}
func ( *isolatingRunSequence) () {
for , := range .types {
:=
:= .findRunLimit(, ET)
=
}
}
for , := range .types {
func ( *isolatingRunSequence) () {
var , Class
=
= typeForLevel(.level)
}
setTypes(.types[:], )
func ( *isolatingRunSequence) () {
.assertOnly(L, R, EN, AN)
.resolvedLevels = make([]level, len(.types))
setLevels(.resolvedLevels, .level)
if (.level & 1) == 0 { // even level
} else if == R {
.resolvedLevels[] += 1
} else { // t == AN || t == EN
.resolvedLevels[] += 2
}
}
} else { // odd level
} else { // t == L || t == AN || t == EN
.resolvedLevels[] += 1
}
}
}
}
func ( *isolatingRunSequence) () {
for , := range .indexes {
.p.resultTypes[] = .types[]
.p.resultLevels[] = .resolvedLevels[]
}
}
func ( *paragraph) () [][]int {
:= []int{}
:= [][]int{}
:= implicitLevel
for := range .initialTypes {
if !isRemovedByX9(.initialTypes[]) {
= .resultLevels[]
}
= append(, )
}
func ( *paragraph) () []*isolatingRunSequence {
:= .determineLevelRuns()
:= make([]int, .Len())
for , := range {
for , := range {
[] =
}
}
:= []*isolatingRunSequence{}
var []int
for , := range {
:= [0]
if .initialTypes[] != PDI || .matchingIsolateInitiator[] == -1 {
= append(, ...)
:= [len()-1]
:= .initialTypes[]
if .in(LRI, RLI, FSI) && .matchingPDI[] != .Len() {
= [[.matchingPDI[]]]
} else {
break
}
}
= append(, .isolatingRunSequence())
}
}
return
}
func ( *paragraph) () {
for , := range .initialTypes {
if .in(LRE, RLE, LRO, RLO, PDF, BN) {
.resultTypes[] =
.resultLevels[] = -1
}
if .resultLevels[0] == -1 {
.resultLevels[0] = .embeddingLevel
}
for := 1; < len(.initialTypes); ++ {
if .resultLevels[] == -1 {
.resultLevels[] = .resultLevels[-1]
}
}
validateLineBreaks(, .Len())
:= append([]level(nil), .resultLevels...)
for , := range .initialTypes {
[] = .embeddingLevel
for := - 1; >= 0; -- {
if isWhitespace(.initialTypes[]) { // including format codes
[] = .embeddingLevel
} else {
break
}
}
}
}
:= 0
for , := range {
for := - 1; >= ; -- {
if isWhitespace(.initialTypes[]) { // including format codes
[] = .embeddingLevel
} else {
break
}
}
=
}
return
}
func ( *paragraph) ( []int) []int {
validateLineBreaks(, .Len())
return computeMultilineReordering(.getLevels(), )
}
for := range {
[] =
}
:=
:= + 1
for < len() && [] >= {
++
}
for , := , -1; < ; , = +1, -1 {
[], [] = [], []
=
}
}
}
return
}
func ( []Class) {
if len() == 0 {
log.Panic("types is null")
}
for , := range [:len()-1] {
if == B {
log.Panicf("B type before end of paragraph at index: %d", )
}
}
}
func ( level) {
if != implicitLevel &&
!= 0 &&
!= 1 {
log.Panicf("illegal paragraph embedding level: %d", )
}
}
func ( []int, int) {
:= 0
for , := range {
if <= {
log.Panicf("bad linebreak: %d at index: %d", , )
}
=
}
if != {
log.Panicf("last linebreak was %d, want %d", , )
}
}
func ( []bracketType) {
if len() == 0 {
log.Panic("pairTypes is null")
}
for , := range {
switch {
case bpNone, bpOpen, bpClose:
default:
log.Panicf("illegal pairType value at %d: %v", , [])
}
}
}
func ( []rune, []bracketType) {
if == nil {
log.Panic("pairValues is null")
}
if len() != len() {
log.Panic("pairTypes is different length from pairValues")
}
![]() |
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. |