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


Golang strconv.Btoi64函数代码示例

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


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

示例1: VisitFile

func (v *visitor) VisitFile(file string, f *os.FileInfo) {
	var match, err = filepath.Match("c.*.*.dat", filepath.Base(file))
	if match && err == nil {
		var (
			s       = strings.SplitN(filepath.Base(file), ".", 4)
			x, xErr = strconv.Btoi64(s[1], 36)
			z, zErr = strconv.Btoi64(s[2], 36)
		)
		if xErr == nil && zErr == nil && !v.mask.IsMasked(int(x), int(z)) {
			v.chunks[file] = true
		}
	}
}
开发者ID:nemesit,项目名称:mcobj,代码行数:13,代码来源:alphaworld.go

示例2: Read

func (qd qDecoder) Read(p []byte) (n int, err error) {
	// This method writes at most one byte into p.
	if len(p) == 0 {
		return 0, nil
	}
	if _, err := qd.r.Read(qd.scratch[:1]); err != nil {
		return 0, err
	}
	switch c := qd.scratch[0]; {
	case c == '=':
		if _, err := io.ReadFull(qd.r, qd.scratch[:2]); err != nil {
			return 0, err
		}
		x, err := strconv.Btoi64(string(qd.scratch[:2]), 16)
		if err != nil {
			return 0, fmt.Errorf("mail: invalid RFC 2047 encoding: %q", qd.scratch[:2])
		}
		p[0] = byte(x)
	case c == '_':
		p[0] = ' '
	default:
		p[0] = c
	}
	return 1, nil
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:25,代码来源:message.go

示例3: articlesIndex

// articlesIndex is the handler for the site's index page.
// It shows up to the last 10 article summaries (all public info except
// for the Body) on a single page.
func articlesIndex(w http.ResponseWriter, r *http.Request) {
	// Get the user-entered offset, or default to a zero offset.
	offsetS := r.FormValue("Page")
	var offset int
	if len(offsetS) > 0 {
		offset64, err := strconv.Btoi64(offsetS, 10)
		check(err)
		offset = int(offset64)
	} else {
		offset = 0
	}

	// Fetch public data from datastore, up to 10, with offset `offset * 10`
	c := appengine.NewContext(r)
	q := datastore.NewQuery("Article").Order("-Date").Filter("Public =", true).Limit(10).Offset(10 * offset)
	a := make([]Article, 0, 10)
	_, err := q.GetAll(c, &a)
	check(err)

	// Prepares the `indexTemplate.html` template
	t := template.New("index")
	t, err = t.ParseFile("templates/indexTemplate.html")
	check(err)

	// Executes the template, providing the data gathered from the datastore
	err = t.Execute(w, a)
	check(err)
}
开发者ID:CorbinH,项目名称:TechKit-Blog,代码行数:31,代码来源:article.go

示例4: Status

func (self *String) Status() (i int64) {
	var err os.Error
	if i, err = strconv.Btoi64(string(*self), 0); err != nil {
		panic(err)
	}
	return i
}
开发者ID:machinaut,项目名称:oh,代码行数:7,代码来源:cell.go

示例5: scanInt

// scanInt returns the value of the integer represented by the next
// token, checking for overflow.  Any error is stored in s.err.
func (s *ss) scanInt(verb int, bitSize int) int64 {
	if verb == 'c' {
		return s.scanRune(bitSize)
	}
	s.skipSpace(false)
	base, digits := s.getBase(verb)
	haveDigits := false
	if verb == 'U' {
		if !s.consume("U", false) || !s.consume("+", false) {
			s.errorString("bad unicode format ")
		}
	} else {
		s.accept(sign) // If there's a sign, it will be left in the token buffer.
		if verb == 'v' {
			base, digits, haveDigits = s.scanBasePrefix()
		}
	}
	tok := s.scanNumber(digits, haveDigits)
	i, err := strconv.Btoi64(tok, base)
	if err != nil {
		s.error(err)
	}
	n := uint(bitSize)
	x := (i << (64 - n)) >> (64 - n)
	if x != i {
		s.errorString("integer overflow on token " + tok)
	}
	return i
}
开发者ID:go-nosql,项目名称:golang,代码行数:31,代码来源:scan.go

示例6: newVariable

// Allocate a new variable-evaluation element.
func (t *Template) newVariable(words []string) *variableElement {
	// After the final space-separated argument, formatters may be specified separated
	// by pipe symbols, for example: {a b c|d|e}

	// Until we learn otherwise, formatters contains a single name: "", the default formatter.
	formatters := []string{""}
	lastWord := words[len(words)-1]
	bar := strings.IndexRune(lastWord, '|')
	if bar >= 0 {
		words[len(words)-1] = lastWord[0:bar]
		formatters = strings.Split(lastWord[bar+1:], "|", -1)
	}

	args := make([]interface{}, len(words))

	// Build argument list, processing any literals
	for i, word := range words {
		var lerr os.Error
		switch word[0] {
		case '"', '`', '\'':
			v, err := strconv.Unquote(word)
			if err == nil && word[0] == '\'' {
				args[i] = []int(v)[0]
			} else {
				args[i], lerr = v, err
			}

		case '.', '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			v, err := strconv.Btoi64(word, 0)
			if err == nil {
				args[i] = v
			} else {
				v, err := strconv.Atof64(word)
				args[i], lerr = v, err
			}

		default:
			args[i] = fieldName(word)
		}
		if lerr != nil {
			t.parseError("invalid literal: %q: %s", word, lerr)
		}
	}

	// We could remember the function address here and avoid the lookup later,
	// but it's more dynamic to let the user change the map contents underfoot.
	// We do require the name to be present, though.

	// Is it in user-supplied map?
	for _, f := range formatters {
		if t.formatter(f) == nil {
			t.parseError("unknown formatter: %q", f)
		}
	}

	return &variableElement{t.linenum, args, formatters}
}
开发者ID:go-nosql,项目名称:golang,代码行数:58,代码来源:template.go

示例7: parseModeUidGid

func parseModeUidGid(s_mode, s_uid, s_gid string) (mode int64, uid, gid int, err error) {
	mode, err = strconv.Btoi64(s_mode, 0)
	if err != nil {
		return
	}
	uid, err = strconv.Atoi(s_uid)
	if err != nil {
		return
	}
	gid, err = strconv.Atoi(s_gid)
	return mode, uid, gid, nil
}
开发者ID:akrennmair,项目名称:gobox,代码行数:12,代码来源:parser.go

示例8: newVariable

// newVariable allocates a new variable-evaluation element.
func (t *Template) newVariable(words []string) *variableElement {
	formatters := extractFormatters(words)
	args := make([]interface{}, len(words))

	// Build argument list, processing any literals
	for i, word := range words {
		var lerr error
		switch word[0] {
		case '"', '`', '\'':
			v, err := strconv.Unquote(word)
			if err == nil && word[0] == '\'' {
				args[i], _ = utf8.DecodeRuneInString(v)
			} else {
				args[i], lerr = v, err
			}

		case '.', '+', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
			v, err := strconv.Btoi64(word, 0)
			if err == nil {
				args[i] = v
			} else {
				v, err := strconv.Atof64(word)
				args[i], lerr = v, err
			}

		default:
			args[i] = fieldName(word)
		}
		if lerr != nil {
			t.parseError("invalid literal: %q: %s", word, lerr)
		}
	}

	// We could remember the function address here and avoid the lookup later,
	// but it's more dynamic to let the user change the map contents underfoot.
	// We do require the name to be present, though.

	// Is it in user-supplied map?
	for _, f := range formatters {
		if t.formatter(f) == nil {
			t.parseError("unknown formatter: %q", f)
		}
	}

	return &variableElement{t.linenum, args, formatters}
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:47,代码来源:parse.go

示例9: scanInt

// scanInt returns the value of the integer represented by the next
// token, checking for overflow.  Any error is stored in s.err.
func (s *ss) scanInt(verb int, bitSize int) int64 {
	if verb == 'c' {
		return s.scanRune(bitSize)
	}
	base, digits := s.getBase(verb)
	s.skipSpace(false)
	s.accept(sign) // If there's a sign, it will be left in the token buffer.
	tok := s.scanNumber(digits)
	i, err := strconv.Btoi64(tok, base)
	if err != nil {
		s.error(err)
	}
	n := uint(bitSize)
	x := (i << (64 - n)) >> (64 - n)
	if x != i {
		s.errorString("integer overflow on token " + tok)
	}
	return i
}
开发者ID:GNA-SERVICES-INC,项目名称:MoNGate,代码行数:21,代码来源:scan.go

示例10: decodeRFC2047Word

func decodeRFC2047Word(s string) (string, os.Error) {
	fields := strings.Split(s, "?", -1)
	if len(fields) != 5 || fields[0] != "=" || fields[4] != "=" {
		return "", os.ErrorString("mail: address not RFC 2047 encoded")
	}
	charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2])
	// TODO(dsymonds): Support "b" encoding too.
	if enc != "q" {
		return "", fmt.Errorf("mail: RFC 2047 encoding not supported: %q", enc)
	}
	if charset != "iso-8859-1" && charset != "utf-8" {
		return "", fmt.Errorf("mail: charset not supported: %q", charset)
	}

	in := fields[3]
	b := new(bytes.Buffer)
	for i := 0; i < len(in); i++ {
		switch c := in[i]; {
		case c == '=' && i+2 < len(in):
			x, err := strconv.Btoi64(in[i+1:i+3], 16)
			if err != nil {
				return "", fmt.Errorf("mail: invalid RFC 2047 encoding: %q", in[i:i+3])
			}
			i += 2
			switch charset {
			case "iso-8859-1":
				b.WriteRune(int(x))
			case "utf-8":
				b.WriteByte(byte(x))
			}
		case c == '_':
			b.WriteByte(' ')
		default:
			b.WriteByte(c)
		}
	}
	return b.String(), nil
}
开发者ID:jnwhiteh,项目名称:go,代码行数:38,代码来源:message.go

