Class CaseFormats
java.lang.Object
com.google.guava.labs.base.CaseFormats
Additional utilities pertaining to
CaseFormat
.
Warning: This class doesn't recognize supplementary code points.
- Since:
- 9.0
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
CaseFormats
public CaseFormats()
-
-
Method Details
-
toCase
Convertsinput
string to using the givenCaseFormat
.input
can be insnake_case
,lowerCamelCase
,UpperCamelCase
,CONSTANT_CASE
,dash-case
or any combination thereof. For example:toCase(LOWER_CAMEL, "user_id") => "userId" toCase(LOWER_HYPHEN, "UserID") => "user-id" toCase(UPPER_UNDERSCORE, "orderId") => "ORDER_ID" toCase(LOWER_UNDERSCORE, "primaryUser.userId") => "primary_user.user_id"
Given that
CaseFormat
only handles ascii, characters outside of the range of[a-zA-Z0-9_-]
(e.g. whitespaces, parenthesis, non-ascii) are passed through as is. If you need to support non-ascii camel case such as Greek upper case ('Β') and lower case ('β'), consider usingCaseBreaker.breakCase(java.lang.CharSequence)
to break up words in the source and then apply target casing manually using e.g.Character.toLowerCase(char)
.
-