本文整理汇总了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)
}
示例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)
}
示例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)
}
示例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
}
示例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, "_")
}
示例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
}
示例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")
}
示例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
}
示例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
}
示例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
}
示例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)
}
示例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
}
示例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))
}
示例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
}
示例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
}