当前位置: 首页>>代码示例>>Golang>>正文


Golang unicode.IsMark函数代码示例

本文整理汇总了Golang中unicode.IsMark函数的典型用法代码示例。如果您正苦于以下问题:Golang IsMark函数的具体用法?Golang IsMark怎么用?Golang IsMark使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了IsMark函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Stat

// Stat calculates statistics for all runes read from r.
func (m *Main) Stat(r io.RuneReader) (Stats, error) {
	var stats Stats

	for {
		// Read next character.
		ch, sz, err := r.ReadRune()
		if err == io.EOF {
			break
		} else if err != nil {
			return stats, err
		}

		// Calculate stats.
		stats.TotalN++
		if unicode.IsControl(ch) {
			stats.ControlN++
		}
		if unicode.IsDigit(ch) {
			stats.DigitN++
		}
		if unicode.IsGraphic(ch) {
			stats.GraphicN++
		}
		if unicode.IsLetter(ch) {
			stats.LetterN++
		}
		if unicode.IsLower(ch) {
			stats.LowerN++
		}
		if unicode.IsMark(ch) {
			stats.MarkN++
		}
		if unicode.IsNumber(ch) {
			stats.NumberN++
		}
		if unicode.IsPrint(ch) {
			stats.PrintN++
		}
		if unicode.IsPunct(ch) {
			stats.PunctN++
		}
		if unicode.IsSpace(ch) {
			stats.SpaceN++
		}
		if unicode.IsSymbol(ch) {
			stats.SymbolN++
		}
		if unicode.IsTitle(ch) {
			stats.TitleN++
		}
		if unicode.IsUpper(ch) {
			stats.UpperN++
		}
		if sz > 1 {
			stats.MultiByteN++
		}
	}

	return stats, nil
}
开发者ID:boutros,项目名称:unistat,代码行数:61,代码来源:main.go

示例2: CharType

// CharType returns a string representing the unicode type of a rune
func CharType(r rune) string {
	switch {
	case unicode.IsLetter(r):
		return "letter"
	case unicode.IsSpace(r):
		return "space"
	case unicode.IsPunct(r):
		return "punct"
	case unicode.IsNumber(r):
		return "number"
	case unicode.IsSymbol(r):
		return "symbol"
	case unicode.IsMark(r):
		return "mark"
	case unicode.IsDigit(r):
		return "digit"
	case unicode.IsPrint(r):
		return "print"
	case unicode.IsControl(r):
		return "control"
	case unicode.IsGraphic(r):
		return "graphic"
	default:
		return "invalid"
	}
}
开发者ID:aliwatters,项目名称:go-course-02,代码行数:27,代码来源:ex4.8.go

示例3: CharCount

// CharCount scans a *bufio.Reader and returns a map of the counts of its
// Unicode character types.
func CharCount(in *bufio.Reader) map[string]int {
	counts := make(map[string]int) // counts of Unicode character types

	for {
		r, n, err := in.ReadRune() // returns rune, nbytes, error
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
			os.Exit(1)
		}

		switch {
		case r == unicode.ReplacementChar && n == 1:
			counts["invalid"]++
		case unicode.IsControl(r):
			counts["control"]++
		case unicode.IsLetter(r):
			counts["letter"]++
		case unicode.IsMark(r):
			counts["mark"]++
		case unicode.IsNumber(r):
			counts["number"]++
		case unicode.IsPunct(r):
			counts["punct"]++
		case unicode.IsSpace(r):
			counts["space"]++
		case unicode.IsSymbol(r):
			counts["symbol"]++
		}
	}
	return counts
}
开发者ID:joyrexus,项目名称:gopl-exercises,代码行数:36,代码来源:charcount.go

示例4: incrementCount

func incrementCount(r rune, counts map[int]int) {
	switch {
	case unicode.IsControl(r):
		counts[isControl]++

	case unicode.IsNumber(r):
		counts[isNumber]++

	case unicode.IsDigit(r):
		counts[isDigit]++

	case unicode.IsLetter(r):
		counts[isLetter]++

	case unicode.IsMark(r):
		counts[isMark]++

	case unicode.IsPunct(r):
		counts[isPunct]++

	case unicode.IsSpace(r):
		counts[isSpace]++

	case unicode.IsSymbol(r):
		counts[isSymbol]++

	case unicode.IsPrint(r):
		counts[isPrint]++

	case unicode.IsGraphic(r):
		counts[isGraphic]++
	}

}
开发者ID:alexchowle,项目名称:tgpl,代码行数:34,代码来源:charcount.go

示例5: TestRune_IsIndependent

