Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
825f8c14
Commit
825f8c14
authored
Aug 25, 2011
by
Mikio Hara
Committed by
Russ Cox
Aug 25, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net: move internal string manipulation routines to parse.go
R=rsc CC=golang-dev
https://golang.org/cl/4968044
parent
78963f4f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
47 deletions
+44
-47
src/pkg/net/interface.go
src/pkg/net/interface.go
+0
-12
src/pkg/net/ip.go
src/pkg/net/ip.go
+1
-35
src/pkg/net/parse.go
src/pkg/net/parse.go
+43
-0
No files found.
src/pkg/net/interface.go
View file @
825f8c14
...
@@ -83,18 +83,6 @@ error:
...
@@ -83,18 +83,6 @@ error:
return
nil
,
os
.
NewError
(
"invalid MAC address: "
+
s
)
return
nil
,
os
.
NewError
(
"invalid MAC address: "
+
s
)
}
}
// xtoi2 converts the next two hex digits of s into a byte.
// If s is longer than 2 bytes then the third byte must be e.
// If the first two bytes of s are not hex digits or the third byte
// does not match e, false is returned.
func
xtoi2
(
s
string
,
e
byte
)
(
byte
,
bool
)
{
if
len
(
s
)
>
2
&&
s
[
2
]
!=
e
{
return
0
,
false
}
n
,
ei
,
ok
:=
xtoi
(
s
[
:
2
],
0
)
return
byte
(
n
),
ok
&&
ei
==
2
}
// Interface represents a mapping between network interface name
// Interface represents a mapping between network interface name
// and index. It also represents network interface facility
// and index. It also represents network interface facility
// information.
// information.
...
...
src/pkg/net/ip.go
View file @
825f8c14
...
@@ -230,40 +230,6 @@ func (ip IP) Mask(mask IPMask) IP {
...
@@ -230,40 +230,6 @@ func (ip IP) Mask(mask IPMask) IP {
return
out
return
out
}
}
// Convert i to decimal string.
func
itod
(
i
uint
)
string
{
if
i
==
0
{
return
"0"
}
// Assemble decimal in reverse order.
var
b
[
32
]
byte
bp
:=
len
(
b
)
for
;
i
>
0
;
i
/=
10
{
bp
--
b
[
bp
]
=
byte
(
i
%
10
)
+
'0'
}
return
string
(
b
[
bp
:
])
}
// Convert i to hexadecimal string.
func
itox
(
i
uint
)
string
{
if
i
==
0
{
return
"0"
}
// Assemble hexadecimal in reverse order.
var
b
[
32
]
byte
bp
:=
len
(
b
)
for
;
i
>
0
;
i
/=
16
{
bp
--
b
[
bp
]
=
"0123456789abcdef"
[
byte
(
i
%
16
)]
}
return
string
(
b
[
bp
:
])
}
// String returns the string form of the IP address ip.
// String returns the string form of the IP address ip.
// If the address is an IPv4 address, the string representation
// If the address is an IPv4 address, the string representation
// is dotted decimal ("74.125.19.99"). Otherwise the representation
// is dotted decimal ("74.125.19.99"). Otherwise the representation
...
@@ -317,7 +283,7 @@ func (ip IP) String() string {
...
@@ -317,7 +283,7 @@ func (ip IP) String() string {
}
else
if
i
>
0
{
}
else
if
i
>
0
{
s
+=
":"
s
+=
":"
}
}
s
+=
itox
((
uint
(
p
[
i
])
<<
8
)
|
uint
(
p
[
i
+
1
])
)
s
+=
itox
((
uint
(
p
[
i
])
<<
8
)
|
uint
(
p
[
i
+
1
]),
1
)
}
}
return
s
return
s
}
}
...
...
src/pkg/net/parse.go
View file @
825f8c14
...
@@ -159,6 +159,18 @@ func xtoi(s string, i0 int) (n int, i int, ok bool) {
...
@@ -159,6 +159,18 @@ func xtoi(s string, i0 int) (n int, i int, ok bool) {
return
n
,
i
,
true
return
n
,
i
,
true
}
}
// xtoi2 converts the next two hex digits of s into a byte.
// If s is longer than 2 bytes then the third byte must be e.
// If the first two bytes of s are not hex digits or the third byte
// does not match e, false is returned.
func
xtoi2
(
s
string
,
e
byte
)
(
byte
,
bool
)
{
if
len
(
s
)
>
2
&&
s
[
2
]
!=
e
{
return
0
,
false
}
n
,
ei
,
ok
:=
xtoi
(
s
[
:
2
],
0
)
return
byte
(
n
),
ok
&&
ei
==
2
}
// Integer to decimal.
// Integer to decimal.
func
itoa
(
i
int
)
string
{
func
itoa
(
i
int
)
string
{
var
buf
[
30
]
byte
var
buf
[
30
]
byte
...
@@ -181,6 +193,37 @@ func itoa(i int) string {
...
@@ -181,6 +193,37 @@ func itoa(i int) string {
return
string
(
buf
[
n
:
])
return
string
(
buf
[
n
:
])
}
}
// Convert i to decimal string.
func
itod
(
i
uint
)
string
{
if
i
==
0
{
return
"0"
}
// Assemble decimal in reverse order.
var
b
[
32
]
byte
bp
:=
len
(
b
)
for
;
i
>
0
;
i
/=
10
{
bp
--
b
[
bp
]
=
byte
(
i
%
10
)
+
'0'
}
return
string
(
b
[
bp
:
])
}
// Convert i to hexadecimal string.
func
itox
(
i
uint
,
min
int
)
string
{
// Assemble hexadecimal in reverse order.
var
b
[
32
]
byte
bp
:=
len
(
b
)
for
;
i
>
0
||
min
>
0
;
i
/=
16
{
bp
--
b
[
bp
]
=
"0123456789abcdef"
[
byte
(
i
%
16
)]
min
--
}
return
string
(
b
[
bp
:
])
}
// Number of occurrences of b in s.
// Number of occurrences of b in s.
func
count
(
s
string
,
b
byte
)
int
{
func
count
(
s
string
,
b
byte
)
int
{
n
:=
0
n
:=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment