dnrajugade / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Better toString for CharMatcher #1207

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The CharMatcher mixed hexadecimal and character representation. For example

CharMatcher.inRange('0', '9').or(CharMatcher.anyOf("40"))

gets printed as

CharMatcher.or(CharMatcher.inRange(30, 39), CharMatcher.anyOf("40"))

There are multiple minor issues:

- It's unsystematic, only `inRange`, `is` and `isNot` display their arguments 
as numbers.
- The number gets shown in hexadecimal without it getting indicated (as `0x30` 
or `'\u0030'` or whatever).
- The output suggests that there's a static method `CharMatcher.or`, which 
isn't true.

Ideally, the above output should exactly mirror the expression.

___

Possibly, non-printable characters are better to be replaced by something 
readable, e.g., `CharMatcher.anyOf("\n\r")` should ideally be output as given. 
However, the "printability" is highly subjective (there are billions of people 
considering U+7684 as printable, but I don't), so I'm not really suggesting 
anything here. Note that the need for escaping applies equally to `inRange` and 
`anyOf`.

___

The default `toString` for a user-created `CharMatcher` is 
`UnknownCharMatcher`, which is IMHO much worse than the Java default behavior 
(which returns a worse-looking but much more useful string). Changing it is 
trivial.

Original issue reported on code.google.com by Maaarti...@gmail.com on 18 Nov 2012 at 2:04

GoogleCodeExporter commented 9 years ago
Good find...Louis, do you want to have a look at this?

Original comment by kak@google.com on 21 Nov 2012 at 2:56

GoogleCodeExporter commented 9 years ago
My true preference would be to try to use escapers for this when they come 
along, but we can at least make it consistent in the meantime.

Original comment by lowas...@google.com on 21 Nov 2012 at 2:58

GoogleCodeExporter commented 9 years ago

Original comment by kak@google.com on 21 Nov 2012 at 4:06

GoogleCodeExporter commented 9 years ago

Original comment by lowas...@google.com on 26 Dec 2012 at 5:02

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08