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


Golang unicode.IsOneOf函数代码示例

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


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

示例1: consumeIdentifierToken

func (l *Lexer) consumeIdentifierToken() bool {
	c := l.r.Peek(0)
	if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '$' || c == '_' {
		l.r.Move(1)
	} else if c >= 0xC0 {
		if r, n := l.r.PeekRune(0); unicode.IsOneOf(identifierStart, r) {
			l.r.Move(n)
		} else {
			return false
		}
	} else if !l.consumeUnicodeEscape() {
		return false
	}
	for {
		c := l.r.Peek(0)
		if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '$' || c == '_' {
			l.r.Move(1)
		} else if c >= 0xC0 {
			if r, n := l.r.PeekRune(0); r == '\u200C' || r == '\u200D' || unicode.IsOneOf(identifierContinue, r) {
				l.r.Move(n)
			} else {
				break
			}
		} else {
			break
		}
	}
	return true
}
开发者ID:go-playground,项目名称:assets,代码行数:29,代码来源:lex.go

示例2: SlugBytes

// SlugBytes replaces each run of characters which are not unicode letters or
// numbers with a single hyphen, except for leading or trailing runs. Letters
// will be stripped of diacritical marks and lowercased. Letter or number
// codepoints that do not have combining marks or a lower-cased variant will
// be passed through unaltered.
func SlugBytes(s []byte) []byte {
	s = norm.NFKD.Bytes(s)
	buf := make([]byte, 0, len(s))
	dash := false
	for len(s) > 0 {
		r, i := utf8.DecodeRune(s)
		switch {
		// unicode 'letters' like mandarin characters pass through
		case unicode.IsOneOf(lat, r):
			buf = append(buf, s[:i]...)
			dash = true
		case unicode.IsOneOf(nop, r):
			// skip
		case dash:
			buf = append(buf, '-')
			dash = false
		}
		s = s[i:]
	}
	i := len(buf) - 1
	if i >= 0 && buf[i] == '-' {
		buf = buf[:i]
	}
	return buf
}
开发者ID:xtgo,项目名称:slug,代码行数:30,代码来源:bytes.go

示例3: Width

func (Runes) Width(r rune) int {
	if unicode.IsOneOf(zeroWidth, r) {
		return 0
	}
	if unicode.IsOneOf(doubleWidth, r) {
		return 2
	}
	return 1
}
开发者ID:mhahn,项目名称:empire,代码行数:9,代码来源:runes.go

示例4: getPrefixGlyphs

