"\x7f"

648 views
Skip to first unread message

Gustavo Niemeyer

unread,
Jun 26, 2013, 2:25:20 PM6/26/13
to golan...@googlegroups.com
Is there a reason for fmt to display "\x7f" as "\x007f" in quoted strings?

http://play.golang.org/p/0sT5R-DDqN


gustavo @ http://niemeyer.net

Gustavo Niemeyer

unread,
Jun 26, 2013, 2:25:47 PM6/26/13
to golan...@googlegroups.com
On Wed, Jun 26, 2013 at 3:25 PM, Gustavo Niemeyer <gus...@niemeyer.net> wrote:
> Is there a reason for fmt to display "\x7f" as "\x007f" in quoted strings?

Sorry, I meant "\u007f".


gustavo @ http://niemeyer.net

Rob Pike

unread,
Jun 26, 2013, 2:28:57 PM6/26/13
to Gustavo Niemeyer, golan...@googlegroups.com
It's strconv, not fmt that's doing this.

http://play.golang.org/p/awxg5_ib5A

Not that that's an answer.

-rob

Jeremy Wall

unread,
Jun 26, 2013, 2:30:05 PM6/26/13
to Gustavo Niemeyer, golang-nuts
\x7f is the same as \u007f and the fmt package doesn't know which format you wrote it in so how should it choose in that situation? Any choice will be somewhat arbitrary.




gustavo @ http://niemeyer.net

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Rob Pike

unread,
Jun 26, 2013, 2:35:41 PM6/26/13
to Jeremy Wall, Gustavo Niemeyer, golang-nuts
The real answer: strconv.Quote uses \x only for characters less than
space. I'm sure the design has some history that ends at an arbitrary
decision in the infinite past.

I can't get excited about changing it; plus it's arguably an API change.

-rob

Gustavo Niemeyer

unread,
Jun 26, 2013, 2:42:53 PM6/26/13
to Rob Pike, Jeremy Wall, golang-nuts
On Wed, Jun 26, 2013 at 3:35 PM, Rob Pike <r...@golang.org> wrote:
> The real answer: strconv.Quote uses \x only for characters less than
> space.

It's a bit more involved: http://play.golang.org/p/sZ26RCvncQ

> I'm sure the design has some history that ends at an arbitrary
> decision in the infinite past.
>
> I can't get excited about changing it; plus it's arguably an API change.

I wouldn't take that as an API change, but it's not exactly exciting
either. Just seems arbitrary.


gustavo @ http://niemeyer.net

Rob Pike

unread,
Jun 26, 2013, 3:08:51 PM6/26/13
to Gustavo Niemeyer, Jeremy Wall, golang-nuts
It is arbitrary. Why do you care? That implies a non-arbitrary thought process.

-rob

Gustavo Niemeyer

unread,
Jun 26, 2013, 3:16:42 PM6/26/13
to Rob Pike, Jeremy Wall, golang-nuts
On Wed, Jun 26, 2013 at 4:08 PM, Rob Pike <r...@golang.org> wrote:
> It is arbitrary. Why do you care? That implies a non-arbitrary thought process.

Even if I agree, my brain tends to appreciate non-arbitrariness for
whatever reason. If I feed it things that look alike, it tends to spot
their meaning more quickly.


gustavo @ http://niemeyer.net

Zachary Collier

unread,
Mar 31, 2022, 1:40:53 AM3/31/22
to golang-nuts
9 years in the future:

This is why I cared: https://go.dev/play/p/F4GlQBQL7UC

It's the only ASCII character showing as Unicode. When testing, I was alarmed thinking I had an error, but it was inaccurately represented as Unicode.  
The length is accurate.  
  fmt.Printf("Byte 127 len: %d\n", len([]byte{127}))


peterGo

unread,
Mar 31, 2022, 2:40:55 AM3/31/22
to golang-nuts
Unicode Standard

C0 Controls and Basic Latin Range: 0000–007F

Control character 007F  = DELETE

Peter

Rob Pike

unread,
Mar 31, 2022, 2:42:34 AM3/31/22
to Zachary Collier, golang-nuts
It's odd, and the oddness comes from the strconv package. But it's not
incorrect.

It happens because \x7f is kinda sort not ASCII, at least as far as
strconv thinks. It's trivial to "fix", though, if a fix is necessary.

https://github.com/golang/go/issues/52062

-rob
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/60ad41f0-10d6-417d-a604-6a151c357d93n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages