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


Golang unicode.ToUpper函数代码示例

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


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

示例1: uppercase

func (g Garbler) uppercase(p string, numUppercase int) string {
	if numUppercase <= 0 {
		return p
	}
	b := []byte(p)
	numsDone := 0
	for i := 0; i < len(b); i++ {
		//play nice with environ sequence,
		//just uppercase 1st and 2nd consonants,
		//which should make the whole thing more readable
		if i%5 == 0 || i%5 == 2 {
			b[i] = byte(unicode.ToUpper(rune(b[i])))
			numsDone++
			if numsDone >= numUppercase {
				return string(b)
			}
		}
	}
	//playing nice didn't work out so do the other letters too
	//in no particular order
	for i := 0; i < len(b); i++ {
		if !(i%5 == 0 || i%5 == 2) {
			b[i] = byte(unicode.ToUpper(rune(b[i])))
			numsDone++
			if numsDone >= numUppercase {
				return string(b)
			}
		}
	}
	//still here? then numUppercase was too large, panic
	panic("ouch")
}
开发者ID:pavel-odintsov,项目名称:garbler,代码行数:32,代码来源:garbler.go

示例2: defaultFileName

func defaultFileName(lang string, pkg *types.Package) string {
	switch lang {
	case "java":
		if pkg == nil {
			return "Universe.java"
		}
		firstRune, size := utf8.DecodeRuneInString(pkg.Name())
		className := string(unicode.ToUpper(firstRune)) + pkg.Name()[size:]
		return className + ".java"
	case "go":
		if pkg == nil {
			return "go_universe.go"
		}
		return "go_" + pkg.Name() + ".go"
	case "objc":
		if pkg == nil {
			return "GoUniverse.m"
		}
		firstRune, size := utf8.DecodeRuneInString(pkg.Name())
		className := string(unicode.ToUpper(firstRune)) + pkg.Name()[size:]
		return "Go" + className + ".m"
	}
	errorf("unknown target language: %q", lang)
	os.Exit(exitStatus)
	return ""
}
开发者ID:pankona,项目名称:mobile,代码行数:26,代码来源:gen.go

示例3: upperWordLetterPairs

func upperWordLetterPairs(runes []rune) ([]runeBigram, int) {
	limit := len(runes) - 1
	if limit < 1 {
		return make([]runeBigram, 0), 0
	}
	bigrams := make([]runeBigram, limit)
	var a rune
	var b rune
	numPairs := 0
	for i := 0; i < limit; i++ {
		a = runes[i]
		b = runes[i+1]
		if unicode.IsSpace(b) {
			i++
			continue
		}
		if unicode.IsSpace(a) {
			continue
		}
		bigrams[numPairs] = runeBigram{rA: unicode.ToUpper(a), rB: unicode.ToUpper(b)}
		numPairs++
	}
	bigrams = bigrams[0:numPairs]
	return bigrams, numPairs
}
开发者ID:ZackPierce,项目名称:stralgo,代码行数:25,代码来源:runewise.go

示例4: standardizedLocale

func standardizedLocale(s string) string {
	localeParts := strings.Split(s, "-")
	language := localeParts[0]
	regionOrScript := localeParts[1]

	switch len(s) {
	case 5:
		newRegion := ""
		for _, v := range regionOrScript {
			newRegion += string(unicode.ToUpper(v))
		}
		return language + "_" + newRegion
	case 7:
		newScript := ""
		for i, v := range regionOrScript {
			if i == 0 {
				newScript += string(unicode.ToUpper(v))
			} else {
				newScript += string(v)
			}
		}
		return language + "-" + newScript
	}

	return s
}
开发者ID:mandarjog,项目名称:cli,代码行数:26,代码来源:i18n.go

示例5: markov

// This is what generates the actual markov chain
func markov(channel string, conn *irc.Conn) {
	markovData.mutex.RLock()
	var markovchain string
	messageLength := random(50) + 10
	for i := 0; i < messageLength; i++ {
		splitchain := strings.Split(markovchain, " ")
		if len(splitchain) < 2 {
			s := []rune(markovData.keys[random(len(markovData.keys))])
			s[0] = unicode.ToUpper(s[0])
			markovchain = string(s)
			continue
		}
		chainlength := len(splitchain)
		searchfor := strings.ToLower(splitchain[chainlength-2] + " " + splitchain[chainlength-1])
		if len(markovData.bigmap[searchfor]) == 0 || strings.LastIndex(markovchain, ".") < len(markovchain)-50 {
			s := []rune(markovData.keys[random(len(markovData.keys))])
			s[0] = unicode.ToUpper(s[0])
			markovchain = markovchain + ". " + string(s)
			continue
		}
		randnext := random(len(markovData.bigmap[searchfor]))
		markovchain = markovchain + " " + markovData.bigmap[searchfor][randnext]
	}
	conn.Privmsg(channel, markovchain+".")
	markovData.mutex.RUnlock()
}
开发者ID:kravlin,项目名称:sadbot,代码行数:27,代码来源:markov.go

