Class TitleCaseSanitizer

java.lang.Object
io.github.rabinarayanpatra.sanitizer.builtin.TitleCaseSanitizer
All Implemented Interfaces:
FieldSanitizer<String>

public class TitleCaseSanitizer extends Object implements FieldSanitizer<String>
Sanitizer that converts the input string to title case by capitalizing the first character of each word and lowercasing the rest.

Leading and trailing whitespace is trimmed first. If the input is null or blank, it is returned as-is.

 
 String input = "  heLLo WoRLd ";
 String sanitized = new TitleCaseSanitizer().sanitize(input); // "Hello World"
 
 
Since:
1.0.0
See Also:
  • Constructor Details

    • TitleCaseSanitizer

      public TitleCaseSanitizer()
      Default constructor.
  • Method Details

    • sanitize

      public @Nullable String sanitize(@Nullable String input)
      Converts a trimmed string to title case (capitalizes the first letter of each word, lowercases the rest).
      Specified by:
      sanitize in interface FieldSanitizer<String>
      Parameters:
      input - the string to sanitize
      Returns:
      the title-cased string, or the original input if it is null or blank