Пример #1
0
func ExampleIf() {
	// 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)

	// Output:
	// アルアノリウ tech / 中國 / 5₩
}
Пример #2
0
func ExampleIn() {
	// 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)

	// Output:
	// アルアノリウ tech / アルアノリウ tech
}
Пример #3
0
func dealWithYujian(rawQuery string) string {
	// We create a transformer that reduces all latin runes to their canonical form
	t := runes.If(runes.In(unicode.Latin), width.Fold, nil)
	rawQuery, _, _ = transform.String(t, rawQuery)

	if shawnTanRE.MatchString(rawQuery) {
		rawQuery = shawnRE.ReplaceAllLiteralString(rawQuery, "Yujian")
		rawQuery = TAN_RE.ReplaceAllLiteralString(rawQuery, "Yao")
	} else if tq := strings.Replace(rawQuery, " ", "", -1); shawnTanRE.MatchString(tq) {
		rawQuery = shawnRE.ReplaceAllLiteralString(tq, "Yujian")
		rawQuery = TAN_RE.ReplaceAllLiteralString(rawQuery, "Yao")
	}

	return rawQuery
}