示例11: readInt

func readInt(lx *Lexer) int64 {
	base := 10
	strVal := ""

	if lx.curChar == '0' {
		lx.nextChar()
		base = readBase(lx)
	}
	for ; isNumChar(lx.curChar, base); lx.nextChar() {
		if lx.curChar != '_' {
			strVal += string(lx.curChar)
		}
	}
	var ret int64 = 0
	if len(strVal) > 0 {
		val, err := strconv.Btoi64(strVal, base)
		if err != nil {
			lx.Error(err.String())
		}
		ret = val
	}
	return ret
}
开发者ID:ole108,项目名称:diamond-lang,代码行数:23,代码来源:lexfuncs.go

示例12: VerifyValue

// VerifyValue extracts a value from a string created by SignValue. An error is
// returned if the expiration time has elapsed or the signature is not correct.
func VerifyValue(secret, context string, signedValue string) (string, os.Error) {
	a := strings.Split(signedValue, "~", 3)
	if len(a) != 3 {
		return "", errVerificationFailure
	}
	expiration, err := strconv.Btoi64(a[1], 16)
	if err != nil || expiration < time.Seconds() {
		return "", errVerificationFailure
	}
	expectedSig := signature(secret, context, a[1], a[2])
	actualSig := a[0]
	if len(actualSig) != len(expectedSig) {
		return "", errVerificationFailure
	}
	// Time independent compare
	eq := 0
	for i := 0; i < len(actualSig); i++ {
		eq = eq | (int(actualSig[i]) ^ int(expectedSig[i]))
	}
	if eq != 0 {
		return "", errVerificationFailure
	}
	return a[2], nil
}
开发者ID:rene-dev,项目名称:twister,代码行数:26,代码来源:misc.go

