package runes
Import Path
golang.org/x/text/runes (on go.dev)
Dependency Relation
imports 3 packages, and imported by 2 packages
Code Examples
package main
import (
"fmt"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/width"
)
func main() {
// Widen everything but ASCII.
isASCII := func(r rune) bool { return r <= unicode.MaxASCII }
t := runes.If(runes.Predicate(isASCII), nil, width.Widen)
s, _, _ := transform.String(t, "アルアノリウ tech / 中國 / 5₩")
fmt.Println(s)
}
package main
import (
"fmt"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/width"
)
func main() {
// Convert Latin characters to their canonical form, while keeping other
// width distinctions.
t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
s, _, _ := transform.String(t, "アルアノリウ tech / アルアノリウ tech")
fmt.Println(s)
}
package main
import (
"fmt"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
)
func main() {
replaceHyphens := runes.Map(func(r rune) rune {
if unicode.Is(unicode.Hyphen, r) {
return '|'
}
return r
})
s, _, _ := transform.String(replaceHyphens, "a-b‐c⸗d﹣e")
fmt.Println(s)
}
package main
import (
"fmt"
"unicode"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
)
func main() {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
s, _, _ := transform.String(t, "résumé")
fmt.Println(s)
}
Package-Level Type Names (total 2)
A Set is a collection of runes.
Contains returns true if r is contained in the set.
*github.com/jcmturner/gokrb5/v8/types.PADataSequence
func In(rt *unicode.RangeTable) Set
func NotIn(rt *unicode.RangeTable) Set
func Predicate(f func(rune) bool) Set
func golang.org/x/text/secure/precis.(*Profile).Allowed() Set
func If(s Set, tIn, tNotIn transform.Transformer) Transformer
func Remove(s Set) Transformer
func golang.org/x/text/secure/precis.Disallow(set Set) precis.Option
func golang.org/x/text/secure/precis.NewRestrictedProfile(parent *precis.Profile, disallow Set) *precis.Profile
Transformer implements the transform.Transformer interface.
Bytes returns a new byte slice with the result of converting b using t. It
calls Reset on t. It returns nil if any error was found. This can only happen
if an error-producing Transformer is passed to If.
( Transformer) Reset()
( Transformer) Span(b []byte, atEOF bool) (n int, err error)
String returns a string with the result of converting s using t. It calls
Reset on t. It returns the empty string if any error was found. This can only
happen if an error-producing Transformer is passed to If.
( Transformer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error)
Transformer : golang.org/x/text/transform.SpanningTransformer
Transformer : golang.org/x/text/transform.Transformer
Transformer : vendor/golang.org/x/text/transform.SpanningTransformer
Transformer : vendor/golang.org/x/text/transform.Transformer
func If(s Set, tIn, tNotIn transform.Transformer) Transformer
func Map(mapping func(rune) rune) Transformer
func Remove(s Set) Transformer
func ReplaceIllFormed() Transformer
Package-Level Functions (total 7)
If returns a transformer that applies tIn to consecutive runes for which
s.Contains(r) and tNotIn to consecutive runes for which !s.Contains(r). Reset
is called on tIn and tNotIn at the start of each run. A Nop transformer will
substitute a nil value passed to tIn or tNotIn. Invalid UTF-8 is translated
to RuneError to determine which transformer to apply, but is passed as is to
the respective transformer.
In creates a Set with a Contains method that returns true for all runes in
the given RangeTable.
Map returns a Transformer that maps the runes in the input using the given
mapping. Illegal bytes in the input are converted to utf8.RuneError before
being passed to the mapping func.
NotIn creates a Set with a Contains method that returns true for all runes not
in the given RangeTable.
Predicate creates a Set with a Contains method that returns f(r).
Remove returns a Transformer that removes runes r for which s.Contains(r).
Illegal input bytes are replaced by RuneError before being passed to f.
ReplaceIllFormed returns a transformer that replaces all input bytes that are
not part of a well-formed UTF-8 code sequence with utf8.RuneError.
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux 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. |