Class CollapseWhitespaceSanitizer
java.lang.Object
io.github.rabinarayanpatra.sanitizer.builtin.CollapseWhitespaceSanitizer
- All Implemented Interfaces:
FieldSanitizer<String>
Sanitizer that trims leading and trailing whitespace and collapses internal
whitespace sequences into a single space.
Useful for cleaning up user input where excessive spacing may be present, such as names or addresses.
String input = " John Doe ";
String sanitized = new CollapseWhitespaceSanitizer().sanitize(input); // "John Doe"
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
CollapseWhitespaceSanitizer
public CollapseWhitespaceSanitizer()Default constructor.
-
-
Method Details
-
sanitize
Trims the input and replaces all runs of whitespace with a single space.- Specified by:
sanitizein interfaceFieldSanitizer<String>- Parameters:
in- the input string to sanitize- Returns:
- the sanitized string, or
nullif the input wasnull
-