java.lang.Object
me.hugmanrique.cartage.util.StringUtils
Provides
String-related utilities.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringReturns a string of the given length, consisting ofstringfollowed by as many instances ofpadCharas necessary to reach that length.static voidrequireLength(CharSequence sequence, int length)Ensures the length of the given sequence islength.static voidrequireMaxLength(CharSequence sequence, int maxLength)Ensures the length of the given sequence is less than or equal tomaxLength.static voidrequireUppercaseAscii(String string)Ensures the given string is composed of uppercase ASCII characters, spaces, and null terminators (\0).static voidrequireUppercaseAscii(String string, boolean acceptNullTerminators)Ensures the given string is composed of uppercase ASCII characters and spaces, ignoring null terminators (\0) if specified.
-
Method Details
-
requireLength
Ensures the length of the given sequence islength.- Parameters:
sequence- the sequence to checklength- the expected length- Throws:
IllegalArgumentException- if the length of the sequence is notlength
-
requireMaxLength
Ensures the length of the given sequence is less than or equal tomaxLength.- Parameters:
sequence- the sequence to checkmaxLength- the maximum length allowed- Throws:
IllegalArgumentException- if the length of the sequence is greater thanmaxLength
-
requireUppercaseAscii
Ensures the given string is composed of uppercase ASCII characters, spaces, and null terminators (\0).- Parameters:
string- the string to check- Throws:
IllegalArgumentException- if the string contains non-ASCII or non-uppercase characters
-
requireUppercaseAscii
Ensures the given string is composed of uppercase ASCII characters and spaces, ignoring null terminators (\0) if specified.- Parameters:
string- the string to checkacceptNullTerminators- whether to ignore null terminators- Throws:
IllegalArgumentException- if the string contains non-ASCII or non-uppercase characters
-
padEnd
Returns a string of the given length, consisting ofstringfollowed by as many instances ofpadCharas necessary to reach that length.- Parameters:
string- the string to padlength- the length of the returned stringpadChar- the character to append at the end of the string- Returns:
- the padded string
- Throws:
IllegalArgumentException- ifstring.length() > length
-