Class CaseFormats

java.lang.Object
com.google.guava.labs.base.CaseFormats

@CheckReturnValue public final class CaseFormats extends Object
Additional utilities pertaining to CaseFormat.

Warning: This class doesn't recognize supplementary code points.

Since:
9.0
  • Constructor Details

    • CaseFormats

      public CaseFormats()
  • Method Details

    • toCase

      public static String toCase(com.google.common.base.CaseFormat caseFormat, String input)
      Converts input string to using the given CaseFormat. input can be in snake_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 using CaseBreaker.breakCase(java.lang.CharSequence) to break up words in the source and then apply target casing manually using e.g. Character.toLowerCase(char).