func TestRune_IsIndependent(t *testing.T) {
	numbers := make([]rune, 0)
	letters := make([]rune, 0)
	marks := make([]rune, 0)
	symbols := make([]rune, 0)
	puncts := make([]rune, 0)
	others := make([]rune, 0)
	for _, r := range unicode.Myanmar.R16 {
		for c := r.Lo; c <= r.Hi; c++ {
			switch mr := rune(c); true {
			case unicode.IsLetter(mr):
				letters = append(letters, mr)
			case unicode.IsNumber(mr):
				numbers = append(numbers, mr)
			case unicode.IsMark(mr):
				marks = append(marks, mr)
			case unicode.IsPunct(mr):
				puncts = append(puncts, mr)
			case unicode.IsSymbol(mr):
				symbols = append(symbols, mr)
			default:
				others = append(others, mr)
			}
		}
	}

	independents := string(letters) + string(numbers) + string(puncts) + " \t\r\n"
	for _, consonant := range independents {
		if ok, _ := Rune(consonant).IsIndependent(); !ok {
			t.Errorf("[%U] expected result is true, but it returns false", consonant)
		}
	}
}
开发者ID:jittuu,项目名称:songbook,代码行数:33,代码来源:text_test.go

示例6: scanFrac

func scanFrac(l *CommonLexer, ch rune) (stateFn, syms.SymbolID) {
	if unicode.IsDigit(ch) {
		return scanFrac, syms.NUM
	}
	if ch == '.' || unicode.IsLetter(ch) || unicode.IsNumber(ch) || unicode.IsMark(ch) {
		return scanIllegal, syms.ERROR
	}
	return nil, syms.NUM
}
开发者ID:hialin,项目名称:hialin,代码行数:9,代码来源:lexer.go

示例7: Sanitize

func Sanitize(r rune) rune {
	switch {
	case unicode.IsPunct(r):
		return ' '
	case unicode.IsMark(r):
		return ' '
	case unicode.IsSymbol(r):
		return ' '
	}
	return r
}
开发者ID:rueycheng,项目名称:trec-liveqa-server,代码行数:11,代码来源:text.go

示例8: scanHex

func scanHex(l *CommonLexer, ch rune) (stateFn, syms.SymbolID) {
	if unicode.IsDigit(ch) ||
		'a' <= ch && ch <= 'f' ||
		'A' <= ch && ch <= 'F' {
		return scanHex, syms.HEXNUM
	}
	if ch == '.' || unicode.IsLetter(ch) || unicode.IsNumber(ch) || unicode.IsMark(ch) {
		return scanIllegal, syms.ERROR
	}
	return nil, syms.HEXNUM
}
开发者ID:hialin,项目名称:hialin,代码行数:11,代码来源:lexer.go

示例9: main

func main() {
	counts := make(map[string]int)
	var utflen [utf8.UTFMax + 1]int
	invalid := 0

	in := bufio.NewReader(os.Stdin)
	for {
		r, n, err := in.ReadRune()
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
			os.Exit(1)
		}
		if r == unicode.ReplacementChar && n == 1 {
			invalid++
			continue
		}

		utflen[n]++
		switch {
		case unicode.IsLetter(r):
			counts["Letter"]++
		case unicode.IsMark(r):
			counts["Mark"]++
		case unicode.IsNumber(r):
			counts["Number"]++
		case unicode.IsPunct(r):
			counts["Punct"]++
		case unicode.IsSymbol(r):
			counts["Symbol"]++
		case unicode.IsSpace(r):
			counts["Space"]++
		default:
			counts["Other"]++
		}
	}

	fmt.Printf("rune\tcount\n")
	for c, n := range counts {
		fmt.Printf("%s\t%d\n", c, n)
	}
	fmt.Print("\nlen\tcount\n")
	for i, n := range utflen {
		if i > 0 {
			fmt.Printf("%d\t%d\n", i, n)
		}
	}
	if invalid > 0 {
		fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
	}
}
开发者ID:seikichi,项目名称:gopl,代码行数:53,代码来源:main.go

示例10: main

func main() {
	counts := make(map[rune]int) // counts of Unicode characters
	var utflen [utf8.UTFMax]int  // count of lengths of UTF-8 encodings
	invalid := 0                 // count of invalid UTF-8 characters
	cats := make(map[string]int) // counts of Unicode categories

	// In a terminal, use CTRL+Z at line start to signal EOF with ENTER.
	in := bufio.NewReader(os.Stdin)
	for {
		r, n, err := in.ReadRune() // returns rune, nbytes, error
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
			os.Exit(1)
		}
		if r == unicode.ReplacementChar && n == 1 {
			invalid++
			continue
		}
		switch {
		case unicode.IsLetter(r):
			cats["letter"]++
		case unicode.IsDigit(r):
			cats["digit"]++
		case unicode.IsControl(r):
			cats["control"]++
		case unicode.IsMark(r):
			cats["mark"]++
		case unicode.IsPunct(r):
			cats["punct"]++
		case unicode.IsSymbol(r):
			cats["symbol"]++
		}
		counts[r]++
		utflen[n-1]++
	}
	fmt.Printf("rune\tcount\n")
	for c, n := range counts {
		fmt.Printf("%q\t%d\n", c, n)
	}
	fmt.Print("\nlen\tcount\n")
	for i, n := range utflen {
		fmt.Printf("%d\t%d\n", i+1, n)
	}
	fmt.Print("\ncat\tcount\n")
	for s, n := range cats {
		fmt.Printf("%v\t%d\n", s, n)
	}
	fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
}
开发者ID:yyBeta,项目名称:gopl,代码行数:52,代码来源:ex8.go

