Strings class
A set of String utility functions that aim to extend the set of functions available the core String class as well as provding safe methods when working with nullable Strings. A Strings method will never thrown an NPE and aims to provide the expected result by treating the null as an empty String or a space filled String where a range access is applied.
The same approach is applied for non-null Strings when the strings length would result in a RangeError; Instead we pad the String to ensure code returns the expected length String and you code keesp running rather than crashing.
e.g.
Strings.substring(null, 2,3);
-> ' '
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
abbreviate(
String? string, int maxWidth, {int offset = 0}) → String -
Methods that deal with parts of a string.
Abbreviate a string to
maxWidth
by truncating the string and adding '...' to the truncated string. -
allMatches(
String? pattern, String string, [int start = 0]) → Iterable< Match> - Refer to String.allMatches
-
codeUnitAt(
String? string, int index) → int -
Refer to
Safe.codeUnitAt
-
codeUnits(
String? string) → List< int> - Refer to String.codeUnits
-
compareTo(
String? string, String? other, {bool nullIsLessThan = true}) → int -
Refer to
Safe.compareTo
-
contains(
String? string, Pattern other, [int startIndex = 0]) → bool -
Refer to
Safe.contains
-
endsWith(
String? string, String? other) → bool -
Refer to
Safe.endsWith
-
equals(
String? lhs, String? rhs) → bool - Safely compares two nullable strings.
-
equalsIgnoreCase(
String? lhs, String? rhs) → bool - Compare two nullable strings ignoring case.
-
hidePart(
String? string, {int start = 0, int? end, String replaceWith = '*'}) → String -
Obscures part of
string
by replace the characters betweenstart
(inclusive) andend
exclusive withreplaceWith
-
indexOf(
String? string, Pattern pattern, [int start = 0]) → int -
Refer to
Safe.indexOf
-
isAscii(
String? string) → bool -
returns true if
string
only contains ascii characters. (0 - 128) -
isBlank(
String? string) → bool -
Returns true if the
string
is null or Blank. -
isDigits(
String? string) → bool -
returns true if
string
only contains digits -
isEmpty(
String? string) → bool -
true if the
string
is null, or is a zero length String -
isLowerCase(
String? string) → bool -
Returns true if
string
does not contain upper case letters -
isNotBlank(
String? string) → bool -
Returns true if the
string
is not null and not Blank. -
isNotEmpty(
String? string) → bool -
true if the
string
is not null and is not a zero length String -
isNumeric(
String? string) → bool -
Checks if
string
is a number by attempting to parse it as a double. -
isPrintable(
int? character) → bool -
Returns true if
character
is a printable ascii character. -
isUpperCase(
String? string) → bool -
Returns true if
string
does not contain any lower case letters. -
isWhitespace(
String string) → bool -
returns true if the
string
only contains whitespace characters. We use the same definition of whitespace as String.trim. -
isWhitespaceRune(
int rune) → bool -
returns true if the
rune
is a whitespace characters. We use the same definition of whitespace as String.trim. -
join(
List< Object?> ? list, {String separator = '', bool excludeEmpty = false}) → String -
Returns the joined elements of the
list
. -
lastIndexOf(
String? string, Pattern pattern, [int? start]) → int -
Refer to
Safe.lastIndexOf
-
left(
String? string, int take, {Pad pad = Pad.none}) → String -
Returns left most
take
characters fromstring
. -
length(
String? string) → int - Refer to String.length
-
matchAsPrefix(
String? pattern, String string, [int start = 0]) → Match? -
Refer to
Safe.matchAsPrefix
-
orElse(
String? string, String elsestring) → String -
If
string
is not null, then returnstring
Ifstring
is null theelsestring
is returned -
orElseCall(
String? string, String elsestring()) → String -
If
string
is not null, then returnstring
Ifstring
is null, callselsestring
and return the result. -
orElseOnBlank(
String? string, String elseString) → String -
If the
string
is not blank then we returnstring
otherwise we returnelseString
-
padLeft(
String? string, int width, [String padding = ' ']) → String -
Refer to
Safe.padLeft
-
padRight(
String? string, int width, [String padding = ' ']) → String -
Refer to
Safe.padRight
-
replaceAll(
String? string, Pattern from, String replace) → String -
Refer to
Safe.replaceAll
-
replaceAllMapped(
String? string, Pattern from, String replace(Match match)) → String -
Refer to
Safe.replaceAllMapped
-
replaceFirst(
String? string, Pattern from, String to, [int startIndex = 0]) → String -
Refer to
Safe.replaceFirst
-
replaceFirstMapped(
String? string, Pattern from, String replace(Match match), [int startIndex = 0]) → String -
Refer to
Safe.replaceFirstMapped
-
replaceRange(
String? string, int start, int? end, String replacement) → String -
Refer to
Safe.replaceRange
-
reverse(
String? string) → String - Returns a string with reversed order of characters.
-
right(
String? string, int take, {Pad pad = Pad.none}) → String -
Returns the right most
take
characters fromstring
. -
runes(
String? string) → Runes - Refer to String.runes
-
split(
String? string, Pattern pattern) → List< String> -
Refer to
Safe.split
-
splitMapJoin(
String? string, Pattern pattern, {String onMatch(Match)?, String onNonMatch(String)?}) → String -
Refer to
Safe.splitMapJoin
-
startsWith(
String? string, Pattern pattern, [int index = 0]) → bool -
Refer to
Safe.startsWith
-
startsWithLowerCase(
String? string) → bool -
Returns true if
string
starts with the lower case character. -
startsWithUpperCase(
String? string) → bool - Returns true if the string starts with the upper case character.
-
substring(
String? string, int start, [int? end]) → String -
Refer to
Safe.substring
-
toCamelCase(
String? string, {bool lower = false}) → String -
Returns
string
in the form "UpperCamelCase" or "lowerCamelCase". -
toCapitalised(
String? string) → String -
Returns
string
with the first character capitalized. -
toEmpty(
String? string) → String -
If
string
is null we return a zero length string otherwise we returnstring
. -
toEscaped(
String? string, {String encode(int charCode)?}) → String - Returns an escaped string.
-
toLowerCase(
String? string) → String -
Refer to
Safe.toLowerCase
-
toPrintable(
String? string) → String - Returns an escaped string.
-
toProperCase(
String? sentence) → String -
Converts
sentence
to proper case by capitalising the first letter of each word and forcing all other characters to lower case. -
toSnakeCase(
String? string) → String -
Converts
string
to snake_case by inserting an underscore before each sequence of upper case letters and changing all upper case letters to lowercase. -
toUnicode(
int? charCode) → String - Returns an Unicode representation of the character code.
-
toUpperCase(
String? string) → String -
Refer to
Safe.toUpperCase
-
trim(
String? string) → String -
Refer to
Safe.trim
-
trimLeft(
String? string) → String -
Refer to
Safe.trimLeft
-
trimRight(
String? string) → String -
Refer to
Safe.trimRight
-
upTo(
String string, String delimiter) → String -
Returns the left most part of a string upto,
but not including, the
delimiter
-
within(
String string, String left, String right) → String -
Returns the string bounded by the
left
andright
delimiters. Throws an ArgumentError exception if either of the delimiters are missing. If there are nested delimiters we return the outer most delimiters.