java.lang.Object
io.github.mmm.base.text.CaseSyntax
Defines the different styles of lower-/upper-case usage such as
The main idea is that you "parse" a given variable name syntax via
camlCase, train-case, etc. For further examples see the constants defined here in CaseSyntax.The main idea is that you "parse" a given variable name syntax via
ofExample(String, boolean) and then you
can transform the value of such variable via convert(String). As a small teaser and motivation here are some
examples assuming that the value for "VaraibleName" would be "MyValue":
| VariableSyntax | Result |
|---|---|
| VariableName | MyValue |
| variablename | myvalue |
| variable-name | my-value |
| VARIABLE_NAME | MY_VALUE |
| variableName | myValue |
- Since:
- 1.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CaseSyntaxCaseSyntaxforcamlCase(e.g.static final CaseSyntaxCaseSyntaxforcaml_Snake_Case.static final CaseSyntaxCaseSyntaxforcaml Space Case.static final CaseSyntaxCaseSyntaxforcaml-Train-Case.static final CaseSyntaxCaseSyntaxforC$$apitalized(only convert first char to upper case, keep other case untouched).static final CaseSyntaxCaseSyntaxforCapitalizedlower.static final CharacterTheword separatorused to keep any special (separator) characters untouched byconvert.static final CaseSyntaxCaseSyntaxforlower_snake_case(e.g.static final CaseSyntaxCaseSyntaxforlower space case.static final CaseSyntaxCaseSyntaxforlowercase(e.g.static final CaseSyntaxCaseSyntaxforPascalCase(e.g.static final CaseSyntaxCaseSyntaxforPascal_Snake_Case.static final CaseSyntaxCaseSyntaxforPascal Space Case.static final CaseSyntaxCaseSyntaxforPascal-Train-Case.static final CaseSyntaxCaseSyntaxfortrain-case(e.g.static final CaseSyntaxCaseSyntaxforu$$capitalized(only convert first char to lower case, keep other case untouched).static final CaseSyntaxCaseSyntaxforCapitalizedlower.static final CaseSyntaxCaseSyntaxfor$$$unmodified(keep all characters untouched).static final CaseSyntaxCaseSyntaxforUPPER_SNAKE_CASE(e.g.static final CaseSyntaxCaseSyntaxforUPPER SPACE CASE.static final CaseSyntaxCaseSyntaxforUPPER-TRAIN-CASE.static final CaseSyntaxCaseSyntaxforUPPERCASE. -
Method Summary
Modifier and TypeMethodDescriptionSame asconvert(String, Locale)with a standardLocaleto prevent accidental conversion.Converts to thisCaseSyntax.booleaninthashCode()booleanstatic StringnormalizeExample(String example) static CaseSyntaxof(Character separator, CaseConversion allCharCase) The constructor.static CaseSyntaxof(Character separator, CaseConversion firstCharCase, CaseConversion wordStartCharCase) The constructor.static CaseSyntaxof(Character separator, CaseConversion firstCharCase, CaseConversion wordStartCharCase, CaseConversion otherCharCase) static CaseSyntaxstatic CaseSyntaxtoString()
-
Field Details
-
KEEP_SPECIAL_CHARS
Theword separatorused to keep any special (separator) characters untouched byconvert. -
LOWERCASE
CaseSyntaxforlowercase(e.g. for Java package segments). -
UPPERCASE
CaseSyntaxforUPPERCASE. -
CAML_CASE
CaseSyntaxforcamlCase(e.g. for Java fields). -
PASCAL_CASE
CaseSyntaxforPascalCase(e.g. for Java types). -
TRAIN_CASE
CaseSyntaxfortrain-case(e.g. for URLs or Angular). -
UPPER_TRAIN_CASE
CaseSyntaxforUPPER-TRAIN-CASE. -
PASCAL_TRAIN_CASE
CaseSyntaxforPascal-Train-Case. -
CAML_TRAIN_CASE
CaseSyntaxforcaml-Train-Case. -
LOWER_SNAKE_CASE
CaseSyntaxforlower_snake_case(e.g. for Ruby). -
UPPER_SNAKE_CASE
CaseSyntaxforUPPER_SNAKE_CASE(e.g. for Java constants). -
PASCAL_SNAKE_CASE
CaseSyntaxforPascal_Snake_Case. -
CAML_SNAKE_CASE
CaseSyntaxforcaml_Snake_Case. -
LOWER_SPACE_CASE
CaseSyntaxforlower space case. -
UPPER_SPACE_CASE
CaseSyntaxforUPPER SPACE CASE. -
PASCAL_SPACE_CASE
CaseSyntaxforPascal Space Case. -
CAML_SPACE_CASE
CaseSyntaxforcaml Space Case. -
UNMODIFIED
CaseSyntaxfor$$$unmodified(keep all characters untouched). -
CAPITALIZED
CaseSyntaxforC$$apitalized(only convert first char to upper case, keep other case untouched). -
UNCAPITALIZED
CaseSyntaxforu$$capitalized(only convert first char to lower case, keep other case untouched). -
CAPITALIZED_LOWER
CaseSyntaxforCapitalizedlower. -
UNCAPITALIZED_UPPER
CaseSyntaxforCapitalizedlower.
-
-
Method Details
-
getWordSeparator
- Returns:
- the word separator char (e.g.
'_','-' or '.') ornullfor no word separator. The valueKEEP_SPECIAL_CHARScan be used to keep special characters untouched.
-
hasWordSeparator
public boolean hasWordSeparator()- Returns:
trueif theword separatorisnullor
-
getFirstCase
- Returns:
- the
CaseConversionused byconvert(String)for the first character.
-
getWordStartCase
- Returns:
- the
CaseConversionused byconvert(String)for word start characters (the first character of a new word except for thefirstcharacter of the entireString).
-
getOtherCase
- Returns:
- the
CaseConversionused byconvert(String)for all other characters (exceptfirstandword startcharacters).
-
convert
Same asconvert(String, Locale)with a standardLocaleto prevent accidental conversion.- Parameters:
string- theStringto convert.- Returns:
- the String converted to this
CaseSyntax.
-
convert
Converts to thisCaseSyntax. The first character will be converted usinggetFirstCase(). Characters other thanletters or digitsare considered as word separator. In the most cases, they will be- Parameters:
string- theStringto convert.locale- the explicitLocaleto use. In most cases you want to useconvert(String)instead.- Returns:
- the String converted to this
CaseSyntax.
-
equals
-
hashCode
public int hashCode() -
toString
-
of
The constructor.- Parameters:
separator- - seegetWordSeparator().allCharCase- theCaseConversionused forfirst,word-start, and allotheralphabetic characters.- Returns:
- the requested
CaseSyntax.
-
of
public static CaseSyntax of(Character separator, CaseConversion firstCharCase, CaseConversion wordStartCharCase) The constructor. Will useCaseConversion.LOWER_CASEforothercharacters.- Parameters:
separator- - seegetWordSeparator().firstCharCase- - seegetFirstCase().wordStartCharCase- - seegetWordStartCase().- Returns:
- the requested
CaseSyntax.
-
of
public static CaseSyntax of(Character separator, CaseConversion firstCharCase, CaseConversion wordStartCharCase, CaseConversion otherCharCase) - Parameters:
separator- - seegetWordSeparator().firstCharCase- - seegetFirstCase().wordStartCharCase- - seegetWordStartCase().otherCharCase- - seegetOtherCase().- Returns:
- the requested
CaseSyntax.
-
normalizeExample
- Parameters:
example- theexampleto normalize.- Returns:
- the normalized
example(in lower case with all special characters removed).
-
ofExample
- Parameters:
example- an example for the requestedCaseSyntaxsuch asPascalCaseorMyVariableNameforPASCAL_CASE. For further details seeofExample(String, boolean).- Returns:
- the
CaseSyntaxfor the givenexampleas described above. - See Also:
-
ofExample
- Parameters:
example- an example for the requestedCaseSyntaxsuch asPascalCaseorMyVariableNameforPASCAL_CASEandtrain-caseormy-variable-nameforTRAIN_CASE. See otherCaseSyntaxconstants for more examples. The givenexampleStringhas to start with aletterwith an underscore forKEEP_SPECIAL_CHARS, or with$-Sign) and contain at least two more such characters (letter or $-sign) next to each other. Digits are more or less ignored. If you use variable names as example consider naming such variables with more than one word and no characters other thanletters or digits. Otherwise you would have to write things such asComPonentorcom-ponentto indicate PascalCase or train-case for the variablecomponent. Also when using variables asCaseSyntaxexample you shouldnormalizeExample(String)normalize} them before resolving.standardize- -trueif existing constants such asPASCAL_CASEorTRAIN_CASEshall be returned ifequalto the requestedCaseSyntax,falseotherwise.- Returns:
- the
CaseSyntaxfor the givenexampleas described above.
-