示例11: main

func main() {
	in := bufio.NewReader(os.Stdin)
	counts := make(map[string]int)  // counts of Unicode character types
	var utflen [utf8.UTFMax + 1]int // count of lengths of UTF-8 encodings
	invalid := 0                    // count of invalid UTF-8 characters

	for {
		r, n, err := in.ReadRune() // returns rune, nbytes, error
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "charcount: %v\n", err)
			os.Exit(1)
		}
		if r == unicode.ReplacementChar && n == 1 {
			invalid++
			continue
		}

		switch {
		case unicode.IsControl(r):
			counts["control"]++
		case unicode.IsLetter(r):
			counts["letter"]++
		case unicode.IsMark(r):
			counts["mark"]++
		case unicode.IsNumber(r):
			counts["number"]++
		case unicode.IsPunct(r):
			counts["punct"]++
		case unicode.IsSpace(r):
			counts["space"]++
		case unicode.IsSymbol(r):
			counts["symbol"]++
		}
		utflen[n]++
	}
	fmt.Printf("rune\tcount\n")
	for c, n := range counts {
		fmt.Printf("%q\t%d\n", c, n)
	}
	fmt.Print("\nlen\tcount\n")
	for i, n := range utflen {
		if i > 0 {
			fmt.Printf("%d\t%d\n", i, n)
		}
	}
	if invalid > 0 {
		fmt.Printf("\n%d invalid UTF-8 characters\n", invalid)
	}
}
开发者ID:joyrexus,项目名称:gopl-exercises,代码行数:52,代码来源:main.go

示例12: printChars

func printChars(chars map[rune]int) {
	keys := sortRuneKeys(chars)
	var p [utf8.UTFMax]byte
	for _, key := range keys {
		char := key
		if !unicode.IsPrint(key) || unicode.IsMark(key) {
			char = ' '
		}
		var cat string
		for name, rng := range unicode.Categories {
			if unicode.In(key, rng) && len(name) > 1 {
				cat = name
			}
		}
		utf8.EncodeRune(p[:], key)
		fmt.Printf("%c (%-2s %U 0x%x) %d\n", char, cat, key, p, chars[key])
	}
}
开发者ID:finkf,项目名称:ucharstats,代码行数:18,代码来源:main.go

示例13: scanIdentifier

// scanIdentifier returns the extent of the prefix of the string that
// represents a valid identifier, along with the length of that prefix
// in runes.
//
// Identifiers may contain utf8-encoded non-Latin letters, which will
// cause the returned "rune length" to be shorter than the byte length
// of the returned string.
func scanIdentifier(s string) (string, int) {
	byteLen := 0
	runeLen := 0
	for {
		if byteLen >= len(s) {
			break
		}

		nextRune, size := utf8.DecodeRuneInString(s[byteLen:])
		if !(nextRune == '_' ||
			nextRune == '-' ||
			nextRune == '.' ||
			nextRune == '*' ||
			unicode.IsNumber(nextRune) ||
			unicode.IsLetter(nextRune) ||
			unicode.IsMark(nextRune)) {
			break
		}

		// If we reach a star, it must be between periods to be part
		// of the same identifier.
		if nextRune == '*' && s[byteLen-1] != '.' {
			break
		}

		// If our previous character was a star, then the current must
		// be period. Otherwise, undo that and exit.
		if byteLen > 0 && s[byteLen-1] == '*' && nextRune != '.' {
			byteLen--
			if s[byteLen-1] == '.' {
				byteLen--
			}

			break
		}

		byteLen = byteLen + size
		runeLen = runeLen + 1
	}

	return s[:byteLen], runeLen
}
开发者ID:hooklift,项目名称:terraform,代码行数:49,代码来源:scanner.go

示例14: UnicodeSanitize

// Rewrite string to remove non-standard path characters
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)
		}
	}

	return string(target)
}
开发者ID:tomzhang,项目名称:afero,代码行数:23,代码来源:util.go

示例15: 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


注:本文中的unicode.IsMark函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。