Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
6524b82f
Commit
6524b82f
authored
Nov 03, 2008
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ascii to unsigned integer
R=rsc DELTA=60 (35 added, 17 deleted, 8 changed) OCL=18339 CL=18343
parent
f618f894
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
19 deletions
+37
-19
strings.go
src/lib/strings.go
+37
-19
No files found.
src/lib/strings.go
View file @
6524b82f
...
...
@@ -116,23 +116,9 @@ export func join(a *[]string, sep string) string {
return
string
(
b
)
}
// Convert decimal string to integer.
// Convert decimal string to
unsigned
integer.
// TODO: Doesn't check for overflow.
export
func
atol
(
s
string
)
(
i
int64
,
ok
bool
)
{
// empty string bad
if
len
(
s
)
==
0
{
return
0
,
false
}
// pick off leading sign
neg
:=
false
;
if
s
[
0
]
==
'+'
{
s
=
s
[
1
:
len
(
s
)]
}
else
if
s
[
0
]
==
'-'
{
neg
=
true
;
s
=
s
[
1
:
len
(
s
)]
}
export
func
atoui64
(
s
string
)
(
i
uint64
,
ok
bool
)
{
// empty string bad
if
len
(
s
)
==
0
{
return
0
,
false
...
...
@@ -149,21 +135,53 @@ export func atol(s string) (i int64, ok bool) {
}
// parse number
n
:=
int64
(
0
);
n
:=
u
int64
(
0
);
for
i
:=
0
;
i
<
len
(
s
);
i
++
{
if
s
[
i
]
<
'0'
||
s
[
i
]
>
'9'
{
return
0
,
false
}
n
=
n
*
10
+
int64
(
s
[
i
]
-
'0'
)
n
=
n
*
10
+
u
int64
(
s
[
i
]
-
'0'
)
}
return
n
,
true
}
// Convert decimal string to integer.
// TODO: Doesn't check for overflow.
export
func
atoi64
(
s
string
)
(
i
int64
,
ok
bool
)
{
// empty string bad
if
len
(
s
)
==
0
{
return
0
,
false
}
// pick off leading sign
neg
:=
false
;
if
s
[
0
]
==
'+'
{
s
=
s
[
1
:
len
(
s
)]
}
else
if
s
[
0
]
==
'-'
{
neg
=
true
;
s
=
s
[
1
:
len
(
s
)]
}
var
un
uint64
;
un
,
ok
=
atoui64
(
s
);
if
!
ok
{
return
0
,
false
}
n
:=
int64
(
un
);
if
neg
{
n
=
-
n
}
return
n
,
true
}
export
func
atoui
(
s
string
)
(
i
uint
,
ok
bool
)
{
ii
,
okok
:=
atoui64
(
s
);
i
=
uint
(
ii
);
return
i
,
okok
}
export
func
atoi
(
s
string
)
(
i
int
,
ok
bool
)
{
ii
,
okok
:=
ato
l
(
s
);
ii
,
okok
:=
ato
i64
(
s
);
i
=
int
(
ii
);
return
i
,
okok
}
...
...
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