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
Modifier and TypeMethodDescriptionstatic StringtoCase(CaseFormat caseFormat, String input) Convertsinputstring to using the givenCaseFormat.
-
Constructor Details
-
CaseFormats
public CaseFormats()
-
-
Method Details
-
toCase
Convertsinputstring to using the givenCaseFormat.inputcan be insnake_case,lowerCamelCase,UpperCamelCase,CONSTANT_CASE,dash-caseor 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
CaseFormatonly 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).
-