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


Golang unicode.IsUpper函数代码示例

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


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

示例1: ToSnake

// ToSnake is a utility function that converts from camelCase to snake_case.
func ToSnake(in string) string {
	if len(in) == 0 {
		return ""
	}

	out := make([]rune, 0, len(in))
	foundUpper := false
	r := []rune(in)

	for i := 0; i < len(r); i++ {
		ch := r[i]
		if unicode.IsUpper(ch) {
			if i > 0 && i < len(in)-1 && !unicode.IsUpper(r[i+1]) {
				out = append(out, '_', unicode.ToLower(ch), r[i+1])
				i++
				continue
				foundUpper = false
			}
			if i > 0 && !foundUpper {
				out = append(out, '_')
			}
			out = append(out, unicode.ToLower(ch))
			foundUpper = true
		} else {
			foundUpper = false
			out = append(out, ch)
		}
	}
	return string(out)
}
开发者ID:moshee,项目名称:gas,代码行数:31,代码来源:gas.go

示例2: Exported

// Is the item exported from the package?
func (n *Named) Exported() bool {
	if n.Imported() {
		return false
	}
	r, _ := utf8.DecodeRuneInString(n.Name)
	return unicode.IsUpper(r)
}
开发者ID:bobappleyard,项目名称:go-pkg,代码行数:8,代码来源:pkg.go

示例3: ToLatin

// ToLatin returns a string transliterated using provided mapping table.
// Runes that cannot be transliterated inserted as-is.
func ToLatin(s string, table map[int]string) string {
	runes := []int(s)
	out := make([]int, 0, len(s))
	for i, rune := range runes {
		if tr, ok := table[unicode.ToLower(rune)]; ok {
			if tr == "" {
				continue
			}
			if unicode.IsUpper(rune) {
				// Correctly translate case of successive characters:
				// ЩИ -> SCHI
				// Щи -> Schi
				if i+1 < len(runes) && !unicode.IsUpper(runes[i+1]) {
					t := []int(tr)
					t[0] = unicode.ToUpper(t[0])
					out = append(out, t...)
					continue
				}
				out = append(out, []int(strings.ToUpper(tr))...)
				continue
			}
			out = append(out, []int(tr)...)
		} else {
			out = append(out, rune)
		}
	}
	return string(out)
}
开发者ID:dchest,项目名称:translit.go,代码行数:30,代码来源:translit.go

示例4: ConvertToUnderscore

func ConvertToUnderscore(camel string) (string, error) {
	var prevRune rune
	var underscore []rune
	for index, runeChar := range camel {
		if index == 0 {
			if !unicode.IsLetter(runeChar) {
				return "", fmt.Errorf("Table and column names can't start with a character other than a letter.")
			}
			underscore = append(underscore, unicode.ToLower(runeChar))
			prevRune = runeChar
		} else {
			if runeChar == '_' || unicode.IsLetter(runeChar) || unicode.IsDigit(runeChar) {
				//Look for Upper case letters, append _ and make character lower case
				if unicode.IsUpper(runeChar) {
					if !unicode.IsUpper(prevRune) {
						underscore = append(underscore, '_')
					}
					underscore = append(underscore, unicode.ToLower(runeChar))
				} else {
					underscore = append(underscore, runeChar)
				}
			} else {
				return "", fmt.Errorf("Table and column names can't contain non-alphanumeric characters.")
			}
		}
		prevRune = runeChar
	}
	return string(underscore), nil
}
开发者ID:AidHamza,项目名称:StreetCRUD,代码行数:29,代码来源:string_fns.go

示例5: UnderscoreMapper

// UnderscoreMapper converts CamelCase strings to their camel_case
// counterpart
func UnderscoreMapper(str string) string {
	var (
		parts = []string{}
		cur   = []rune{}
		last2 = [2]rune{}
	)

	for _, c := range str {
		if unicode.IsUpper(c) {
			if last2[1] != 0 && unicode.IsLower(last2[1]) {
				parts = append(parts, string(cur))
				cur = nil
			}

			cur = append(cur, unicode.ToLower(c))
		} else {
			if last2[0] != 0 && last2[1] != 0 && unicode.IsUpper(last2[0]) && unicode.IsUpper(last2[1]) {
				parts = append(parts, string(cur[:len(cur)-1]))
				cur = []rune{cur[len(cur)-1]}
			}

			cur = append(cur, c)
		}

		last2[0] = last2[1]
		last2[1] = c
	}

	if len(cur) > 0 {
		parts = append(parts, string(cur))
	}

	return strings.Join(parts, "_")
}
开发者ID:jonasi,项目名称:env,代码行数:36,代码来源:mapper.go

