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


Golang strconv.Atoui函数代码示例

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


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

示例1: ReadCsvPlante

func (o *VueObjet) ReadCsvPlante(cells []string, brut bool) (err error) {
	if len(cells) < 8 {
		err = errors.New(fmt.Sprintf("pas assez de champs (%d)", len(cells)))
		return
	}
	if o.X, err = Atoi16(cells[1]); err != nil {
		return
	}
	if o.Y, err = Atoi16(cells[2]); err != nil {
		return
	}
	o.Type = "plante"
	o.Quantité, _ = strconv.Atoui(cells[4])
	o.Label = fmt.Sprintf("%d %s", o.Quantité, cells[5])
	if o.Quantité > 1 {
		o.Label += "s de "
	} else {
		o.Label += " de "
	}
	o.Label += cells[6]
	if brut {
		o.Label += " (plante brute)"
	} else {
		o.Label += " (plante préparée)"
	}
	if o.IdType, err = strconv.Atoui(cells[8]); err != nil {
		return
	}
	return
}
开发者ID:yesnault,项目名称:braldop,代码行数:30,代码来源:VueObjet.go

示例2: ReadCsvGraine

func (o *VueObjet) ReadCsvGraine(cells []string) (err error) {
	if len(cells) < 6 {
		err = errors.New(fmt.Sprintf("pas assez de champs (%d)", len(cells)))
		return
	}
	if o.X, err = Atoi16(cells[1]); err != nil {
		return
	}
	if o.Y, err = Atoi16(cells[2]); err != nil {
		return
	}
	o.Type = "graine"
	o.Quantité, _ = strconv.Atoui(cells[4])
	o.Label = fmt.Sprintf("%d %s", o.Quantité, "graine")
	if o.Quantité > 1 {
		o.Label += "s de "
	} else {
		o.Label += " de "
	}
	o.Label += cells[5]
	if o.IdType, err = strconv.Atoui(cells[6]); err != nil {
		return
	}
	return
}
开发者ID:yesnault,项目名称:braldop,代码行数:25,代码来源:VueObjet.go

示例3: bye

func bye(ctx *web.Context) string {
	timeStr := ctx.Request.Params["t"]
	sampleStr := ctx.Request.Params["s"]
	times, _ := strconv.Atoui(timeStr)
	if times > 1000 {
		if times > 20000 {
			return "Hi,Chamberlain"
		}
		return "您...是种马吗?\n"
	}

	if times == 0 {
		times = 100
	}

	samples, _ := strconv.Atoui(sampleStr)
	if samples > 10000 {
		return "靠,真bt,有必要这么多次吗\n"
	}

	if samples == 0 {
		samples = 1000
	}

	return fmt.Sprintf("根据%d次平均取样,在%d中挑你碰到的第%d个最好就从了吧\n", samples, times, calcRate(uint32(times), uint32(samples)))
}
开发者ID:gaxxx,项目名称:funx,代码行数:26,代码来源:date.go

示例4: toSeconds

// Convert a string with format hh:mm:ss to a uint with seconds
func toSeconds(str string) (sec uint, err os.Error) {
	h, err := strconv.Atoui(str[0:2])
	toSecondsCheck(err)
	m, err := strconv.Atoui(str[3:5])
	toSecondsCheck(err)
	s, err := strconv.Atoui(str[6:8])
	toSecondsCheck(err)

	return h*3600 + m*60 + s, nil
}
开发者ID:sbhackerspace,项目名称:sbhx-snippets,代码行数:11,代码来源:toseconds-orig.go

示例5: ReadDiploGraph

// charge un fichier de diplo (il vaut mieux partir d'un graphe vide avant de charger un jeu de fichiers)
func (g *DiploGraph) ReadDiploGraph(r *bufio.Reader, ascii bool, subjectIsTroll bool) error {
	line, err := r.ReadString('\n') // TODO : utiliser r.ReadLine() plutôt que r.ReadString('\n')
	for err == nil {
		tokens := strings.SplitN(line, ";", 6)
		if len(tokens) < 5 {
			fmt.Println("Ligne invalide")
			continue
		}
		sid, _ := strconv.Atoui(tokens[0])
		eIsTroll := false
		if tokens[1] == "T" {
			eIsTroll = true
		}
		eid, _ := strconv.Atoui(tokens[2])
		v := new(DiploVertice)
		sn := getOrCreateNode(g.Guilds, sid)
		sn.IsTroll = subjectIsTroll
		var en *DiploNode
		if eIsTroll {
			en = getOrCreateNode(g.Trolls, eid)
			en.IsTroll = true
		} else {
			en = getOrCreateNode(g.Guilds, eid)
		}
		v.Start = sn
		v.End = en
		sn.Starts = AddVertice(sn.Starts, v)
		en.Ends = AddVertice(en.Ends, v)
		v.Text = strings.Trim(tokens[3], " ")
		if ascii {
			v.Text = AsciiToUTF8([]uint8(v.Text))
		}
		if tokens[4] == "ENNEMI" {
			v.Foe = true
		}
		g.Vertices[v.Key()] = v
		line, err = r.ReadString('\n')
		//~ if subjectIsTroll { // DEBUG de la diplo troll
		//~ fmt.Println(v.ColoredText())
		//~ }
	}
	if err != io.EOF {
		fmt.Println("Erreur au parsage de la diplo :")
		fmt.Println(err)
		return err
	}
	return nil
}
开发者ID:Kassbinette,项目名称:Chrall,代码行数:49,代码来源:diplo.go

示例6: ReadCsvElement

func (o *VueObjet) ReadCsvElement(cells []string) (err error) {
	if len(cells) < 6 {
		err = errors.New(fmt.Sprintf("pas assez de champs (%d)", len(cells)))
		return
	}
	if o.X, err = Atoi16(cells[1]); err != nil {
		return
	}
	if o.Y, err = Atoi16(cells[2]); err != nil {
		return
	}
	o.Type = strings.ToLower(cells[4])
	o.Quantité, _ = strconv.Atoui(cells[5])

	o.Label = fmt.Sprintf("%d %s", o.Quantité, o.Type)
	// lignes suivantes provisoires
	if o.Quantité > 1 {
		if len(cells) > 6 {
			o.Label += cells[6]
		} else {
			o.Label += "s"
		}
	}
	return
}
开发者ID:yesnault,项目名称:braldop,代码行数:25,代码来源:VueObjet.go

示例7: Cmd

// Executes an FTP command.
// Sends the command to the server.
// Returns the response code, the response text from the server, and any errors.
// The response code will be zero if an error is encountered.
// The response string will be the empty string if an error is encountered.
func (c *Connection) Cmd(command string, arg string) (code uint, response string, err os.Error) {
	// Format command to be sent to the server.
	formattedCommand := command + " " + arg + CRLF

	// Send command to the server.
	_, err = c.control.Write([]byte(formattedCommand))
	if err != nil {
		return 0, "", err
	}

	// Process the response.
	reader := bufio.NewReader(c.control)
	regex := regexp.MustCompile("[0-9][0-9][0-9] ")
	for {
		ln, err := reader.ReadString('\n')
		if err != nil {
			return 0, "", err
		}

		response += ln
		if regex.MatchString(ln) {
			break
		}
	}
	code, err = strconv.Atoui(response[0:3])
	if err != nil {
		return 0, response, err
	}
	return code, response, err
}
开发者ID:jramnani,项目名称:go-ftp,代码行数:35,代码来源:client.go

示例8: Dial

// Dials up a remote FTP server.
// host should be in the form of address:port e.g. myserver:21 or myserver:ftp
// Returns a pointer to a Connection
func Dial(host string) (*Connection, os.Error) {
	if host == "" {
		return nil, os.NewError("FTP Connection Error: Host can not be blank!")
	}
	if !hasPort(host) {
		return nil, os.NewError("FTP Connection Error: Host must have a port! e.g. host:21")
	}
	conn, err := net.Dial("tcp", "", host)
	if err != nil {
		return nil, err
	}
	// Upon connect, most servers respond with a welcome message.
	// The welcome message contains a status code, just like any other command.
	// TODO: Handle servers with no welcome message.
	welcomeMsg := make([]byte, 1024)
	_, err = conn.Read(welcomeMsg)
	if err != nil {
		return nil, os.NewError("Couldn't read the server's initital connection information. Error: " + err.String())
	}
	code, err := strconv.Atoui(string(welcomeMsg[0:3]))
	err = checkResponseCode(2, code)
	if err != nil {
		return nil, os.NewError("Couldn't read the server's Welcome Message. Error: " + err.String())
	}
	// This doesn't work for IPv6 addresses.
	hostParts := strings.Split(host, ":", 2)
	return &Connection{conn, hostParts[0]}, nil
}
开发者ID:jramnani,项目名称:go-ftp,代码行数:31,代码来源:client.go

示例9: parseLine

// TODO: should args be []interface{} ?
func (obj *GTPObject) parseLine(line string) (empty, hasId bool, id uint, commandName string, args []string) {
	line = obj.preprocessLine(line)
	empty = false
	if line == "" {
		return true, false, 0, "", nil
	}
	split := strings.Split(line, " ", -1)
	// Check if the first part is an id
	hasId = false
	//fmt.Printf("%v\n", split)
	if i, err := strconv.Atoui(split[0]); err == nil {
		// fmt.Printf("Atoui(%s) = %d\n", split[0], i)
		// fmt.Printf("err: %s\n", err)
		hasId = true
		id = i
		split = split[1:len(split)]
	}
	//fmt.Printf("%v\n", split)
	// If there is nothing after the id, the line is treated as if it were empty.
	if len(split) == 0 {
		return true, false, 0, "", nil
	}
	commandName = split[0]
	split = split[1:len(split)]
	args = make([]string, len(split))
	for index, arg := range split {
		args[index] = arg
	}

	return
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:32,代码来源:gtp.go

示例10: cmd

// cmd executes an NNTP command:
// It sends the command given by the format and arguments, and then
// reads the response line. If expectCode > 0, the status code on the
// response line must match it. 1 digit expectCodes only check the first
// digit of the status code, etc.
func (c *Conn) cmd(expectCode uint, format string, args ...interface{}) (code uint, line string, err os.Error) {
	if c.close {
		return 0, "", ProtocolError("connection closed")
	}
	if c.br != nil {
		if err := c.br.discard(); err != nil {
			return 0, "", err
		}
		c.br = nil
	}
	if _, err := fmt.Fprintf(c.conn, format+"\r\n", args); err != nil {
		return 0, "", err
	}
	line, err = c.r.ReadString('\n')
	if err != nil {
		return 0, "", err
	}
	line = strings.TrimSpace(line)
	if len(line) < 4 || line[3] != ' ' {
		return 0, "", ProtocolError("short response: " + line)
	}
	code, err = strconv.Atoui(line[0:3])
	if err != nil {
		return 0, "", ProtocolError("invalid response code: " + line)
	}
	line = line[4:]
	if 1 <= expectCode && expectCode < 10 && code/100 != expectCode ||
		10 <= expectCode && expectCode < 100 && code/10 != expectCode ||
		100 <= expectCode && expectCode < 1000 && code != expectCode {
		err = Error{code, line}
	}
	return
}
开发者ID:rapgamer,项目名称:golang-china,代码行数:38,代码来源:nntp.go

示例11: setField

func (f *Frequency) setField(fieldName, val string) {
	// log.Println("setField", fieldName, value)
	switch fieldName {
	case "trip_id":
		f.Trip = f.feed.Trips[val]
		break
	case "start_time":
		v, err := timeOfDayStringToSeconds(val)
		if err != nil {
			panic(err.String() + val)
		}
		f.StartTime = v
		break
	case "end_time":
		v, err := timeOfDayStringToSeconds(val)
		if err != nil {
			panic(err)
		}
		f.EndTime = v
		break
	case "headway_secs":
		v, _ := strconv.Atoui(val)
		f.HeadwaySecs = v
		break
	}
}
开发者ID:stefanw,项目名称:gogtfs,代码行数:26,代码来源:frequency.go

示例12: GetUInt

func (jsonObj *JSONMap) GetUInt(name string) (i int, r bool) {
	i = 0
	r = false
	val := jsonObj.mapp.MapIndex(reflect.ValueOf(name))

	if val.IsValid() && !val.IsNil() {
		if val.Kind() == reflect.Interface {
			if v, err := strconv.Atoui(val.Elem().String()); err == nil {
				i = int(v)
				r = true
			} else if val.Elem().Kind() == reflect.Uint {
				i = int(val.Elem().Uint())
				r = true
			} else if val.Elem().Kind() == reflect.Int {
				i = int(val.Elem().Int())
				r = true
			} else if val.Elem().Kind() == reflect.Float64 || val.Elem().Kind() == reflect.Float32 {
				i = int(val.Elem().Float())
				r = true
			}
		}
	}

	return i, r
}
开发者ID:nrchandan,项目名称:marvin-go,代码行数:25,代码来源:jsondata.go

示例13: parseNumber

// number = int_lit [ "p" int_lit ] .
//
func (p *gcParser) parseNumber() Const {
	// mantissa
	sign, val := p.parseInt()
	mant, ok := new(big.Int).SetString(sign+val, 10)
	assert(ok)

	if p.lit == "p" {
		// exponent (base 2)
		p.next()
		sign, val = p.parseInt()
		exp, err := strconv.Atoui(val)
		if err != nil {
			p.error(err)
		}
		if sign == "-" {
			denom := big.NewInt(1)
			denom.Lsh(denom, exp)
			return Const{new(big.Rat).SetFrac(mant, denom)}
		}
		if exp > 0 {
			mant.Lsh(mant, exp)
		}
		return Const{new(big.Rat).SetInt(mant)}
	}

	return Const{mant}
}
开发者ID:WXB506,项目名称:golang,代码行数:29,代码来源:gcimporter.go

示例14: parseResponse

// Parses a response for the OAuth dance and sets the appropriate fields
// in o for the request type.
func (o *OAuth) parseResponse(status int, body io.Reader, requestType int) os.Error {
	//dump, _ := http.DumpResponse(resp, true)
	//fmt.Fprintf(os.Stderr, "%s\n", dump)
	r := bodyString(body)

	if status == 401 {
		return &danceError{
			What:  r,
			Where: fmt.Sprintf("parseResponse(requestType=%d)", requestType),
		}
	}

	params := parseParams(r)

	switch requestType {
	case TempCredentialReq:
		o.requestToken = params["oauth_token"]
		o.requestSecret = params["oauth_token_secret"]
		if confirmed, ok := params["oauth_callback_confirmed"]; !ok ||
			confirmed != "true" {
			return &callbackError{o.Callback}
		}
	case TokenReq:
		o.accessToken = params["oauth_token"]
		o.accessSecret = params["oauth_token_secret"]
		o.userId, _ = strconv.Atoui(params["user_id"])
		o.userName = params["screen_name"]
	default:
		return &implementationError{
			What:  "requestType=" + strconv.Itoa(requestType),
			Where: "OAuth\xb7parseResponse()",
		}
	}
	return nil
}
开发者ID:rsesek,项目名称:go-oauth,代码行数:37,代码来源:oauth.go

示例15: Command

func Command(cmd string) []string {
	command := []byte(strings.ToLower(cmd))
	if what_time.Match(command) {
		current_time := time.LocalTime()
		formatted_time := current_time.Format(time.Kitchen)
		return []string{formatted_time}
	} else if who_are_you.Match(command) {
		return []string{"I am Gopher, I'm here to help."}
	} else if cmd == "gopher quit" {
		os.Exit(0)
	} else if matches := gist.FindSubmatch(command); matches != nil {
		for _, match := range matches {
			fmt.Printf("Match: %s\n", string(match))
		}

		if len(matches) > 1 {
			gist_id, err := strconv.Atoui(string(matches[1]))
			if err != nil {
				fmt.Printf("Could not parse the gist_id: %s\n", string(matches[1]))
				return []string{}
			}
			gist_file := strings.TrimSpace(string(matches[2]))
			fmt.Printf("Gist file: %s\n", gist_file)
			gist_content := GetGist(gist_id, gist_file)
			fmt.Printf("Gist Content: %s\n", gist_content)
			return gist_content
		}
		return []string{}
	} else if matches := hoogle.FindSubmatch([]byte(cmd)); matches != nil {
		return Hoogle(strings.Fields(string(matches[1])))
	} else if matches := man_page.FindSubmatch([]byte(cmd)); matches != nil {
		return Manpage(strings.Fields(string(matches[1])))
	}
	return []string{"Dunno what you are asking me. WTF dude?"}
}
开发者ID:wjlroe,项目名称:gocampfire,代码行数:35,代码来源:commands.go


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