func getPrefixGlyphs(s []rune, num int) []rune {
	p := 0
	for n := 0; n < num && p < len(s); p++ {
		if !unicode.IsOneOf(zeroWidth, s[p]) {
			n++
		}
	}
	for p < len(s) && unicode.IsOneOf(zeroWidth, s[p]) {
		p++
	}
	return s[:p]
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:12,代码来源:width.go

示例5: Char

func Char(r rune) int {
	if r == 0 {
		return 0 // null character
	} else if unicode.Is(unicode.C, r) { // is r control or special character
		return -1
		/* binary search in table of non-spacing characters */
	} else if unicode.IsOneOf(nonSpacing, r) {
		return 0
	} else if unicode.IsOneOf(fullAndWideSpacing, r) {
		return 2
	}
	return 1
}
开发者ID:rwcarlsen,项目名称:flashcard,代码行数:13,代码来源:colwidth.go

示例6: countGlyphs

// countGlyphs considers zero-width characters to be zero glyphs wide,
// and members of Chinese, Japanese, and Korean scripts to be 2 glyphs wide.
func countGlyphs(s []rune) int {
	n := 0
	for _, r := range s {
		switch {
		case unicode.IsOneOf(zeroWidth, r):
		case unicode.IsOneOf(doubleWidth, r):
			n += 2
		default:
			n++
		}
	}
	return n
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:15,代码来源:width.go

示例7: extract_go_expr

// starting from the end of the 'file', move backwards and return a slice of a
// valid Go expression
func (this *bytes_iterator) extract_go_expr() []byte {
	const (
		last_none = iota
		last_dot
		last_paren
		last_ident
	)
	last := last_none
	orig := this.cursor
	this.move_backwards()
loop:
	for {
		r := this.rune()
		switch r {
		case '.':
			this.move_backwards()
			last = last_dot
		case ')', ']':
			if last == last_ident {
				break loop
			}
			this.skip_to_bracket_pair()
			this.move_backwards()
			last = last_paren
		default:
			if unicode.IsOneOf(g_unicode_ident_set, r) {
				this.skip_ident()
				last = last_ident
			} else {
				break loop
			}
		}
	}
	return this.data[this.cursor+1 : orig]
}
开发者ID:ronankde,项目名称:gocode,代码行数:37,代码来源:cursorcontext.go

示例8: readToken

func (scanner *Scanner) readToken() (Token, error) {
	r, _, err := scanner.stream.ReadRune()
	for err == nil && unicode.IsSpace(r) {
		r, _, err = scanner.stream.ReadRune()
	}

	if err == io.EOF {
		return EndToken{}, nil
	}
	if err != nil {
		return nil, err
	}

	switch {
	case r == rune('('):
		return OpenParenToken{}, nil
	case r == rune(')'):
		return CloseParenToken{}, nil
	case r == rune('!'), r == rune('='), r == rune('<'), r == rune('>'):
		return scanner.readComparisonOperatorToken(r)
	case unicode.IsOneOf(symbolChars, r), r == rune('\\'):
		scanner.stream.UnreadRune()
		return scanner.readTextToken()
	default:
		return nil, fmt.Errorf("Unepxected character '%v'.", r)
	}

	panic("unreachable")
}
开发者ID:logtcn,项目名称:TMSU,代码行数:29,代码来源:scanner.go

示例9: readString

func (scanner *Scanner) readString(initialRune rune) (string, error) {
	text := string(initialRune)

	stop := false
	for !stop {
		r, _, err := scanner.stream.ReadRune()

		if err == io.EOF {
			return text, nil
		}
		if err != nil {
			return "", err
		}

		switch {
		case unicode.IsSpace(r), r == rune(')'), r == rune('('), r == rune('='), r == rune('<'), r == rune('>'):
			scanner.stream.UnreadRune()
			return text, nil
		case unicode.IsOneOf(symbolChars, r):
			text += string(r)
		default:
			return "", fmt.Errorf("Unexpected character '%v'.", r)
		}
	}

	panic("unreachable")
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:27,代码来源:scanner.go

示例10: validateValueName

func validateValueName(valueName string) error {
	switch valueName {
	case "":
		return errors.New("tag value cannot be empty.")
	case ".", "..":
		return errors.New("tag value cannot be '.' or '..'.") // cannot be used in the VFS
	case "and", "or", "not":
		return errors.New("tag value cannot be a logical operator: 'and', 'or' or 'not'.") // used in query language
	}

	for _, ch := range valueName {
		switch ch {
		case '(', ')':
			return errors.New("tag value cannot contain parentheses: '(' or ')'.") // used in query language
		case ',':
			return errors.New("tag value cannot contain comma: ','.") // reserved for tag delimiter
		case '=', '<', '>':
			return errors.New("tag value cannot contain a comparison operator: '=', '<' or '>'.") // reserved for tag values
		case ' ', '\t':
			return errors.New("tag value cannot contain space or tab.") // used as tag delimiter
		case '/':
			return errors.New("tag value cannot contain slash: '/'.") // cannot be used in the VFS
		}

		if !unicode.IsOneOf(validValueChars, ch) {
			return fmt.Errorf("tag value cannot contain '%c'.", ch)
		}
	}

	return nil
}
开发者ID:Konubinix,项目名称:tmsu,代码行数:31,代码来源:value.go

示例11: deduce_cursor_context

// deduce cursor context, it includes the declaration under the cursor and partial identifier
// (usually a part of the name of the child declaration)
func (c *auto_complete_context) deduce_cursor_context(file []byte, cursor int) (cursor_context, bool) {
	if cursor <= 0 {
		return cursor_context{nil, ""}, true
	}

	orig := cursor
	iter := bytes_iterator{file, cursor}

	// figure out what is just before the cursor
	iter.move_backwards()
	if iter.char() == '.' {
		// we're '<whatever>.'
		// figure out decl, Parital is ""
		decl := c.deduce_cursor_decl(&iter)
		return cursor_context{decl, ""}, decl != nil
	}

	r := iter.rune()
	if unicode.IsOneOf(g_unicode_ident_set, r) {
		// we're '<whatever>.<ident>'
		// parse <ident> as Partial and figure out decl
		iter.skip_ident()
		partial := string(iter.data[iter.cursor+1 : orig])
		if iter.char() == '.' {
			decl := c.deduce_cursor_decl(&iter)
			return cursor_context{decl, partial}, decl != nil
		} else {
			return cursor_context{nil, partial}, true
		}
	}

	return cursor_context{nil, ""}, true
}
开发者ID:rjmcguire,项目名称:gocode,代码行数:35,代码来源:cursorcontext.go

示例12: SlugAsciiBytes

// SlugAsciiBytes is identical to SlugBytes, except that runs of one or more
// unicode letters or numbers that still fall outside the ASCII range will have
// their UTF-8 representation hex encoded and delimited by hyphens. As with
// SlugBytes, in no case will hyphens appear at either end of the returned
// string.
func SlugAsciiBytes(s []byte) []byte {
	s = norm.NFKD.Bytes(s)
	const m = utf8.UTFMax
	var (
		ib    [m * 3]byte
		ob    []byte
		buf   = make([]byte, 0, len(s))
		dash  = false
		latin = true
	)
	for len(s) > 0 {
		r, i := utf8.DecodeRune(s)
		switch {
		case unicode.IsOneOf(lat, r):
			r = unicode.ToLower(r)
			n := utf8.EncodeRune(ib[:m], r)
			if r >= 128 {
				if latin && dash {
					buf = append(buf, '-')
				}
				n = hex.Encode(ib[m:], ib[:n])
				ob = ib[m : m+n]
				latin = false
			} else {
				if !latin {
					buf = append(buf, '-')
				}
				ob = ib[:n]
				latin = true
			}
			dash = true
			buf = append(buf, ob...)
		case unicode.IsOneOf(nop, r):
			// skip
		case dash:
			buf = append(buf, '-')
			dash = false
			latin = true
		}
		s = s[i:]
	}
	i := len(buf) - 1
	if i >= 0 && buf[i] == '-' {
		buf = buf[:i]
	}
	return buf
}
开发者ID:xtgo,项目名称:slug,代码行数:52,代码来源:bytes.go

示例13: getPrefixGlyphs

func getPrefixGlyphs(s []rune, num int) []rune {
	p := 0
	for n := 0; n < num && p < len(s); p++ {
		// speed up the common case
		if s[p] < 127 {
			n++
			continue
		}
		if !unicode.IsOneOf(zeroWidth, s[p]) {
			n++
		}
	}
	for p < len(s) && unicode.IsOneOf(zeroWidth, s[p]) {
		p++
	}
	return s[:p]
}
开发者ID:peterh,项目名称:liner,代码行数:17,代码来源:width.go

示例14: isChar

func isChar(s string, rangeTable []*unicode.RangeTable) bool {
	runeForm := []rune(s)
	for _, r := range runeForm {
		if !unicode.IsOneOf(rangeTable, r) {
			return false
		}
	}
	return true
}
开发者ID:deathevent,项目名称:kana,代码行数:9,代码来源:kana.go

示例15: countMultiLineGlyphs

func countMultiLineGlyphs(s []rune, columns int, start int) int {
	n := start
	for _, r := range s {
		switch {
		case unicode.IsOneOf(zeroWidth, r):
		case unicode.IsOneOf(doubleWidth, r):
			n += 2
			// no room for a 2-glyphs-wide char in the ending
			// so skip a column and display it at the beginning
			if n%columns == 1 {
				n++
			}
		default:
			n++
		}
	}
	return n
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:18,代码来源:width.go


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