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


Golang strings.ToUpper函数代码示例

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


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

示例1: PeopleMutation

func PeopleMutation(x string, mode string) []string {

	var (

		//		y	=	[]string{"","","","",""}
		y []string

		ckl = int(0)
		num = int(0)
	)

	for strings.Contains(x, "  ") {
		x = strings.Replace(x, "  ", " ", -1)
	}

	y = strings.Split(strings.Trim(strings.ToLower(x), " "), " ")

	num = len(y)

	for ckl = 0; ckl < num; ckl++ {
		if mode == "RUS" {
			y[ckl] = fmt.Sprintf("%s%s", strings.ToUpper(y[ckl][:2]), y[ckl][2:])
		} else {
			y[ckl] = fmt.Sprintf("%s%s", strings.ToUpper(y[ckl][:1]), y[ckl][1:])
		}
	}

	return y

}
开发者ID:BestianRU,项目名称:SABookServices,代码行数:30,代码来源:02TextMutation.go

示例2: GetKillometreExtract

func (m *TksManager) GetKillometreExtract(typeExtract string, startIndex int, pageSize int, searched string) (ke *KillometreExtract) {
	// comme il n'y a pas la moindre structure d'index, les recherches, en particulier sur le nom, sont forcément lentes
	ke = new(KillometreExtract)
	ke.SearchedTrollIndex = -1
	m.checkTrollInfosLoaded()
	var source []*TrollInfos
	switch typeExtract {
	case "TrollsByKills":
		source = m.TrollsByKills
	case "TrollsByKillsMonstres":
		source = m.TrollsByKillsMonstres
	case "TrollsByKillsTrolls":
		source = m.TrollsByKillsTrolls
	case "AtkByKillsTrolls":
		source = m.AtkByKillsTrolls
	default:
		ke.Error = "Erreur GetKillometreExtract : type non reconnu : " + typeExtract
		return
	}
	searchedNum, _ := strconv.Atoi(searched)
	if searchedNum > 0 {
		foundIndex := -1
		for i, t := range source {
			if t.Num == searchedNum {
				foundIndex = i
				break
			}
		}
		pageNum := foundIndex / pageSize
		startIndex = pageNum * pageSize
		ke.SearchedTrollIndex = foundIndex - startIndex
	} else if searched != "" {
		upperSearched := strings.ToUpper(searched)
		foundIndex := -1
		for i, t := range source {
			if strings.Index(strings.ToUpper(t.Nom), upperSearched) >= 0 {
				foundIndex = i
				break
			}
		}
		pageNum := foundIndex / pageSize
		startIndex = pageNum * pageSize
		ke.SearchedTrollIndex = foundIndex - startIndex
	} else {
		if startIndex < 0 || startIndex > len(source) {
			ke.Error = fmt.Sprintf("Erreur GetKillometreExtract : index invalide : %d\n", startIndex)
			return
		}
	}
	if pageSize < 0 || pageSize > 100 {
		ke.Error = fmt.Sprintf("Erreur GetKillometreExtract : pageSize invalide : %d\n", pageSize)
		return
	} else if pageSize == 0 {
		pageSize = 20
	}
	//fmt.Printf("startIndex=%d  pageSize=%d\n", startIndex, pageSize)
	ke.Trolls = source[startIndex : pageSize+startIndex]
	ke.StartIndex = startIndex
	return
}
开发者ID:Kassbinette,项目名称:Chrall,代码行数:60,代码来源:trollinfos.go

示例3: main

func main() {
	// 以下读取网卡信息
	Interface, err := net.Interfaces()
	if err != nil {
		panic("未发现网卡地址")
		os.Exit(1)
	}

	handwareAddrs = make(map[string]string, len(Interface))
	for _, inter := range Interface {
		inMAC := strings.ToUpper(inter.HardwareAddr.String())
		handwareAddrs[inMAC] = inMAC
	}

	if len(os.Args) != 2 {
		fmt.Println("为保障安全:请先绑定本机上的网卡地址")
		os.Exit(0)
	}

	addr := os.Args[1]
	h, e := net.ParseMAC(addr)
	if e != nil {
		fmt.Println("为保障安全:请先绑定本机上的网卡地址")
		fmt.Println("方法:client.exe 90-4C-E5-58-7E-FE")
		os.Exit(2)
	}
	inputMAC := strings.ToUpper(h.String())
	if inputMAC != handwareAddrs[inputMAC] {
		fmt.Println("网卡地址不匹配")
		os.Exit(0)
	}
}
开发者ID:nemowen,项目名称:golang,代码行数:32,代码来源:mac.go

示例4: TsigVerify

// TsigVerify verifies the TSIG on a message.
// If the signature does not validate err contains the
// error, otherwise it is nil.
func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) error {
	rawsecret, err := packBase64([]byte(secret))
	if err != nil {
		return err
	}
	// Srtip the TSIG from the incoming msg
	stripped, tsig, err := stripTsig(msg)
	if err != nil {
		return err
	}

	buf := tsigBuffer(stripped, tsig, requestMAC, timersOnly)

	ti := uint64(time.Now().Unix()) - tsig.TimeSigned
	if uint64(tsig.Fudge) < ti {
		return ErrTime
	}

	var h hash.Hash
	switch tsig.Algorithm {
	case HmacMD5:
		h = hmac.New(md5.New, []byte(rawsecret))
	case HmacSHA1:
		h = hmac.New(sha1.New, []byte(rawsecret))
	case HmacSHA256:
		h = hmac.New(sha256.New, []byte(rawsecret))
	default:
		return ErrKeyAlg
	}
	io.WriteString(h, string(buf))
	if strings.ToUpper(hex.EncodeToString(h.Sum(nil))) != strings.ToUpper(tsig.MAC) {
		return ErrSig
	}
	return nil
}
开发者ID:avalanche123,项目名称:dns,代码行数:38,代码来源:tsig.go

示例5: Verb

func (cl cmdLine) Verb() string {
	s := string(cl)
	if idx := strings.Index(s, " "); idx != -1 {
		return strings.ToUpper(s[:idx])
	}
	return strings.ToUpper(s[:len(s)-2])
}
开发者ID:EMC-CMD,项目名称:bosh-agent,代码行数:7,代码来源:smtpd.go

示例6: ToEnv

func (l *Link) ToEnv() []string {
	env := []string{}
	alias := strings.ToUpper(l.Alias())

	if p := l.getDefaultPort(); p != nil {
		env = append(env, fmt.Sprintf("%s_PORT=%s://%s:%s", alias, p.Proto(), l.ChildIP, p.Port()))
	}

	// Load exposed ports into the environment
	for _, p := range l.Ports {
		env = append(env, fmt.Sprintf("%s_PORT_%s_%s=%s://%s:%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto(), l.ChildIP, p.Port()))
		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_ADDR=%s", alias, p.Port(), strings.ToUpper(p.Proto()), l.ChildIP))
		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PORT=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Port()))
		env = append(env, fmt.Sprintf("%s_PORT_%s_%s_PROTO=%s", alias, p.Port(), strings.ToUpper(p.Proto()), p.Proto()))
	}

	// Load the linked container's name into the environment
	env = append(env, fmt.Sprintf("%s_NAME=%s", alias, l.Name))

	if l.ChildEnvironment != nil {
		for _, v := range l.ChildEnvironment {
			parts := strings.Split(v, "=")
			if len(parts) != 2 {
				continue
			}
			// Ignore a few variables that are added during docker build
			if parts[0] == "HOME" || parts[0] == "PATH" {
				continue
			}
			env = append(env, fmt.Sprintf("%s_ENV_%s=%s", alias, parts[0], parts[1]))
		}
	}
	return env
}
开发者ID:Nerdness,项目名称:docker,代码行数:34,代码来源:links.go

示例7: newListNodesFilters

