commons-text
commons-text copied to clipboard
Cases API + 4 implementations (Pascal, Camel, Kebab, Snake)
This is a more formal API for parsing and formatting strings of various "Cases".
Similar logic is present in org.apache.commons.text.CaseUtils
as well as #360 to add two additional case functions, but that code is based around the initial string having delimiters, and cannot translate between cases. This API aims to be slightly more formal, expecting the inputs to the parse method to abide by the syntax of the case. No assumptions (other than the Case syntax) are made about the inputs, and removal of unwanted characters is left to the user. Case classes can be sub classed as necessary to support that.
The Case interface exposes two methods...
String format(Iterable<String> tokens)
List<String> parse(String string)
with parse() returning a List of String tokens, which can then be passed to another Case instance format() method. Allowing users to change the case of a string e.g. CamelCase.INSTANCE.format(KebabCase.INSTANCE.parse("my-kebab-string"))
. I followed the pattern of other commons-text classes in using code points rather than primitive chars (I assume to support UTF32).