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
c81d09d9
Commit
c81d09d9
authored
May 15, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement %#o %#x %#X formats
R=rsc OCL=28936 CL=28936
parent
66f5e890
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
1 deletion
+21
-1
fmt_test.go
src/lib/fmt/fmt_test.go
+6
-1
format.go
src/lib/fmt/format.go
+15
-0
No files found.
src/lib/fmt/fmt_test.go
View file @
c81d09d9
...
...
@@ -77,7 +77,6 @@ var fmttests = []fmtTest{
fmtTest
{
"%+d"
,
12345
,
"+12345"
},
fmtTest
{
"%+d"
,
-
12345
,
"-12345"
},
fmtTest
{
"% d"
,
12345
,
" 12345"
},
fmtTest
{
"% d"
,
-
12345
,
"-12345"
},
// arrays
fmtTest
{
"%v"
,
array
,
"[1 2 3 4 5]"
},
...
...
@@ -92,12 +91,15 @@ var fmttests = []fmtTest{
fmtTest
{
"%d"
,
uint32
(
b32
),
"4294967295"
},
fmtTest
{
"%d"
,
uint64
(
b64
),
"18446744073709551615"
},
fmtTest
{
"%o"
,
01234
,
"1234"
},
fmtTest
{
"%#o"
,
01234
,
"01234"
},
fmtTest
{
"%o"
,
uint32
(
b32
),
"37777777777"
},
fmtTest
{
"%o"
,
uint64
(
b64
),
"1777777777777777777777"
},
fmtTest
{
"%x"
,
0x1234abcd
,
"1234abcd"
},
fmtTest
{
"%#x"
,
0x1234abcd
,
"0x1234abcd"
},
fmtTest
{
"%x"
,
b32
-
0x1234567
,
"fedcba98"
},
fmtTest
{
"%X"
,
0x1234abcd
,
"1234ABCD"
},
fmtTest
{
"%X"
,
b32
-
0x1234567
,
"FEDCBA98"
},
fmtTest
{
"%#X"
,
0
,
"0X0"
},
fmtTest
{
"%x"
,
b64
,
"ffffffffffffffff"
},
fmtTest
{
"%b"
,
7
,
"111"
},
fmtTest
{
"%b"
,
b64
,
"1111111111111111111111111111111111111111111111111111111111111111"
},
...
...
@@ -125,6 +127,9 @@ var fmttests = []fmtTest{
fmtTest
{
"%20d"
,
1234
,
" 1234"
},
fmtTest
{
"%-20.8d"
,
1234
,
"00001234 "
},
fmtTest
{
"%-20.8d"
,
-
1234
,
"-00001234 "
},
fmtTest
{
"%-#20.8x"
,
0x1234abc
,
"0x01234abc "
},
fmtTest
{
"%-#20.8X"
,
0x1234abc
,
"0X01234ABC "
},
fmtTest
{
"%-#20.8o"
,
01234
,
"00001234 "
},
fmtTest
{
"%.20b"
,
7
,
"00000000000000000111"
},
fmtTest
{
"%20.5s"
,
"qwertyuiop"
,
" qwert"
},
fmtTest
{
"%.5s"
,
"qwertyuiop"
,
"qwert"
},
...
...
src/lib/fmt/format.go
View file @
c81d09d9
...
...
@@ -202,6 +202,21 @@ func (f *Fmt) integer(a int64, base uint, is_signed bool, digits *string) string
i
--
;
}
if
f
.
sharp
{
switch
base
{
case
8
:
if
buf
[
i
+
1
]
!=
'0'
{
buf
[
i
]
=
'0'
;
i
--
;
}
case
16
:
buf
[
i
]
=
'x'
+
digits
[
10
]
-
'a'
;
i
--
;
buf
[
i
]
=
'0'
;
i
--
;
}
}
if
negative
{
buf
[
i
]
=
'-'
;
i
--
;
...
...
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