示例6: getFuncs

func getFuncs(prog *ssa.Program, pkg *ssa.Package) []*ssa.Function {
	funcs := make([]*ssa.Function, 0, len(pkg.Members))
	for _, mem := range pkg.Members {
		fn, ok := mem.(*ssa.Function)
		if ok {
			if iu := unicode.IsUpper(rune(fn.Name()[0])); iu || *nonExp {
				funcs = append(funcs, fn)
			}
		}
		typ, ok := mem.(*ssa.Type)
		if ok {
			mset := prog.MethodSets.MethodSet(typ.Type())
			for i, n := 0, mset.Len(); i < n; i++ {
				if mf := prog.MethodValue(mset.At(i)); mf != nil {
					if mfn := mf.Name(); len(mfn) > 0 {
						if iu := unicode.IsUpper(rune(mfn[0])); iu || *nonExp {
							funcs = append(funcs, mf)
							//fmt.Printf("DEBUG method %v %v\n", mfn, mf)
						}
					}
				}
			}
		}
	}
	return funcs
}
开发者ID:elliott5,项目名称:shouldexp,代码行数:26,代码来源:main.go

示例7: Rename

func Rename(filename string, line int, column int, newName string) (ok bool, err *errors.GoRefactorError) {

	if ok, err = CheckRenameParameters(filename, line, column, newName); !ok {
		return
	}

	programTree := parseProgram(filename)

	var sym st.Symbol
	if sym, err = programTree.FindSymbolByPosition(filename, line, column); err == nil {

		if _, ok := sym.(*st.PointerTypeSymbol); ok {
			panic("find by position returned pointer type!!!")
		}
		if st.IsPredeclaredIdentifier(sym.Name()) {
			return false, errors.UnrenamableIdentifierError(sym.Name(), " It's a basic language symbol")
		}
		if sym.PackageFrom().IsGoPackage {
			return false, errors.UnrenamableIdentifierError(sym.Name(), " It's a symbol,imported from go library")
		}
		if unicode.IsUpper(int(sym.Name()[0])) && !unicode.IsUpper(int(newName[0])) ||
			unicode.IsLower(int(sym.Name()[0])) && !unicode.IsLower(int(newName[0])) {
			return false, &errors.GoRefactorError{ErrorType: "Can't rename identifier", Message: "can't change access modifier. Changing first letter's case can cause errors."}
		}
		if _, ok := sym.Scope().LookUp(newName, filename); ok {
			return false, errors.IdentifierAlreadyExistsError(newName)
		}

		if meth, ok := sym.(*st.FunctionSymbol); ok {
			if meth.IsInterfaceMethod {
				return false, errors.UnrenamableIdentifierError(sym.Name(), " It's an interface method")
			}
		}
		if ps, ok := sym.(*st.PackageSymbol); ok {
			pack, file := programTree.FindPackageAndFileByFilename(filename)
			impDecl := findImportDecl(pack, file, ps)
			if impDecl == nil {
				panic("couldn't find import decl")
			}
			if impDecl.Name == nil || impDecl.Name.Name == "" {
				impDecl.Name = ast.NewIdent(newName)
			}
		}
		fnames, fsets, files, err := renameSymbol(sym, newName, programTree)
		if err == nil {
			for i, f := range fnames {
				programTree.SaveFileExplicit(f, fsets[i], files[i])
			}
		}
		return err == nil, err
	} else {
		return false, err
	}
	panic("unreachable code")
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:55,代码来源:rename.go

示例8: Snake

func Snake(name string) (r string) {
	// first two letters are upcase like URL, MD5, HTTPRequest etc, keep it as it is.
	if len(name) >= 2 {
		if unicode.IsUpper([]rune(name)[0]) && (unicode.IsUpper([]rune(name)[1]) || unicode.IsNumber([]rune(name)[1])) {
			return name
		}
	}

	r = strings.ToLower(name[:1]) + name[1:]
	return
}
开发者ID:jinzhu,项目名称:hypermusk,代码行数:11,代码来源:definition.go

示例9: isUpperFold

func isUpperFold(rune int) bool {
	if unicode.IsUpper(rune) {
		return true
	}
	c := unicode.SimpleFold(rune)
	for c != rune {
		if unicode.IsUpper(c) {
			return true
		}
		c = unicode.SimpleFold(c)
	}
	return false
}
开发者ID:WXB506,项目名称:golang,代码行数:13,代码来源:parse_test.go

示例10: lintCapAndPunct

func lintCapAndPunct(s string) (isCap, isPunct bool) {
	first, firstN := utf8.DecodeRuneInString(s)
	last, _ := utf8.DecodeLastRuneInString(s)
	isPunct = last == '.' || last == ':' || last == '!'
	isCap = unicode.IsUpper(first)
	if isCap && len(s) > firstN {
		// Don't flag strings starting with something that looks like an initialism.
		if second, _ := utf8.DecodeRuneInString(s[firstN:]); unicode.IsUpper(second) {
			isCap = false
		}
	}
	return
}
开发者ID:swadhin4,项目名称:lint,代码行数:13,代码来源:lint.go

示例11: firstSentenceLen

// firstSentenceLen returns the length of the first sentence in s.
// The sentence ends after the first period followed by space and
// not preceded by exactly one uppercase letter.
//
func firstSentenceLen(s string) int {
	var ppp, pp, p rune
	for i, q := range s {
		if q == '\n' || q == '\r' || q == '\t' {
			q = ' '
		}
		if q == ' ' && p == '.' && (!unicode.IsUpper(pp) || unicode.IsUpper(ppp)) {
			return i
		}
		ppp, pp, p = pp, p, q
	}
	return len(s)
}
开发者ID:ZeusbasePython,项目名称:appscale,代码行数:17,代码来源:synopsis.go

示例12: CompareMethodsByVisibility

func CompareMethodsByVisibility(d1 *ast.FuncDecl, d2 *ast.FuncDecl) int {
	n1 := getDeclName(d1)
	n2 := getDeclName(d2)
	b1 := unicode.IsUpper(int(n1[0]))
	b2 := unicode.IsUpper(int(n2[0]))
	switch {
	case b1 && !b2:
		return 1
	case !b1 && b2:
		return -1
	}
	return 0
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:13,代码来源:sort.go

示例13: extraUpperCaseEntropy

func extraUpperCaseEntropy(match match.Match) float64 {
	word := match.Token

	allLower := true

	for _, char := range word {
		if unicode.IsUpper(char) {
			allLower = false
			break
		}
	}
	if allLower {
		return float64(0)
	}

	//a capitalized word is the most common capitalization scheme,
	//so it only doubles the search space (uncapitalized + capitalized): 1 extra bit of entropy.
	//allcaps and end-capitalized are common enough too, underestimate as 1 extra bit to be safe.

	for _, regex := range []string{START_UPPER, END_UPPER, ALL_UPPER} {
		matcher := regexp.MustCompile(regex)

		if matcher.MatchString(word) {
			return float64(1)
		}
	}
	//Otherwise calculate the number of ways to capitalize U+L uppercase+lowercase letters with U uppercase letters or
	//less. Or, if there's more uppercase than lower (for e.g. PASSwORD), the number of ways to lowercase U+L letters
	//with L lowercase letters or less.

	countUpper, countLower := float64(0), float64(0)
	for _, char := range word {
		if unicode.IsUpper(char) {
			countUpper++
		} else if unicode.IsLower(char) {
			countLower++
		}
	}
	totalLenght := countLower + countUpper
	var possibililities float64

	for i := float64(0); i <= math.Min(countUpper, countLower); i++ {
		possibililities += float64(zxcvbn_math.NChoseK(totalLenght, i))
	}

	if possibililities < 1 {
		return float64(1)
	}

	return float64(math.Log2(possibililities))
}
开发者ID:kressin,项目名称:zxcvbn-go,代码行数:51,代码来源:entropyCalculator.go

示例14: camelToUnderscore

func camelToUnderscore(name string) string {
	rv := ""
	for i, r := range name {
		if unicode.IsUpper(r) && i != 0 {
			rv += "_"
			rv += string(unicode.ToLower(r))
		} else if unicode.IsUpper(r) && i == 0 {
			rv += string(unicode.ToLower(r))
		} else {
			rv += string(r)
		}
	}
	return rv
}
开发者ID:trebogeer,项目名称:cbft,代码行数:14,代码来源:ns_server.go

示例15: camelToSnakeCase

// camelToSnakeCase converts a string containing one or more camel
// cased words into their snake cased equivalents. For example,
// "CamelCase" results in "camel_case".
func camelToSnakeCase(s string) string {
	result := ""
	boundary := true // Are we on a word boundary?
	for _, r := range s {
		if unicode.IsUpper(r) && !boundary {
			result += "_" + string(unicode.ToLower(r))
		} else if unicode.IsUpper(r) {
			result += string(unicode.ToLower(r))
		} else {
			result += string(r)
		}
		boundary = !(unicode.IsLetter(r) || unicode.IsDigit(r))
	}
	return result
}
开发者ID:walmartlabs,项目名称:lovebeat,代码行数:18,代码来源:snakecase.go


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