本文整理汇总了Golang中strconv.Btoui64函数的典型用法代码示例。如果您正苦于以下问题:Golang Btoui64函数的具体用法?Golang Btoui64怎么用?Golang Btoui64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Btoui64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Symbol
// Symbol looks up the program counters listed in the request,
// responding with a table mapping program counters to function names.
// The package initialization registers it as /debug/pprof/symbol.
func Symbol(c *http.Conn, r *http.Request) {
c.SetHeader("content-type", "text/plain; charset=utf-8")
// We don't know how many symbols we have, but we
// do have symbol information. Pprof only cares whether
// this number is 0 (no symbols available) or > 0.
fmt.Fprintf(c, "num_symbols: 1\n")
var b *bufio.Reader
if r.Method == "POST" {
b = bufio.NewReader(r.Body)
} else {
b = bufio.NewReader(strings.NewReader(r.URL.RawQuery))
}
for {
w, err := b.ReadSlice('+')
if err == nil {
w = w[0 : len(w)-1] // trim +
}
pc, _ := strconv.Btoui64(string(w), 0)
if pc != 0 {
f := runtime.FuncForPC(uintptr(pc))
if f != nil {
fmt.Fprintf(c, "%#x %s\n", pc, f.Name())
}
}
// Wait until here to check for err; the last
// symbol will have an err because it doesn't end in +.
if err != nil {
break
}
}
}
示例2: parseScript
func parseScript(line string, scripts map[string][]Script) {
comment := strings.Index(line, "#")
if comment >= 0 {
line = line[0:comment]
}
line = strings.TrimSpace(line)
if len(line) == 0 {
return
}
field := strings.Split(line, ";")
if len(field) != 2 {
logger.Fatalf("%s: %d fields (expected 2)\n", line, len(field))
}
matches := scriptRe.FindStringSubmatch(line)
if len(matches) != 4 {
logger.Fatalf("%s: %d matches (expected 3)\n", line, len(matches))
}
lo, err := strconv.Btoui64(matches[1], 16)
if err != nil {
logger.Fatalf("%.5s...: %s", line, err)
}
hi := lo
if len(matches[2]) > 2 { // ignore leading ..
hi, err = strconv.Btoui64(matches[2][2:], 16)
if err != nil {
logger.Fatalf("%.5s...: %s", line, err)
}
}
name := matches[3]
scripts[name] = append(scripts[name], Script{uint32(lo), uint32(hi), name})
}
示例3: single_rune
// Consume a single rune; assumes this is being invoked as the last possible
// option and will panic if an invalid escape sequence is found. Will return the
// found rune (as an integer) and with cursor past the entire representation.
func (p *parser) single_rune() int {
if rune := p.src.curr(); rune != '\\' {
// This is just a regular character; return it immediately.
p.src.nextCh()
return rune
}
if p.src.peek() == 'x' {
// Match hex character code.
var hex string
p.src.nextCh()
if p.src.nextCh() == '{' {
hex = p.src.literal("{", "}")
} else {
hex = fmt.Sprintf("%c%c", p.src.curr(), p.src.nextCh())
p.src.nextCh() // Step over the end of the hex code.
}
// Parse and return the corresponding rune.
rune, err := strconv.Btoui64(hex, 16)
if err != nil {
panic(fmt.Sprintf("couldn't parse hex: %s", hex))
}
return int(rune)
} else if rune := ESCAPES[p.src.peek()]; rune != 0 {
// Literally match '\n', '\r', etc.
p.src.nextCh()
p.src.nextCh()
return rune
} else if unicode.Is(_punct, p.src.peek()) {
// Allow punctuation to be blindly escaped.
rune := p.src.nextCh()
p.src.nextCh()
return rune
} else if unicode.IsDigit(p.src.peek()) {
// Match octal character code (begins with digit, up to three digits).
oct := ""
p.src.nextCh()
for i := 0; i < 3; i++ {
oct += fmt.Sprintf("%c", p.src.curr())
if !unicode.IsDigit(p.src.nextCh()) {
break
}
}
// Parse and return the corresponding rune.
rune, err := strconv.Btoui64(oct, 8)
if err != nil {
panic(fmt.Sprintf("couldn't parse oct: %s", oct))
}
return int(rune)
}
// This is an escape sequence which does not identify a single rune.
panic(fmt.Sprintf("not a valid escape sequence: \\%c", p.src.peek()))
}
示例4: beginChunk
func (cr *chunkedReader) beginChunk() {
// chunk-size CRLF
var line string
line, cr.err = readLine(cr.r)
if cr.err != nil {
return
}
cr.n, cr.err = strconv.Btoui64(line, 16)
if cr.err != nil {
return
}
if cr.n == 0 {
// trailer CRLF
for {
line, cr.err = readLine(cr.r)
if cr.err != nil {
return
}
if line == "" {
break
}
}
cr.err = os.EOF
}
}
示例5: serveSymbol
func serveSymbol(req *web.Request) {
var p []byte
if req.Method == "POST" {
var err os.Error
p, err = req.BodyBytes(-1)
if err != nil {
req.Error(web.StatusInternalServerError, err)
return
}
} else {
p = []byte(req.URL.RawQuery)
}
w := respondText(req)
io.WriteString(w, "num_symbols: 1\n")
for len(p) > 0 {
var a []byte
if i := bytes.IndexByte(p, '+'); i >= 0 {
a = p[:i]
p = p[i+1:]
} else {
a = p
p = nil
}
if pc, _ := strconv.Btoui64(string(a), 0); pc != 0 {
if f := runtime.FuncForPC(uintptr(pc)); f != nil {
fmt.Fprintf(w, "%#x %s\n", pc, f.Name())
}
}
}
}
示例6: scanUint
// scanUint returns the value of the unsigned integer represented
// by the next token, checking for overflow. Any error is stored in s.err.
func (s *ss) scanUint(verb int, bitSize int) uint64 {
if verb == 'c' {
return uint64(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 if verb == 'v' {
base, digits, haveDigits = s.scanBasePrefix()
}
tok := s.scanNumber(digits, haveDigits)
i, err := strconv.Btoui64(tok, base)
if err != nil {
s.error(err)
}
n := uint(bitSize)
x := (i << (64 - n)) >> (64 - n)
if x != i {
s.errorString("unsigned integer overflow on token " + tok)
}
return i
}
示例7: TestRunServer
func TestRunServer(t *testing.T) {
if !*serve {
return
}
suites := strings.Split(*testCipherSuites, ",")
testConfig.CipherSuites = make([]uint16, len(suites))
for i := range suites {
suite, err := strconv.Btoui64(suites[i], 0)
if err != nil {
panic(err)
}
testConfig.CipherSuites[i] = uint16(suite)
}
l, err := Listen("tcp", ":10443", testConfig)
if err != nil {
t.Fatal(err)
}
for {
c, err := l.Accept()
if err != nil {
break
}
_, err = c.Write([]byte("hello, world\n"))
if err != nil {
t.Errorf("error from TLS: %s", err)
break
}
c.Close()
}
}
示例8: Mknod
func Mknod(call []string) error {
e := flagSet.Parse(call[1:])
if e != nil {
return e
}
if flagSet.NArg() != 1 || *helpFlag {
println("`mknod` [options] <file>")
flagSet.PrintDefaults()
return nil
}
mode, ok := typemap[strings.ToLower(*typeFlag)]
if !ok {
return errors.New("Invalid node type \"" + *typeFlag + "\"")
}
if mode == syscall.S_IFBLK && (*majorFlag == -1 || *minorFlag == -1) {
return errors.New("When creating a block device, both minor and major number have to be given")
}
fmode, e := strconv.Btoui64(*modeFlag, 8)
if e != nil {
return e
}
mode |= uint32(fmode)
e = syscall.Mknod(flagSet.Arg(0), mode, *majorFlag<<8|*minorFlag)
return e
}
示例9: hexPairToByte
func hexPairToByte(rune1 int, rune2 int) byte {
// TODO: this one is slowpoke probably
s := string([]byte{byte(rune1), byte(rune2)})
ui, err := strconv.Btoui64(s, 16)
if err != nil {
panic(err)
}
return byte(ui)
}
示例10: loadCasefold
func loadCasefold() {
if *casefoldingURL == "" {
flag.Set("casefolding", *url+"CaseFolding.txt")
}
resp, err := http.Get(*casefoldingURL)
if err != nil {
logger.Fatal(err)
}
if resp.StatusCode != 200 {
logger.Fatal("bad GET status for CaseFolding.txt", resp.Status)
}
input := bufio.NewReader(resp.Body)
for {
line, err := input.ReadString('\n')
if err != nil {
if err == os.EOF {
break
}
logger.Fatal(err)
}
if line[0] == '#' {
continue
}
field := strings.Split(line, "; ")
if len(field) != 4 {
logger.Fatalf("CaseFolding.txt %.5s...: %d fields (expected %d)\n", line, len(field), 4)
}
kind := field[1]
if kind != "C" && kind != "S" {
// Only care about 'common' and 'simple' foldings.
continue
}
p1, err := strconv.Btoui64(field[0], 16)
if err != nil {
logger.Fatalf("CaseFolding.txt %.5s...: %s", line, err)
}
p2, err := strconv.Btoui64(field[2], 16)
if err != nil {
logger.Fatalf("CaseFolding.txt %.5s...: %s", line, err)
}
chars[p1].foldCase = int(p2)
}
resp.Body.Close()
}
示例11: getu4
// getu4 decodes \uXXXX from the beginning of s, returning the hex value,
// or it returns -1.
func getu4(s []byte) int {
if len(s) < 6 || s[0] != '\\' || s[1] != 'u' {
return -1
}
rune, err := strconv.Btoui64(string(s[2:6]), 16)
if err != nil {
return -1
}
return int(rune)
}
示例12: getu4
// getu4 decodes \uXXXX from the beginning of s, returning the hex value,
// or it returns -1.
func getu4(s []byte) rune {
if len(s) < 6 || s[0] != '\\' || s[1] != 'u' {
return -1
}
r, err := strconv.Btoui64(string(s[2:6]), 16)
if err != nil {
return -1
}
return rune(r)
}
示例13: letterValue
func (char *Char) letterValue(s string, cas string) int {
if s == "" {
return 0
}
v, err := strconv.Btoui64(s, 16)
if err != nil {
char.dump(cas)
logger.Fatalf("%U: bad letter(%s): %s", char.codePoint, s, err)
}
return int(v)
}
示例14: letterValue
func (char *Char) letterValue(s string, cas string) int {
if s == "" {
return 0
}
v, err := strconv.Btoui64(s, 16);
if err != nil {
char.dump(cas);
die.Logf("U+%04x: bad letter(%s): %s", char.codePoint, s, err);
}
return int(v);
}
示例15: parseScript
func parseScript(line string, scripts map[string][]Script) {
comment := strings.Index(line, "#");
if comment >= 0 {
line = line[0:comment]
}
line = strings.TrimSpace(line);
if len(line) == 0 {
return
}
field := strings.Split(line, ";", -1);
if len(field) != 2 {
die.Logf("%s: %d fields (expected 2)\n", line, len(field))
}
matches := scriptRe.MatchStrings(line);
if len(matches) != 4 {
die.Logf("%s: %d matches (expected 3)\n", line, len(matches))
}
lo, err := strconv.Btoui64(matches[1], 16);
if err != nil {
die.Log("%.5s...:", err)
}
hi := lo;
if len(matches[2]) > 2 { // ignore leading ..
hi, err = strconv.Btoui64(matches[2][2:len(matches[2])], 16);
if err != nil {
die.Log("%.5s...:", err)
}
}
name := matches[3];
s, ok := scripts[name];
if !ok || len(s) == cap(s) {
ns := make([]Script, len(s), len(s)+100);
for i, sc := range s {
ns[i] = sc
}
s = ns;
}
s = s[0 : len(s)+1];
s[len(s)-1] = Script{uint32(lo), uint32(hi), name};
scripts[name] = s;
}