-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmt: no padding is applied for "%x" or "%X" #10465
Comments
some issues i encountered while reintroducing the padding with the changes of #10430 in mind: if padding is applied on a per element basis precision should likely too: However there are existing test cases that apply it to the whole slice: I think there are at least 3 options that can be implemented to format byte slices while correcting the padding:
Also should change the doc "' ' (space) leave a space for elided sign in numbers (% d); If there should still be spaces between elements then specifying "% x" would have the (likely unintended) side effect of introducing spaces between elements and adding a space for each byte element in place of sign at the same time.
|
There are some things that need to be thought about here and there are also conflicts in the documentation. For example, it says that "% x" puts spaces between the elements, which implies the first element should not have a space before it, and I believe that is correct and desired behavior, while on the other hand it says the format applies to all elements, which presumably applies to the first. This is not an urgent issue and resolving it may break some things, so I am deferring it until 1.6. |
The documentation says:
The behavior is consistent with that sentence: The entire item is padded, while the 0 and space flags do apply elementwise, as one would expect. |
go version devel +9402e49 Wed Apr 15 05:03:42 2015 +0000 darwin/amd64
testcases to see no padding is applied to strings and byte slices:
#10430
has clarified it is per element for byte slices. However after the change currently no padding seems to be applied since the loop mentioned there does not apply it. It only adds a single space for each element or "0x" but not a general padding.
Also strings and byte slice then as far as i understood need to be handled with differing padding logic as the strings needs to be padded as a whole not hex by hex.
would this be the intended behavior?
Its a bit unclear now to me how and if both of these statements should be applied to the examples:
%x base 16, lower-case, two characters per byte
%X base 16, upper-case, two characters per byte"
P.S.
I will try to supply a patch to add padding back based on my nearly ready prepared patch to not use a buffer but adding the padding directly.
The text was updated successfully, but these errors were encountered: