Source File
map.go
Belonging Package
golang.org/x/text/cases
package cases
import (
)
const maxIgnorable = 30
const supported = "und af az el lt nl tr"
func () {
:= []language.Tag{}
for , := range strings.Split(supported, " ") {
= append(, language.MustParse())
}
matcher = internal.NewInheritanceMatcher()
Supported = language.NewCoverage()
}
var (
matcher *internal.InheritanceMatcher
Supported language.Coverage
upperFunc = []struct {
upper mapFunc
span spanFunc
}{
{nil, nil}, // und
{nil, nil}, // af
{aztrUpper(upper), isUpper}, // az
{elUpper, noSpan}, // el
{ltUpper(upper), noSpan}, // lt
{nil, nil}, // nl
{aztrUpper(upper), isUpper}, // tr
}
undUpper transform.SpanningTransformer = &undUpperCaser{}
undLower transform.SpanningTransformer = &undLowerCaser{}
undLowerIgnoreSigma transform.SpanningTransformer = &undLowerIgnoreSigmaCaser{}
lowerFunc = []mapFunc{
nil, // und
nil, // af
aztrLower, // az
nil, // el
ltLower, // lt
nil, // nl
aztrLower, // tr
}
titleInfos = []struct {
title mapFunc
lower mapFunc
titleSpan spanFunc
rewrite func(*context)
}{
{title, lower, isTitle, nil}, // und
{title, lower, isTitle, afnlRewrite}, // af
{aztrUpper(title), aztrLower, isTitle, nil}, // az
{title, lower, isTitle, nil}, // el
{ltUpper(title), ltLower, noSpan, nil}, // lt
{nlTitle, lower, nlTitleSpan, afnlRewrite}, // nl
{aztrUpper(title), aztrLower, isTitle, nil}, // tr
}
)
func ( language.Tag, options) transform.SpanningTransformer {
, , := matcher.Match()
:= upperFunc[].upper
if == nil {
return undUpper
}
return &simpleCaser{f: , span: upperFunc[].span}
}
func ( language.Tag, options) transform.SpanningTransformer {
, , := matcher.Match()
:= lowerFunc[]
if == nil {
if .ignoreFinalSigma {
return undLowerIgnoreSigma
}
return undLower
}
if .ignoreFinalSigma {
return &simpleCaser{f: , span: isLower}
}
return &lowerCaser{
first: ,
midWord: finalSigma(),
}
}
func ( language.Tag, options) transform.SpanningTransformer {
, , := matcher.Match()
:= &titleInfos[]
:= .lower
if .noLower {
= (*context).copy
} else if !.ignoreFinalSigma {
= finalSigma()
}
return &titleCaser{
title: .title,
lower: ,
titleSpan: .titleSpan,
rewrite: .rewrite,
}
}
func ( *context) bool {
.err = transform.ErrEndOfSpan
return false
}
type undUpperCaser struct{ transform.NopResetter }
type undLowerIgnoreSigmaCaser struct{ transform.NopResetter }
func ( undLowerIgnoreSigmaCaser) (, []byte, bool) (, int, error) {
:= context{dst: , src: , atEOF: }
for .next() && lower(&) {
.checkpoint()
}
return .ret()
}
type undLowerCaser struct{ transform.NopResetter }
func ( undLowerCaser) (, []byte, bool) (, int, error) {
:= context{dst: , src: , atEOF: }
for := true; .next(); {
if {
if .info.isCased() {
if !lower(&) {
break
}
= false
} else if !.copy() {
break
}
} else {
if .info.isNotCasedAndNotCaseIgnorable() {
if !.copy() {
break
}
= true
} else if !.hasPrefix("Σ") {
if !lower(&) {
break
}
} else if !finalSigmaBody(&) {
break
}
}
.checkpoint()
}
return .ret()
}
func ( undLowerCaser) ( []byte, bool) ( int, error) {
:= context{src: , atEOF: }
for .next() && isLower(&) {
.checkpoint()
}
return .retSpan()
}
type lowerCaser struct {
undLowerIgnoreSigmaCaser
context
first, midWord mapFunc
}
func ( *lowerCaser) (, []byte, bool) (, int, error) {
.context = context{dst: , src: , atEOF: }
:= &.context
for := true; .next(); {
if {
if .info.isCased() {
if !.first() {
break
}
= false
} else if !.copy() {
break
}
} else {
if .info.isNotCasedAndNotCaseIgnorable() {
if !.copy() {
break
}
= true
} else if !.midWord() {
break
}
}
.checkpoint()
}
return .ret()
}
type titleCaser struct {
context
if !(.isMidWord && ) {
.checkpoint()
}
if !.next() {
break
}
if && .info.isMid() {
.isMidWord = false
}
}
return .ret()
}
func ( *titleCaser) ( []byte, bool) ( int, error) {
.context = context{src: , atEOF: , isMidWord: .isMidWord}
:= &.context
if !.next() {
return .retSpan()
}
for {
:= .info
if .rewrite != nil {
.rewrite()
}
:= .pDst
.writeString("ς")
:= false
for := 0; < maxIgnorable+1; ++ {
if !.next() {
return false
}
.dst[+1]++ // ς → σ
}
.unreadRune()
return true
, := utf8.DecodeRune()
if <= 0xFF { // See A.6.1
return true
}
.writeBytes([:])
= len([:]) / 2 // Greek modifiers are always of length 2.
}
for ; < maxIgnorable && .next(); ++ {
case 0x0300, // U+0300 COMBINING GRAVE ACCENT
0x0301, // U+0301 COMBINING ACUTE ACCENT
0x0304, // U+0304 COMBINING MACRON
0x0306, // U+0306 COMBINING BREVE
0x0308, // U+0308 COMBINING DIAERESIS
0x0313, // U+0313 COMBINING COMMA ABOVE
0x0314, // U+0314 COMBINING REVERSED COMMA ABOVE
0x0342, // U+0342 COMBINING GREEK PERISPOMENI
.copy()
}
}
}
return == maxIgnorable
}
if [1] == 0xCC && [2] <= 0x91 { // A.2.4.
if !.writeBytes([:1]) {
return false
}
.dst[.pDst-1] += 'a' - 'A' // lower
return .writeString("\u0307") && .writeBytes([1:])
lower()
= 1
} else {
return lower()
}
}
for ; < maxIgnorable && .next(); ++ {
switch .info.cccType() {
case cccZero:
.unreadRune()
return true
case cccAbove:
return .writeString("\u0307") && .copy() // See A.1.
default:
.copy() // See A.1.
}
}
return == maxIgnorable
}
:= 0
for ; < maxIgnorable && .next(); ++ {
switch .info.cccType() {
case cccZero:
.unreadRune()
return true
case cccAbove:
if !.next() {
return false
}
if .dst[] == 'I' && .pDst == +1 && .src[.pSrc] == 0xcc {
:= ""
switch .src[.pSrc+1] {
case 0x80: // U+0300 COMBINING GRAVE ACCENT
= "\u00cc" // U+00CC LATIN CAPITAL LETTER I WITH GRAVE
case 0x81: // U+0301 COMBINING ACUTE ACCENT
= "\u00cd" // U+00CD LATIN CAPITAL LETTER I WITH ACUTE
case 0x83: // U+0303 COMBINING TILDE
= "\u0128" // U+0128 LATIN CAPITAL LETTER I WITH TILDE
case 0x88: // U+0308 COMBINING DIAERESIS
= "\u00cf" // U+00CF LATIN CAPITAL LETTER I WITH DIAERESIS
default:
}
if != "" {
.pDst =
return .writeString()
}
}
}
return .copy()
default:
.copy()
}
}
return == maxIgnorable
}
}
if .src[.pSrc] == 'i' {
return .writeString("İ")
}
return ()
}
}
if .hasPrefix("\u0130") { // İ
return .writeString("i")
}
if .src[.pSrc] != 'I' {
return lower()
}
for ; < maxIgnorable && .next(); ++ {
switch .info.cccType() {
case cccAbove:
if .hasPrefix("\u0307") {
return .writeString("i") && .writeBytes(.src[:.pSrc]) // ignore U+0307
}
= true
break
case cccZero:
.unreadRune()
= true
break
}
}
if == maxIgnorable {
= true
}
return .writeString("ı") && .writeBytes(.src[:.pSrc+.sz]) &&
}
if .src[.pSrc] != 'I' && .src[.pSrc] != 'i' {
return title()
}
if !.writeString("I") || !.next() {
return false
}
if .src[.pSrc] == 'j' || .src[.pSrc] == 'J' {
return .writeString("J")
}
.unreadRune()
return true
}
![]() |
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. |