func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filters, error) {
	accepted := map[string]bool{
		"name":       true,
		"id":         true,
		"label":      true,
		"role":       true,
		"membership": true,
	}
	if err := filter.Validate(accepted); err != nil {
		return nil, err
	}
	f := &swarmapi.ListNodesRequest_Filters{
		Names:      filter.Get("name"),
		IDPrefixes: filter.Get("id"),
		Labels:     runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
	}

	for _, r := range filter.Get("role") {
		if role, ok := swarmapi.NodeRole_value[strings.ToUpper(r)]; ok {
			f.Roles = append(f.Roles, swarmapi.NodeRole(role))
		} else if r != "" {
			return nil, fmt.Errorf("Invalid role filter: '%s'", r)
		}
	}

	for _, a := range filter.Get("membership") {
		if membership, ok := swarmapi.NodeSpec_Membership_value[strings.ToUpper(a)]; ok {
			f.Memberships = append(f.Memberships, swarmapi.NodeSpec_Membership(membership))
		} else if a != "" {
			return nil, fmt.Errorf("Invalid membership filter: '%s'", a)
		}
	}

	return f, nil
}
开发者ID:FlyingShit-XinHuang,项目名称:docker,代码行数:35,代码来源:filters.go

示例8: ident

func (s *sc) ident() (sym Sym) {
	assert.For(unicode.IsLetter(s.ch), 20, "character expected")
	var buf []rune
	for {
		buf = append(buf, s.ch)
		s.next()
		if s.err != nil || !(unicode.IsLetter(s.ch) || unicode.IsDigit(s.ch)) {
			break
		}
	}
	if s.err == nil {
		sym.Str = string(buf)
		key := sym.Str
		if s.evil == nil {
			x := true
			s.evil = &x
			if keyTab[key] == None && keyTab[strings.ToUpper(key)] == s.useTab[0] {
				*s.evil = true
			} else if keyTab[key] == s.useTab[0] {
				*s.evil = false
			}
		}
		set := func() {
			if sym.Code = keyTab[key]; sym.Code == None {
				sym.Code = Ident
				sym.User = s.foreignTab[key]
			} else if sym.Code != None {
				ok := false
				for _, u := range s.useTab {
					if u == sym.Code {
						ok = true
						break
					}
				}
				if !ok {
					sym.Code = Ident
					sym.User = s.foreignTab[key]
				}
			}
		}
		if s.evil != nil {
			if *s.evil {
				key = strings.ToUpper(sym.Str)
				if key != sym.Str {
					set()
				} else {
					sym.Code = Ident
				}
			} else {
				set()
			}

		} else {
			sym.Code = Ident
		}
	} else {
		s.mark("error while ident read")
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:60,代码来源:sc.go

示例9: format

func format(lines []string) {
	var indexes []int
	for i, line := range lines {
		// --- First letter of comments in capital
		if indexes = re_comment_caps.FindStringSubmatchIndex(line); indexes != nil && indexes[2] == -1 {
			// => the first capture group didn't return anything, which is what we want (nb: No negative lookahead for regexp in Go)
			// Capitalisation of the first letter
			line = line[:indexes[4]] + strings.ToUpper(line[indexes[4]:indexes[5]]) + line[indexes[5]:]
		}
		// --- Replace "@" by "\" in doxygen comment blocks
		if indexes = re_dox_backslash.FindStringSubmatchIndex(line); indexes != nil {
			line = line[:indexes[3]] + "\\" + line[indexes[4]:]
		}
		//  --- Capitalisation of first letter after brief/return in doxygen comment blocks
		if indexes = re_dox_caps.FindStringSubmatchIndex(line); indexes != nil && indexes[6] == -1 {
			// the third capture group didn't return anything, which is what we want (nb: No negative lookahead for regexp in Go)
			line = line[:indexes[3]] + " " + strings.ToUpper(line[indexes[4]:indexes[5]]) + line[indexes[5]:]
		}
		//  --- Add colon after parameter name and capitalise the first letter of the parameter detail in doxygen comment blocks
		if indexes = re_dox_colon.FindStringSubmatchIndex(line); indexes != nil {
			line = line[:indexes[3]] + ": " + strings.ToUpper(line[indexes[4]:indexes[4]+1]) + line[indexes[4]+1:]
		}
		// If the line used in the loop is modified we replace it in the slice
		if line != lines[i] {
			lines[i] = line
		}
	}
}
开发者ID:vaz-ar,项目名称:cpp_format,代码行数:28,代码来源:cpp_format.go

示例10: EscapeChar

/**
 * Takes a character and returns the escaped string for that character. For
 * example escapeChar(String.fromCharCode(15)) -> "\\x0E".
 * @param {string} c The character to escape.
 * @return {string} An escaped string representing {@code c}.
 */
func EscapeChar(c string) string {
	if v, ok := _EscapeCharJs[c]; ok {
		return v
	}
	var rv string
	var cc rune
	for _, cc = range rv {
		switch {
		case cc > 31 && cc < 127:
			rv = c
		case cc < 16:
			// tab is 9 but handled above
			rv = "\\x0" + strings.ToUpper(string(cc))
		case cc < 256:
			rv = "\\x" + strings.ToUpper(string(cc))
		case cc < 4096:
			rv = "\\u0" + strings.ToUpper(string(cc))
		case cc >= 4096:
			rv = "\\u" + strings.ToUpper(string(cc))
		default:
			rv = c
		}
		break
	}
	_EscapeCharJs[c] = rv
	return rv
}
开发者ID:romanoff,项目名称:closure-templates,代码行数:33,代码来源:sanitizers.go

示例11: ToRuleCreateMap

// ToRuleCreateMap builds the create rule options into a serializable format.
func (opts CreateRuleOpts) ToRuleCreateMap() (map[string]interface{}, error) {
	rule := make(map[string]interface{})

	if opts.ParentGroupID == "" {
		return rule, errors.New("A ParentGroupID must be set")
	}
	if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
		return rule, errors.New("A FromPort must be set")
	}
	if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
		return rule, errors.New("A ToPort must be set")
	}
	if opts.IPProtocol == "" {
		return rule, errors.New("A IPProtocol must be set")
	}
	if opts.CIDR == "" && opts.FromGroupID == "" {
		return rule, errors.New("A CIDR or FromGroupID must be set")
	}

	rule["parent_group_id"] = opts.ParentGroupID
	rule["from_port"] = opts.FromPort
	rule["to_port"] = opts.ToPort
	rule["ip_protocol"] = opts.IPProtocol

	if opts.CIDR != "" {
		rule["cidr"] = opts.CIDR
	}
	if opts.FromGroupID != "" {
		rule["group_id"] = opts.FromGroupID
	}

	return map[string]interface{}{"security_group_rule": rule}, nil
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:34,代码来源:requests.go

示例12: stringFormat

// stringFormat formats a string.
func stringFormat(format string, text string) string {
	if format == "uppercase" {
		return strings.ToUpper(text)
	} else if format == "lowercase" {
		return strings.ToLower(text)
	} else if format == "sentence" {
		if len(text) > 1 {
			return strings.ToUpper(text[0:1]) + strings.ToLower(text[1:])
		} else {
			return strings.ToUpper(text)
		}
	} else if format == "formal" {
		words := strings.Split(text, " ")
		result := []string{}
		for _, word := range words {
			if len(word) > 1 {
				result = append(result, strings.ToUpper(word[0:1])+strings.ToLower(word[1:]))
			} else {
				result = append(result, strings.ToUpper(word))
			}
		}
		return strings.Join(result, " ")
	}
	return text
}
开发者ID:rossanthony,项目名称:scarecrow,代码行数:26,代码来源:utils.go

示例13: strGetSetFunction

func strGetSetFunction(c []Column, tblName string) string {
	var ret string
	var letter string = strings.ToLower(tblName[:1])
	ret = "func (" + letter + " *" + tblName + ") Set(key string, value interface{}) error {\n"
	if hasIntColumns(c) {
		ret += "\tvar err error\n"
	}
	ret += "\tif  value == nil {\n"
	ret += "\t\treturn errors.New(\"value for \" + key + \" is nil\")\n"
	ret += "\t}\n"
	ret += "\tswitch key {\n"
	for _, col := range c {
		ret += "\tcase \"" + col.Field + "\":\n" //TODO: capitalize fields
		if getType(col.Type) == "int" {
			ret += "\t\t" + letter + "."
			ret += strings.ToUpper(col.Field[:1]) + col.Field[1:]
			ret += ", err = strconv.Atoi(value.(string))\n"
			ret += "\t\tif err != nil && value != \"NULL\" {\n"
			ret += "\t\t\treturn err\n"
			ret += "\t\t}\n"
		} else {
			ret += "\t\t" + letter + "." + strings.ToUpper(col.Field[:1]) + col.Field[1:] + " = value.(string)\n"
		}
		ret += "\t\treturn nil\n"
	}
	ret += "\tdefault:\n"
	ret += "\t\treturn errors.New(\"Key not found:\" + key)\n"
	ret += "\t}\n"
	ret += "}\n\n"
	return ret
}
开发者ID:jmu0,项目名称:orm,代码行数:31,代码来源:dbmodel.go

示例14: TestEnvironmentVariables

func (s *ProxyUpdaterSuite) TestEnvironmentVariables(c *gc.C) {
	setenv := func(proxy, value string) {
		os.Setenv(proxy, value)
		os.Setenv(strings.ToUpper(proxy), value)
	}
	setenv("http_proxy", "foo")
	setenv("https_proxy", "foo")
	setenv("ftp_proxy", "foo")
	setenv("no_proxy", "foo")

	proxySettings, _ := s.updateConfig(c)
	updater, err := proxyupdater.NewWorker(s.config)
	c.Assert(err, jc.ErrorIsNil)
	defer worker.Stop(updater)
	s.waitProxySettings(c, proxySettings)

	assertEnv := func(proxy, value string) {
		c.Assert(os.Getenv(proxy), gc.Equals, value)
		c.Assert(os.Getenv(strings.ToUpper(proxy)), gc.Equals, value)
	}
	assertEnv("http_proxy", proxySettings.Http)
	assertEnv("https_proxy", proxySettings.Https)
	assertEnv("ftp_proxy", proxySettings.Ftp)
	assertEnv("no_proxy", proxySettings.NoProxy)
}
开发者ID:bac,项目名称:juju,代码行数:25,代码来源:proxyupdater_test.go

示例15: initHandlerCache

func (o *TodoListAPI) initHandlerCache() {
	if o.context == nil {
		o.context = middleware.NewRoutableContext(o.spec, o, nil)
	}

	if o.handlers == nil {
		o.handlers = make(map[string]map[string]http.Handler)
	}

	if o.handlers["POST"] == nil {
		o.handlers[strings.ToUpper("POST")] = make(map[string]http.Handler)
	}
	o.handlers["POST"]["/"] = todos.NewAddOne(o.context, o.TodosAddOneHandler)

	if o.handlers["DELETE"] == nil {
		o.handlers[strings.ToUpper("DELETE")] = make(map[string]http.Handler)
	}
	o.handlers["DELETE"]["/{id}"] = todos.NewDestroyOne(o.context, o.TodosDestroyOneHandler)

	if o.handlers["GET"] == nil {
		o.handlers[strings.ToUpper("GET")] = make(map[string]http.Handler)
	}
	o.handlers["GET"]["/"] = todos.NewFindTodos(o.context, o.TodosFindTodosHandler)

	if o.handlers["PUT"] == nil {
		o.handlers[strings.ToUpper("PUT")] = make(map[string]http.Handler)
	}
	o.handlers["PUT"]["/{id}"] = todos.NewUpdateOne(o.context, o.TodosUpdateOneHandler)

}
开发者ID:jak-atx,项目名称:vic,代码行数:30,代码来源:todo_list_api.go


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