mkodekar / guava-libraries

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

Case Formatter handling of accronym from camel Case #1783

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When converting a caml case String to Upper snake case the desired handling 
would be to consider the accronym (aka substring of only upcase caracters) as a 
single word. Instead the converter treats all consecutive upcase caracter as a 
single word.

Reproduce: System.out.println(LOWER_CAMEL.to(UPPER_UNDERSCORE, "ISBN"));
(guava 17)

Result: I_S_B_N

Desired Output: ISBN

Original issue reported on code.google.com by abecc...@mantano.com on 16 Jun 2014 at 2:48

GoogleCodeExporter commented 9 years ago
FYI, in upper camel case (at least using the style we recommend for 
Java--obviously there are other views on this), an acronym like ISBN should be 
written "Isbn", in which case you get "ISBN" as desired. In lower camel case, 
it'd just be "isbn".

Whether or not we want to change the behavior is a different story, though my 
inclination is somewhat against it unless we're sure it's harmless to existing 
usages.

Original comment by cgdecker@google.com on 16 Jun 2014 at 3:42

GoogleCodeExporter commented 9 years ago
I know It should be the case but even java api is not consistent with acronyms 
in camel case (ex: URL,HttpHeaders,..). 

Forget about this, it might broke for sure existing usage, and a found a way 
around by having a pre-treatment where i convert acronym to real camel case 
using the following pattern:
  /(?<=\p{Lower}|\A)(\p{Upper}+)(?=(\p{Upper}\p{Lower})|\Z)/  (groovy string)

:)

Original comment by abecc...@mantano.com on 18 Jun 2014 at 12:12

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

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

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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

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