示例13: VerifyValue

// VerifyValue extracts a value from a string created by SignValue. An error is
// returned if the expiration time has elapsed or the signature is not correct.
func VerifyValue(secret, context string, signedValue string) (string, os.Error) {
	a := strings.SplitN(signedValue, "~", 3)
	if len(a) != 3 {
		return "", errVerificationFailure
	}
	expiration, err := strconv.Btoi64(a[1], 16)
	if err != nil || expiration < time.Seconds() {
		return "", errVerificationFailure
	}
	expectedSig := signature(secret, context, a[1], a[2])
	actualSig := a[0]
	if len(actualSig) != len(expectedSig) {
		return "", errVerificationFailure
	}
	// Constant time compare
	var v byte
	for i := 0; i < len(actualSig); i++ {
		v |= actualSig[i] ^ expectedSig[i]
	}
	if subtle.ConstantTimeByteEq(v, 0) != 1 {
		return "", errVerificationFailure
	}
	return a[2], nil
}
开发者ID:chillicoder,项目名称:twister,代码行数:26,代码来源:misc.go

示例14: resolve

func resolve(tag string, in string) (rtag string, out interface{}) {
	tag = shortTag(tag)
	if !resolvableTag(tag) {
		return tag, in
	}

	defer func() {
		if tag != "" && tag != rtag {
			panic("Can't decode " + rtag + " '" + in + "' as a " + tag)
		}
	}()

	if in == "" {
		return "!!null", nil
	}

	c := resolveTable[in[0]]
	if c == 0 {
		// It's a string for sure. Nothing to do.
		return "!!str", in
	}

	// Handle things we can lookup in a map.
	if item, ok := resolveMap[in]; ok {
		return item.tag, item.value
	}

	switch c {
	case 'M':
		// We've already checked the map above.

	case '.':
		// Not in the map, so maybe a normal float.
		floatv, err := strconv.Atof64(in)
		if err == nil {
			return "!!float", floatv
		}
		// XXX Handle base 60 floats here (WTF!)

	case 'D', 'S':
		// Int, float, or timestamp.
		for i := 0; i != len(in); i++ {
			if in[i] == '_' {
				in = strings.Replace(in, "_", "", -1)
				break
			}
		}
		intv, err := strconv.Btoi64(in, 0)
		if err == nil {
			if intv == int64(int(intv)) {
				return "!!int", int(intv)
			} else {
				return "!!int", intv
			}
		}
		floatv, err := strconv.Atof64(in)
		if err == nil {
			return "!!float", floatv
		}
		if strings.HasPrefix(in, "0b") {
			intv, err := strconv.Btoi64(in[2:], 2)
			if err == nil {
				return "!!int", int(intv)
			}
		} else if strings.HasPrefix(in, "-0b") {
			intv, err := strconv.Btoi64(in[3:], 2)
			if err == nil {
				return "!!int", -int(intv)
			}
		}
		// XXX Handle timestamps here.

	case '<':
		// XXX Handle merge (<<) here.

	default:
		panic("resolveTable item not yet handled: " +
			string([]byte{c}) + " (with " + in + ")")
	}
	return "!!str", in
}
开发者ID:ashokgelal,项目名称:goyaml,代码行数:81,代码来源:resolve.go

示例15: parse

func (f fieldInt32) parse(fstr string) os.Error {
	i, err := strconv.Btoi64(fstr, 0)
	*f.ptr = int32(i)
	return err
}
开发者ID:kylelemons,项目名称:wowlog,代码行数:5,代码来源:parser.go


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