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
37b17873
Commit
37b17873
authored
Feb 11, 2011
by
Luuk van Dijk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flag: allow hexadecimal and octal input for integer flags.
R=r CC=golang-dev
https://golang.org/cl/4182043
parent
28a23694
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
7 deletions
+7
-7
src/pkg/flag/flag.go
src/pkg/flag/flag.go
+4
-4
src/pkg/flag/flag_test.go
src/pkg/flag/flag_test.go
+3
-3
No files found.
src/pkg/flag/flag.go
View file @
37b17873
...
...
@@ -96,7 +96,7 @@ func newIntValue(val int, p *int) *intValue {
}
func
(
i
*
intValue
)
Set
(
s
string
)
bool
{
v
,
err
:=
strconv
.
Atoi
(
s
)
v
,
err
:=
strconv
.
Btoi64
(
s
,
0
)
*
i
=
intValue
(
v
)
return
err
==
nil
}
...
...
@@ -112,7 +112,7 @@ func newInt64Value(val int64, p *int64) *int64Value {
}
func
(
i
*
int64Value
)
Set
(
s
string
)
bool
{
v
,
err
:=
strconv
.
Atoi64
(
s
)
v
,
err
:=
strconv
.
Btoi64
(
s
,
0
)
*
i
=
int64Value
(
v
)
return
err
==
nil
}
...
...
@@ -128,7 +128,7 @@ func newUintValue(val uint, p *uint) *uintValue {
}
func
(
i
*
uintValue
)
Set
(
s
string
)
bool
{
v
,
err
:=
strconv
.
Atoui
(
s
)
v
,
err
:=
strconv
.
Btoui64
(
s
,
0
)
*
i
=
uintValue
(
v
)
return
err
==
nil
}
...
...
@@ -144,7 +144,7 @@ func newUint64Value(val uint64, p *uint64) *uint64Value {
}
func
(
i
*
uint64Value
)
Set
(
s
string
)
bool
{
v
,
err
:=
strconv
.
Atoui64
(
s
)
v
,
err
:=
strconv
.
Btoui64
(
s
,
0
)
*
i
=
uint64Value
(
v
)
return
err
==
nil
}
...
...
src/pkg/flag/flag_test.go
View file @
37b17873
...
...
@@ -106,7 +106,7 @@ func TestParse(t *testing.T) {
"-bool"
,
"-bool2=true"
,
"--int"
,
"22"
,
"--int64"
,
"23"
,
"--int64"
,
"
0x
23"
,
"-uint"
,
"24"
,
"--uint64"
,
"25"
,
"-string"
,
"hello"
,
...
...
@@ -125,8 +125,8 @@ func TestParse(t *testing.T) {
if
*
intFlag
!=
22
{
t
.
Error
(
"int flag should be 22, is "
,
*
intFlag
)
}
if
*
int64Flag
!=
23
{
t
.
Error
(
"int64 flag should be 23, is "
,
*
int64Flag
)
if
*
int64Flag
!=
0x
23
{
t
.
Error
(
"int64 flag should be
0x
23, is "
,
*
int64Flag
)
}
if
*
uintFlag
!=
24
{
t
.
Error
(
"uint flag should be 24, is "
,
*
uintFlag
)
...
...
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