示例6: ToUpperCamelCase

// ToUpperCamelCase returns a copy of the string s with all Unicode letters mapped to their camel case.
// It will convert to upper case previous letter of '_' and first letter, and remove letter of '_'.
func ToUpperCamelCase(s string) string {
	if s == "" {
		return ""
	}
	upper := true
	start := 0
	result := make([]byte, 0, len(s))
	var runeBuf [utf8.UTFMax]byte
	var initialism []byte
	for _, c := range s {
		if c == '_' {
			upper = true
			candidate := string(result[start:])
			initialism = initialism[:0]
			for _, r := range candidate {
				if r < utf8.RuneSelf {
					initialism = append(initialism, toUpperASCII(byte(r)))
				} else {
					n := utf8.EncodeRune(runeBuf[:], unicode.ToUpper(r))
					initialism = append(initialism, runeBuf[:n]...)
				}
			}
			if length := commonInitialism.LookupByBytes(initialism); length > 0 {
				result = append(result[:start], initialism...)
			}
			start = len(result)
			continue
		}
		if upper {
			if c < utf8.RuneSelf {
				result = append(result, toUpperASCII(byte(c)))
			} else {
				n := utf8.EncodeRune(runeBuf[:], unicode.ToUpper(c))
				result = append(result, runeBuf[:n]...)
			}
			upper = false
			continue
		}
		if c < utf8.RuneSelf {
			result = append(result, byte(c))
		} else {
			n := utf8.EncodeRune(runeBuf[:], c)
			result = append(result, runeBuf[:n]...)
		}
	}
	candidate := string(result[start:])
	initialism = initialism[:0]
	for _, r := range candidate {
		if r < utf8.RuneSelf {
			initialism = append(initialism, toUpperASCII(byte(r)))
		} else {
			n := utf8.EncodeRune(runeBuf[:], unicode.ToUpper(r))
			initialism = append(initialism, runeBuf[:n]...)
		}
	}
	if length := commonInitialism.LookupByBytes(initialism); length > 0 {
		result = append(result[:start], initialism...)
	}
	return string(result)
}
开发者ID:zramsay,项目名称:geth-tmsp,代码行数:62,代码来源:strings.go

示例7: Goify

// Goify makes a valid Go identifier out of any string.
// It does that by removing any non letter and non digit character and by making sure the first
// character is a letter or "_".
// Goify produces a "CamelCase" version of the string, if firstUpper is true the first character
// of the identifier is uppercase otherwise it's lowercase.
func Goify(str string, firstUpper bool) string {

	runes := []rune(str)
	w, i := 0, 0 // index of start of word, scan
	for i+1 <= len(runes) {
		eow := false // whether we hit the end of a word
		if i+1 == len(runes) {
			eow = true
		} else if !validIdentifier(runes[i]) {
			// get rid of it
			runes = append(runes[:i], runes[i+1:]...)
		} else if runes[i+1] == '_' {
			// underscore; shift the remainder forward over any run of underscores
			eow = true
			n := 1
			for i+n+1 < len(runes) && runes[i+n+1] == '_' {
				n++
			}
			copy(runes[i+1:], runes[i+n+1:])
			runes = runes[:len(runes)-n]
		} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
			// lower->non-lower
			eow = true
		}
		i++
		if !eow {
			continue
		}

		// [w,i] is a word.
		word := string(runes[w:i])
		// is it one of our initialisms?
		if u := strings.ToUpper(word); commonInitialisms[u] {
			if firstUpper {
				u = strings.ToUpper(u)
			}

			// All the common initialisms are ASCII,
			// so we can replace the bytes exactly.
			copy(runes[w:], []rune(u))
		} else if w > 0 && strings.ToLower(word) == word {
			// already all lowercase, and not the first word, so uppercase the first character.
			runes[w] = unicode.ToUpper(runes[w])
		} else if w == 0 && strings.ToLower(word) == word && firstUpper {
			runes[w] = unicode.ToUpper(runes[w])
		}
		if w == 0 && !firstUpper {
			runes[w] = unicode.ToLower(runes[w])
		}
		//advance to next word
		w = i
	}

	res := string(runes)
	if _, ok := reserved[res]; ok {
		res += "_"
	}
	return res
}
开发者ID:DavyC,项目名称:goa,代码行数:64,代码来源:types.go

示例8: skinkefy

func skinkefy(word string) string {
	isNoun := foundWord(Nouns, word)
	isVerb := foundWord(Verbs, word)
	isAdjective := foundWord(Adjectives, word)
	if UseWordList && !isNoun && !isVerb && !isAdjective {
		return word
	}
	camelCaseCheckR, _ := regexp.Compile("[\\p{Ll}][\\p{Lu}][\\p{L}]+")
	camelCaseR, _ := regexp.Compile("([\\p{Lu}][\\p{Ll}]+|[\\p{Lu}]+)")
	if camelCaseCheckR.MatchString(word) {
		word = camelCaseR.ReplaceAllStringFunc(word, skinkefy)
	} else {
		if (rand.Intn(100) <= skinkeFactor &&
			!IkkeSkinker.Contains(word) &&
			len(word) >= skinkeLength) ||
			Skinker.Contains(word) {
			// Yes, we got a skinke, let's add the word.
			Skinker.Append(word)
			var skinkeCondition int
			first, _ := utf8.DecodeRuneInString(word)
			switch {
			case strings.ToUpper(word) == word:
				skinkeCondition = scFullUpper
			case unicode.ToUpper(first) == first:
				skinkeCondition = scCapitalised
			default:
				skinkeCondition = scRegular
			}
			// Get the last two letters of the word.
			end, size := utf8.DecodeLastRuneInString(word)
			end2, _ := utf8.DecodeLastRuneInString(word[:len(word)-size])
			end = unicode.ToUpper(end)
			end2 = unicode.ToUpper(end2)
			// If it ends on R, it's plural.  That's our rule!
			// If it ends on ET/EN, it's definitive.
			if isNoun {
				word = oneSkinkeNoun(skinkeCondition, end == 'R', end2 == 'E' && (end == 'T' || end == 'N'))
			}
			if isVerb {
				word = oneSkinkeVerb(skinkeCondition, end == 'R', end2 == 'D' && end == 'E')
			}
			if isAdjective {
				word = oneSkinkeAdjective(skinkeCondition)
			}
		} else {
			// Not a skinke word.  If it appears again, it should remain
			// not skinke.
			IkkeSkinker.Append(word)
		}
	}
	return word
}
开发者ID:Athas,项目名称:EggsML,代码行数:52,代码来源:skinkefy.go

示例9: singleLiteralToCharClass

