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
d90d0ede
Commit
d90d0ede
authored
Nov 29, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fmt: allow "% X" as well as "% x"
R=rsc, cw, PeterGo CC=golang-dev
https://golang.org/cl/3319042
parent
abb0c096
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
2 deletions
+6
-2
doc.go
src/pkg/fmt/doc.go
+1
-1
fmt_test.go
src/pkg/fmt/fmt_test.go
+2
-1
format.go
src/pkg/fmt/format.go
+3
-0
No files found.
src/pkg/fmt/doc.go
View file @
d90d0ede
...
...
@@ -58,7 +58,7 @@
0X for hex (%#X); suppress 0x for %p (%#p);
print a raw (backquoted) string if possible for %q (%#q)
' ' (space) leave a space for elided sign in numbers (% d);
put spaces between bytes printing strings or slices in hex (% x)
put spaces between bytes printing strings or slices in hex (% x
, % X
)
0 pad with leading zeros rather than spaces
For each Printf-like function, there is also a Print function
...
...
src/pkg/fmt/fmt_test.go
View file @
d90d0ede
...
...
@@ -121,7 +121,8 @@ var fmttests = []fmtTest{
// basic bytes
{
"%s"
,
[]
byte
(
"abc"
),
"abc"
},
{
"%x"
,
[]
byte
(
"abc"
),
"616263"
},
{
"% x"
,
[]
byte
(
"abc"
),
"61 62 63"
},
{
"% x"
,
[]
byte
(
"abc
\xff
"
),
"61 62 63 ff"
},
{
"% X"
,
[]
byte
(
"abc
\xff
"
),
"61 62 63 FF"
},
{
"%x"
,
[]
byte
(
"xyz"
),
"78797a"
},
{
"%X"
,
[]
byte
(
"xyz"
),
"78797A"
},
{
"%q"
,
[]
byte
(
"abc"
),
`"abc"`
},
...
...
src/pkg/fmt/format.go
View file @
d90d0ede
...
...
@@ -255,6 +255,9 @@ func (f *fmt) fmt_sx(s string) {
func
(
f
*
fmt
)
fmt_sX
(
s
string
)
{
t
:=
""
for
i
:=
0
;
i
<
len
(
s
);
i
++
{
if
i
>
0
&&
f
.
space
{
t
+=
" "
}
v
:=
s
[
i
]
t
+=
string
(
udigits
[
v
>>
4
])
t
+=
string
(
udigits
[
v
&
0xF
])
...
...
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