本文整理汇总了Golang中golang.org/x/text/transform.Chain函数的典型用法代码示例。如果您正苦于以下问题:Golang Chain函数的具体用法?Golang Chain怎么用?Golang Chain使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Chain函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewTransformer
// NewTransformer creates a new transform.Transformer that performs the PRECIS
// preparation and enforcement steps on the given UTF-8 encoded bytes.
func (p Profile) NewTransformer() *Transformer {
var ts []transform.Transformer
if p.options.allowwidechars {
ts = append(ts, width.Fold)
}
ts = append(ts, checker{p: p})
if p.options.width != nil {
ts = append(ts, width.Fold)
}
for _, f := range p.options.additional {
ts = append(ts, f())
}
if p.options.cases {
ts = append(ts, transform.Chain(
cases.Upper(language.Und), cases.Lower(language.Und),
))
}
ts = append(ts, p.options.norm)
// TODO: Apply directionality rule (blocking on the Bidi package)
// TODO: Add the disallow empty rule with a dummy transformer?
return &Transformer{transform.Chain(ts...)}
}
开发者ID:glerchundi,项目名称:etcd2-bootstrapper,代码行数:32,代码来源:profile.go
示例2: NormalizeTitle
func NormalizeTitle(title string) string {
normalizedTitle := title
normalizedTitle = strings.ToLower(normalizedTitle)
normalizedTitle = RomanizeHepburn(title)
normalizedTitle = strings.ToLower(normalizedTitle)
normalizedTitle = RemoveTrailingApostrophe(normalizedTitle)
normalizedTitle, _, _ = transform.String(transform.Chain(
norm.NFD,
transform.RemoveFunc(func(r rune) bool {
return unicode.Is(unicode.Mn, r)
}),
norm.NFC), normalizedTitle)
normalizedTitle = strings.ToLower(normalizedTitle)
normalizedTitle = regexp.MustCompile(`\(\d+\)`).ReplaceAllString(normalizedTitle, " ")
normalizedTitle = strings.Map(func(r rune) rune {
if !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '.' {
return ' '
}
return r
}, normalizedTitle)
normalizedTitle = regexp.MustCompile(`\s+`).ReplaceAllString(normalizedTitle, " ")
normalizedTitle = strings.TrimSpace(normalizedTitle)
return normalizedTitle
}
开发者ID:i96751414,项目名称:quasar,代码行数:25,代码来源:util.go
示例3: NewReader
// NewReader returns a reader which decode from the given encoding, to utf8.
//
// If enc is nil, then only an utf8-enforcing replacement reader
// (see http://godoc.org/code.google.com/p/go.text/encoding#pkg-variables)
// is used.
func NewReader(r io.Reader, enc encoding.Encoding) io.Reader {
if enc == nil || enc == encoding.Replacement {
return transform.NewReader(r, encoding.Replacement.NewEncoder())
}
return transform.NewReader(r,
transform.Chain(enc.NewDecoder(), encoding.Replacement.NewEncoder()))
}
开发者ID:xingskycn,项目名称:go,代码行数:12,代码来源:reader.go
示例4: NewTransformer
// NewTransformer creates a new transform.Transformer that performs the PRECIS
// preparation and enforcement steps on the given UTF-8 encoded bytes.
func (p *Profile) NewTransformer() *Transformer {
var ts []transform.Transformer
// These transforms are applied in the order defined in
// https://tools.ietf.org/html/rfc7564#section-7
if p.options.foldWidth {
ts = append(ts, width.Fold)
}
for _, f := range p.options.additional {
ts = append(ts, f())
}
if p.options.cases != nil {
ts = append(ts, p.options.cases)
}
ts = append(ts, p.options.norm)
if p.options.bidiRule {
ts = append(ts, bidirule.New())
}
ts = append(ts, &checker{p: p, allowed: p.Allowed()})
// TODO: Add the disallow empty rule with a dummy transformer?
return &Transformer{transform.Chain(ts...)}
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:32,代码来源:profile.go
示例5: main
func main() {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
r := transform.NewReader(os.Stdin, t)
if _, err := io.Copy(os.Stdout, r); err != nil {
log.Fatal(err)
}
}
开发者ID:Roman2K,项目名称:transliterate,代码行数:7,代码来源:main.go
示例6: removeNlChars
func removeNlChars(str string) string {
isOk := func(r rune) bool {
return r < 32 || r >= 127
}
t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
str, _, _ = transform.String(t, str)
return str
}
开发者ID:KarolBedkowski,项目名称:rpilcd,代码行数:8,代码来源:lcd.go
示例7: ExampleRemove
func ExampleRemove() {
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
s, _, _ := transform.String(t, "résumé")
fmt.Println(s)
// Output:
// resume
}
开发者ID:davidsoloman,项目名称:beats,代码行数:8,代码来源:example_test.go
示例8: decodeTransfer
// DecodeTransfer decodes base64, quoted-printable or plain text.
func decodeTransfer(r io.Reader, label string) io.Reader {
switch strings.ToLower(label) {
case "base64":
return base64.NewDecoder(base64.StdEncoding, transform.NewReader(r, nonASCIITransformer{}))
case "quoted-printable":
return quotedprintable.NewReader(transform.NewReader(r, transform.Chain(nonASCIITransformer{}, newlineAppendTransformer{})))
case "", "7bit", "8bit", "binary":
return r
default:
return failReader{fmt.Errorf("unsupported transfer encoding: %v", label)}
}
}
开发者ID:kaey,项目名称:mail,代码行数:13,代码来源:mail.go
示例9: stripCtlAndExtFromUnicode
//function to sanitize input
//from: http://rosettacode.org/wiki/Strip_control_codes_and_extended_characters_from_a_string#Go
func stripCtlAndExtFromUnicode(str string) string {
isOk := func(r rune) bool {
return r < 32 || r >= 127
}
// The isOk filter is such that there is no need to chain to norm.NFC
t := transform.Chain(norm.NFKD, transform.RemoveFunc(isOk))
// This Transformer could also trivially be applied as an io.Reader
// or io.Writer filter to automatically do such filtering when reading
// or writing data anywhere.
str, _, _ = transform.String(t, str)
return str
}
开发者ID:RoPe93,项目名称:Namecoin-light,代码行数:14,代码来源:nameserver.go
示例10: GetCompatibleString
// GetCompatibleString removes all the special characters
// from the string name to create a new string compatible
// with different file names.
func GetCompatibleString(name string) string {
// Replace all the & signs with and text
name = strings.Replace(name, "&", "and", -1)
// Change all the characters to ASCII
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ := transform.String(t, name)
// Replace all the spaces with underscore
s, _ := regexp.Compile(`\s+`)
result = s.ReplaceAllString(result, "_")
// Remove all the non alphanumeric characters
r, _ := regexp.Compile(`\W`)
result = r.ReplaceAllString(result, "")
return result
}
开发者ID:dankomiocevic,项目名称:mulifs,代码行数:17,代码来源:objectmanager.go
示例11: normalize
func normalize(name, src string) (string, error) {
if name == "" {
name = baseWithoutExt(src)
}
t := transform.Chain(norm.NFD, transform.RemoveFunc(remove), norm.NFC)
name = strings.TrimSpace(name)
name, _, err := transform.String(t, name)
if err != nil {
return "", err
}
name = strings.ToLower(name)
name = strings.Replace(name, " ", "_", -1)
return name, nil
}
开发者ID:pnelson,项目名称:wimg,代码行数:14,代码来源:main.go
示例12: normalize
// normalize does unicode normalization.
func normalize(in []byte) ([]byte, error) {
// We need a new transformer for each input as it cannot be reused.
filter := func(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks (to be removed)
}
transformer := transform.Chain(norm.NFD, transform.RemoveFunc(filter), norm.NFC)
out, _, err := transform.Bytes(transformer, in)
out = bytes.Map(func(r rune) rune {
if unicode.IsPunct(r) { // Replace punctuations with spaces.
return ' '
}
return unicode.ToLower(r) // Convert to lower case.
}, out)
return out, err
}
开发者ID:dgraph-io,项目名称:benchmarks,代码行数:16,代码来源:forward.go
示例13: ExampleUTF8Validator
func ExampleUTF8Validator() {
for i := 0; i < 2; i++ {
transformer := charmap.Windows1252.NewEncoder()
if i == 1 {
transformer = transform.Chain(encoding.UTF8Validator, transformer)
}
dst := make([]byte, 256)
src := []byte("abc\xffxyz") // src is invalid UTF-8.
nDst, nSrc, err := transformer.Transform(dst, src, true)
fmt.Printf("i=%d: produced %q, consumed %q, error %v\n",
i, dst[:nDst], src[:nSrc], err)
}
// Output:
// i=0: produced "abc\x1axyz", consumed "abc\xffxyz", error <nil>
// i=1: produced "abc", consumed "abc", error encoding: invalid UTF-8
}
开发者ID:davidsoloman,项目名称:beats,代码行数:16,代码来源:example_test.go
示例14: scanContent
// scanContent scans the content of a document for phrases,
// and updates tally.
func (conf *config) scanContent(content []byte, contentType, cs string, tally map[rule]int) {
if strings.Contains(contentType, "javascript") {
conf.scanJSContent(content, tally)
return
}
transformers := make([]transform.Transformer, 0, 3)
if cs != "utf-8" {
e, _ := charset.Lookup(cs)
transformers = append(transformers, e.NewDecoder())
}
if strings.Contains(contentType, "html") {
transformers = append(transformers, entityDecoder{})
}
transformers = append(transformers, new(wordTransformer))
ps := newPhraseScanner(conf.ContentPhraseList, func(s string) {
tally[rule{t: contentPhrase, content: s}]++
})
ps.scanByte(' ')
var t transform.Transformer
if len(transformers) == 1 {
t = transformers[0]
} else {
t = transform.Chain(transformers...)
}
r := transform.NewReader(bytes.NewReader(content), t)
buf := make([]byte, 4096)
for {
n, err := r.Read(buf)
for _, c := range buf[:n] {
ps.scanByte(c)
}
if err != nil {
if err != io.EOF {
log.Println("Error decoding page content:", err)
}
break
}
}
ps.scanByte(' ')
}
开发者ID:ranivishnu,项目名称:redwood,代码行数:49,代码来源:phrase_scan.go
示例15: ExampleUTF8Validator
func ExampleUTF8Validator() {
for i := 0; i < 2; i++ {
var transformer transform.Transformer
transformer = unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM).NewEncoder()
if i == 1 {
transformer = transform.Chain(encoding.UTF8Validator, transformer)
}
dst := make([]byte, 256)
src := []byte("abc\xffxyz") // src is invalid UTF-8.
nDst, nSrc, err := transformer.Transform(dst, src, true)
fmt.Printf("i=%d: produced %q, consumed %q, error %v\n",
i, dst[:nDst], src[:nSrc], err)
}
// Output:
// i=0: produced "\x00a\x00b\x00c\xff\xfd\x00x\x00y\x00z", consumed "abc\xffxyz", error <nil>
// i=1: produced "\x00a\x00b\x00c", consumed "abc", error encoding: invalid UTF-8
}
开发者ID:dylanpoe,项目名称:golang.org,代码行数:17,代码来源:example_test.go
示例16: replace
func replace(path string) {
copy := []string{}
r := `(<script(\s|\S)*?<\/script>)|(<style(\s|\S)*?<\/style>)|(<!--(\s|\S)*?-->)|(<\/?(\s|\S)*?>)|(nbsp;)|((?:\s)\s)|(png)|(jpeg)|(jpg)|(mpg)|(\\u0026)|(\n)|(\v)|(\r)|(\0)|(\t)|(n°)
|(à)|(wbe)|(_)`
regex, err := regexp.Compile(r)
if err != nil {
return // there was a problem with the regular expression.
}
c, _ := readLines(path)
for _, v := range c {
reg := regex.ReplaceAllString(v, " ")
slug := utils.GenerateSlug(reg)
regex1, _ := regexp.Compile(`((\-){1,})|(\b\w{1}\b)`)
reg = regex1.ReplaceAllString(slug, " ")
t := stripchars(reg, `?,.!/©*@#~()$+"'&}]|:;[{²`)
s := strings.TrimSpace(t)
// fmt.Println(s)
normalize := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
normStr1, _, _ := transform.String(normalize, s)
// fmt.Println(normStr1)
if len(v) > 0 {
copy = append(copy, normStr1)
}
}
// fmt.Println(cleaned, "\n")
j := strings.Replace(strings.Join((copy), " "), " ", ",", -1)
// fmt.Println(j)
regex2, err := regexp.Compile(`((\,){2,})`)
j1 := regex2.ReplaceAllString(j, ",")
// fmt.Println(j1)
j2 := strings.Split(j1, ",")
cleaned := []string{}
for _, value := range j2 {
if !stringInSlice(value, cleaned) {
cleaned = append(cleaned, value)
}
}
createCsv(path, filenameCsv, strings.Join(cleaned, ","))
}
开发者ID:kameleon83,项目名称:searchWordsPagesStatic,代码行数:45,代码来源:generate-search.go
示例17: UnicodeSanitize
// UnicodeSanitize sanitizes string to be used in Hugo URL's, allowing only
// a predefined set of special Unicode characters.
// If RemovePathAccents configuration flag is enabled, Uniccode accents
// are also removed.
func UnicodeSanitize(s string) string {
source := []rune(s)
target := make([]rune, 0, len(source))
for _, r := range source {
if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsMark(r) || r == '%' || r == '.' || r == '/' || r == '\\' || r == '_' || r == '-' || r == '#' || r == '+' {
target = append(target, r)
}
}
var result string
if viper.GetBool("RemovePathAccents") {
// remove accents - see https://blog.golang.org/normalization
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ = transform.String(t, string(target))
} else {
result = string(target)
}
return result
}
开发者ID:eRadical,项目名称:hugo,代码行数:26,代码来源:path.go
示例18: cleanSalary
func cleanSalary(input string) string {
cleaner := transform.Chain(norm.NFD,
transform.RemoveFunc(func(r rune) bool {
return unicode.Is(unicode.Mn, r) // Mn: nonspacing marks
}),
norm.NFC)
output, _, _ := transform.String(cleaner, input)
output = strings.ToLower(output)
m := reSalarySep.FindStringSubmatchIndex(output)
if m != nil {
output = output[:m[0]+1] + " - " + output[m[1]-1:]
}
for {
m := reSalarySplit.FindStringSubmatchIndex(output)
if m == nil {
break
}
_, e1 := m[2], m[3]
s2, _ := m[4], m[5]
output = output[:e1] + output[s2:]
}
return output
}
开发者ID:pmezard,项目名称:apec,代码行数:23,代码来源:salary.go
示例19: cleanName
func cleanName(name string) string {
name = strings.Replace(name, "ß", "ss", -1)
name = strings.Replace(name, "Σ", "e", -1)
name = strings.Replace(name, "æ", "a", -1)
name = strings.Replace(name, "&", "and", -1)
name = strings.Replace(name, "$", "s", -1)
for _, c := range removeChars {
name = strings.Replace(name, c, "", -1)
}
for _, c := range spaceChars {
name = strings.Replace(name, c, " ", -1)
}
name = badChanRegex.ReplaceAllString(name, "")
name = strings.Join(strings.Fields(name), " ")
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
unicodeCleanedName, _, err := transform.String(t, name)
if err == nil {
name = unicodeCleanedName
}
return strings.Trim(name, ` "`)
}
开发者ID:hobeone,项目名称:gonab,代码行数:24,代码来源:tv.go
示例20:
case '\u200C':
case '\u200D':
case '\u2060':
case '\uFE00':
case '\uFE01':
case '\uFE02':
case '\uFE03':
case '\uFE04':
case '\uFE05':
case '\uFE06':
case '\uFE07':
case '\uFE08':
case '\uFE09':
case '\uFE0A':
case '\uFE0B':
case '\uFE0C':
case '\uFE0D':
case '\uFE0E':
case '\uFE0F':
case '\uFEFF':
default:
return false
}
return true
})
// Stringprep implements Stringprep Profile for User Names and Passwords (RFC 4013)
// as a transform.Transformer
var Stringprep = transform.Chain(nonASCIISpaceTransformer, mappedToNothing, norm.NFKC)
开发者ID:PMaynard,项目名称:coyim,代码行数:30,代码来源:stringprep.go
注:本文中的golang.org/x/text/transform.Chain函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论