func singleLiteralToCharClass(rx *syntax.Regexp) {
	if rx.Op == syntax.OpLiteral && len(rx.Rune) == 1 {
		char := rx.Rune[0]
		if rx.Flags&syntax.FoldCase != 0 && unicode.ToLower(char) != unicode.ToUpper(char) {
			l, h := unicode.ToLower(char), unicode.ToUpper(char)
			rx.Rune = []rune{h, h, l, l}
			rx.Rune0 = [...]rune{h, h}
		} else {
			rx.Rune = []rune{char, char}
			rx.Rune0 = [...]rune{char, char}
		}
		rx.Op = syntax.OpCharClass
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:14,代码来源:regexp.go

示例10: Goify

// Goify makes a valid Go identifier out of any string.
// It does that by removing any non letter and non digit character and by making sure the first
// character is a letter or "_".
// Goify produces a "CamelCase" version of the string, if firstUpper is true the first character
// of the identifier is uppercase otherwise it's lowercase.
func Goify(str string, firstUpper bool) string {
	if firstUpper {
		if val, ok := acros[str]; ok {
			return val
		}
		for a, u := range acros {
			p := a + "_"
			if strings.HasPrefix(str, p) {
				rest := strings.TrimPrefix(str, p)
				res := Goify(rest, true)
				return u + res
			}
		}
	}
	if str == "ok" && firstUpper {
		return "OK"
	} else if str == "id" && firstUpper {
		return "ID"
	}
	var b bytes.Buffer
	var firstWritten, nextUpper bool
	for i := 0; i < len(str); i++ {
		r := rune(str[i])
		if r == '_' {
			nextUpper = true
		} else if unicode.IsLetter(r) || unicode.IsDigit(r) {
			if !firstWritten {
				if firstUpper {
					r = unicode.ToUpper(r)
				} else {
					r = unicode.ToLower(r)
				}
				firstWritten = true
				nextUpper = false
			} else if nextUpper {
				r = unicode.ToUpper(r)
				nextUpper = false
			}
			b.WriteRune(r)
		}
	}
	if b.Len() == 0 {
		return "_v" // you have a better idea?
	}
	res := b.String()
	if _, ok := reserved[res]; ok {
		res += "_"
	}
	return res
}
开发者ID:RouGang,项目名称:goa,代码行数:55,代码来源:types.go

示例11: helpDocumentation

func helpDocumentation(path string) {
	w := new(bytes.Buffer)
	w.WriteString(documentationHeader)
	w.WriteString("\n/*\n")
	if err := usageTmpl.Execute(w, commands); err != nil {
		log.Fatal(err)
	}

	for _, cmd := range commands {
		r, rlen := utf8.DecodeRuneInString(cmd.Short)
		w.WriteString("\n\n")
		w.WriteRune(unicode.ToUpper(r))
		w.WriteString(cmd.Short[rlen:])
		w.WriteString("\n\nUsage:\n\n\tgomobile " + cmd.Name)
		if cmd.Usage != "" {
			w.WriteRune(' ')
			w.WriteString(cmd.Usage)
		}
		w.WriteRune('\n')
		w.WriteString(cmd.Long)
	}

	w.WriteString("*/\npackage main // import \"golang.org/x/mobile/cmd/gomobile\"\n")

	if err := ioutil.WriteFile(path, w.Bytes(), 0666); err != nil {
		log.Fatal(err)
	}
}
开发者ID:Christeefym,项目名称:lantern,代码行数:28,代码来源:main.go

示例12: removeInvalidCharacters

func removeInvalidCharacters(target string) string {

	var ret bytes.Buffer
	var channel chan rune
	var previousInvalid bool

	channel = make(chan rune)
	previousInvalid = false

	go getCharacterChannel(target, channel)

	for character := range channel {

		if previousInvalid {
			character = unicode.ToUpper(character)
		}

		previousInvalid = !unicode.IsLetter(character) && !unicode.IsDigit(character)

		if !previousInvalid {
			ret.WriteRune(character)
		}
	}

	return ret.String()
}
开发者ID:Knetic,项目名称:presilo,代码行数:26,代码来源:casing.go

示例13: isRegister

func isRegister(ident string) bool {
	if len(ident) != 1 {
		return false
	}
	ch := unicode.ToUpper(rune(ident[0]))
	return (ch >= 'A' && ch <= 'C' || ch >= 'X' && ch <= 'Z' || ch == 'I' || ch == 'J')
}
开发者ID:xconstruct,项目名称:dcpu16,代码行数:7,代码来源:scanner.go

示例14: New

func New(file string, args []string) (*Script, error) {
	if len(args)&1 == 1 {
		return nil, errors.New("number of arguments for template script must be even")
	}
	sc := &Script{}
	if len(args) != 0 {
		sc.args = make(map[string]string)
		for i := 0; i < len(args); i += 2 {
			if len(args[i]) < 2 || args[i][0] != '-' {
				return nil, errors.New("invalid flag name: " + args[i])
			}
			r, n := utf8.DecodeRuneInString(args[i][1:])
			if r == utf8.RuneError {
				return nil, errors.New("invalid flag name: " + args[i])
			}
			sc.args[string(unicode.ToUpper(r))+args[i][1+n:]] = args[i+1]
		}
	}
	tmpl, err := template.New(filepath.Base(file)).Funcs(sc.funcs()).ParseFiles(file)
	if err != nil {
		return nil, err
	}
	sc.tmpl = tmpl
	return sc, nil
}
开发者ID:canthefason,项目名称:gh,代码行数:25,代码来源:tsc.go

示例15: camelize

func camelize(str string) string {
	runes := []rune(str)
	w, i := 0, 0
	for i+1 <= len(runes) {
		eow := false
		if i+1 == len(runes) {
			eow = true
		} else if !validIdentifier(runes[i]) {
			runes = append(runes[:i], runes[i+1:]...)
		} else if spacer(runes[i+1]) {
			eow = true
			n := 1
			for i+n+1 < len(runes) && spacer(runes[i+n+1]) {
				n++
			}
			copy(runes[i+1:], runes[i+n+1:])
			runes = runes[:len(runes)-n]
		} else if unicode.IsLower(runes[i]) && !unicode.IsLower(runes[i+1]) {
			eow = true
		}
		i++
		if !eow {
			continue
		}
		runes[w] = unicode.ToUpper(runes[w])
		w = i
	}
	return string(runes)
}
开发者ID:konstantin-dzreev,项目名称:goa,代码行数:29,代码来源:action.go


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