package cases
import "golang.org/x/text/cases"
Package cases provides general and language-specific case mappers.
Code:play
Output:Example¶
package main
import (
"fmt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
func main() {
src := []string{
"hello world!",
"i with dot",
"'n ijsberg",
"here comes O'Brian",
}
for _, c := range []cases.Caser{
cases.Lower(language.Und),
cases.Upper(language.Turkish),
cases.Title(language.Dutch),
cases.Title(language.Und, cases.NoLower),
} {
fmt.Println()
for _, s := range src {
fmt.Println(c.String(s))
}
}
}
hello world!
i with dot
'n ijsberg
here comes o'brian
HELLO WORLD!
İ WİTH DOT
'N İJSBERG
HERE COMES O'BRİAN
Hello World!
I With Dot
'n IJsberg
Here Comes O'brian
Hello World!
I With Dot
'N Ijsberg
Here Comes O'Brian
Index ¶
- Constants
- Variables
- type Caser
- func Fold(opts ...Option) Caser
- func Lower(t language.Tag, opts ...Option) Caser
- func Title(t language.Tag, opts ...Option) Caser
- func Upper(t language.Tag, opts ...Option) Caser
- func (c Caser) Bytes(b []byte) []byte
- func (c Caser) Reset()
- func (c Caser) Span(src []byte, atEOF bool) (n int, err error)
- func (c Caser) String(s string) string
- func (c Caser) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)
- type Option
Examples ¶
Constants ¶
const UnicodeVersion = "15.0.0"
UnicodeVersion is the Unicode version from which the tables in this package are derived.
Variables ¶
Types ¶
type Caser ¶
type Caser struct {
// contains filtered or unexported fields
}
A Caser transforms given input to a certain case. It implements transform.Transformer.
A Caser may be stateful and should therefore not be shared between goroutines.
func Fold ¶
Fold returns a Caser that implements Unicode case folding. The returned Caser is stateless and safe to use concurrently by multiple goroutines.
Case folding does not normalize the input and may not preserve a normal form. Use the collate or search package for more convenient and linguistically sound comparisons. Use golang.org/x/text/secure/precis for string comparisons where security aspects are a concern.
func Lower ¶
Lower returns a Caser for language-specific lowercasing.
func Title ¶
Title returns a Caser for language-specific title casing. It uses an approximation of the default Unicode Word Break algorithm.
func Upper ¶
Upper returns a Caser for language-specific uppercasing.
func (Caser) Bytes ¶
Bytes returns a new byte slice with the result of converting b to the case form implemented by c.
func (Caser) Reset ¶
func (c Caser) Reset()
Reset resets the Caser to be reused for new input after a previous call to Transform.
func (Caser) Span ¶
Span implements the transform.SpanningTransformer interface.
func (Caser) String ¶
String returns a string with the result of transforming s to the case form implemented by c.
func (Caser) Transform ¶
Transform implements the transform.Transformer interface and transforms the given input to the case form implemented by c.
type Option ¶
type Option func(o options) options
An Option is used to modify the behavior of a Caser.
var ( // NoLower disables the lowercasing of non-leading letters for a title // caser. NoLower Option = noLower // Compact omits mappings in case folding for characters that would grow the // input. (Unimplemented.) Compact Option = compact )
func HandleFinalSigma ¶
HandleFinalSigma specifies whether the special handling of Greek final sigma should be enabled. Unicode prescribes handling the Greek final sigma for all locales, but standards like IDNA and PRECIS override this default.
Source Files ¶
cases.go context.go fold.go info.go map.go tables15.0.0.go trieval.go
- Version
- v0.22.0 (latest)
- Published
- Feb 4, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 1 day ago –
Tools for package owners.