當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。