mirror of
https://github.com/rocky-linux/peridot.git
synced 2024-10-19 07:55:07 +00:00
ad0f7a5305
Upgrade to Go 1.20.5, Hydra v2 SDK, rules-go v0.44.2 (with proper resolves), protobuf v25.3 and mass upgrade of Go dependencies.
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
// Copyright 2009 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Simple file i/o and string manipulation, to avoid
|
|
// depending on strconv and bufio and strings.
|
|
|
|
package net
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// NOTE: This file was forked because it is used by other code that needed to
|
|
// be forked, not because it is used on its own.
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Bigger than we need, not too big to worry about overflow
|
|
const big = 0xFFFFFF
|
|
|
|
// Decimal to integer.
|
|
// Returns number, characters consumed, success.
|
|
func dtoi(s string) (n int, i int, ok bool) {
|
|
n = 0
|
|
for i = 0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
|
n = n*10 + int(s[i]-'0')
|
|
if n >= big {
|
|
return big, i, false
|
|
}
|
|
}
|
|
if i == 0 {
|
|
return 0, 0, false
|
|
}
|
|
return n, i, true
|
|
}
|
|
|
|
// Hexadecimal to integer.
|
|
// Returns number, characters consumed, success.
|
|
func xtoi(s string) (n int, i int, ok bool) {
|
|
n = 0
|
|
for i = 0; i < len(s); i++ {
|
|
if '0' <= s[i] && s[i] <= '9' {
|
|
n *= 16
|
|
n += int(s[i] - '0')
|
|
} else if 'a' <= s[i] && s[i] <= 'f' {
|
|
n *= 16
|
|
n += int(s[i]-'a') + 10
|
|
} else if 'A' <= s[i] && s[i] <= 'F' {
|
|
n *= 16
|
|
n += int(s[i]-'A') + 10
|
|
} else {
|
|
break
|
|
}
|
|
if n >= big {
|
|
return 0, i, false
|
|
}
|
|
}
|
|
if i == 0 {
|
|
return 0, i, false
|
|
}
|
|
return n, i, true
|
|
}
|