Guava: Release SourceCodeEscapers

Created on 31 Oct 2014  路  10Comments  路  Source: google/guava

_Original issue created by [email protected] on 2013-12-19 at 07:40 PM_


Tasks:

  • Figure out the proper names for everything. (Internal bug 3102010, comment 10 has some principles for this.)
  • Determine which of the escapers for each language we actually want. One possible decision is that we want _none_ of the current escapers. For example, does it make sense for our Java escaper to escape printable non-ASCII characters, as it currently does? At least inside Google, our .java files are UTF-8. Considerations: If it _does_ make sense to escape them, then the escaper should perhaps be named "javaAsciiCharEscaper." Also, is there any chance that the set of characters that we _would_ need to escape would change over time? (For example, aren't there some other "newline-like" characters?) Or might it make sense to escape any confusable characters? Is there a standard enough set of confusable characters (maybe for domain names? though of course it might change), or would it be best to avoid non-ASCII altogether? Maybe this is reason to have both javaAsciiCharEscaper and javaCharEscaper ("javaUnicodeCharEscaper?").
P3 package=escape type=addition

All 10 comments

Hmm, is there any plan yet to open source the source code escapers? If not, we may want to consider closing this issue, because at this rate it looks like it's never going to happen. :)

@cushon has done so in GoogleJavaFormat (or ErrorProne, I don't remember?) but package-private. I think it's a question of API and not feasibility.

I wonder if we'd be willing to release it in a separate, small standalone library. It seems niche enough that maybe we could do that as we experiment with the API? But perhaps it needs some package-private details that would make that challenging.

Here's a slightly edited version of what I wrote internally just recently:

  • Do we really want to continue to have a single javaCharEscaper() / javaStringEscaper() that escapes both " and ' characters, or should we instead rename the existing method to javaCharOrStringEscaper(), migrate everyone to that, and then introduce separate javaCharEscaper() and javaStringEscaper() methods for those use specific cases? Users might be annoyed if we insert \' into their strings unnecessarily?

  • It's also not 100% clear that users want non-ASCII characters escaped in all cases. But we need to be careful about exotic line breaks and perhaps about easily confused characters.

  • If we do keep one escaper, is javaCharEscaper() the right name for it when probably most users will be escaping for strings?

(Of course we continue to recommend that most people use higher-level APIs. But someone has to write the low-level APIs that those people use :))

I don't imagine we'll do this unless someone comes along internally who is willing to survey the existing internal callers and see what features they actually want.

Just so I'm clear on this, if Google decides to keep javaCharEscaper() and open sources it, and/or does the same for javaStringEscaper(), would those escapers just escape ' into \' and " into \" respectively? Or would they affect other characters as well in some way?

And would you mind clarifying for me which APIs you're referring to when you say "higher-level APIs" and "low-level APIs"?

The escapers would escape other characters, too, like \n and control characters. We'd have to figure out exact details.

We encourage people to use tools like JavaPoet rather than manually escape strings.

Ah okay, understood and understood. :)

any update on opensourcing the source code escapers? We use it in an internal project that we are going to opensource

Sadly no. Cloning them to other projects remains sad but fairly easy and harmless (since they're static methods).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bocete picture Bocete  路  3Comments

thecoop picture thecoop  路  4Comments

terence1984 picture terence1984  路  3Comments

gissuebot picture gissuebot  路  5Comments

gissuebot picture gissuebot  路  5Comments