StringUtils class

A utility class for working with strings and common string operations.

Constructors

StringUtils()

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

add0x(String value) → String
Adds a 0x prefix to value, unless it already has one.
camelToSnake(String input) → String
Converts camelCase/PascalCase input to snake_case.
decode(List<int> value, {StringEncoding encoding = StringEncoding.utf8, bool allowInvalidOrMalformed = false, bool b64NoPadding = false, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → String
Decodes value into a string using encoding (UTF-8 by default).
decodeJson<T extends Object?>(List<int> value, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T
Decodes a list of bytes value into a JSON object of type T.
encode(String value, {StringEncoding encoding = StringEncoding.utf8, bool validateB64Padding = true, bool allowUrlSafe = true, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → BuBytes
Encodes value into bytes using encoding (UTF-8 by default).
encodeJson(Object json, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → BuBytes
Encodes a JSON-serializable json object into a list of bytes.
fromJson(Object data, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → String
Converts a Dart object represented as a Map to a JSON-encoded string.
hexEqual(String a, String b) → bool
Whether a and b represent the same hex value (case/0x-prefix insensitive).
isBase58(String input) → bool
Whether input contains only valid Base58 characters.
isBase64(String input, {bool validatePadding = true}) → bool
Whether input contains only valid Base64 characters.
isHexadecimalNumber(String v) → bool
Whether v is a valid hexadecimal number, with an optional 0x prefix.
isHexBytes(String v, {int? lengthInBytes}) → bool
Whether v is a valid (even-length) hex string, with an optional 0x prefix. If lengthInBytes is given, also checks the decoded length.
normalizeHex(String hexString, {bool with0x = false}) → String
Like _normalizeHex, but validates hexString first.
snakeToCamel(String input, {required bool capitalizeFirst}) → String
Converts snake_case/kebab-case input to camelCase (or PascalCase if capitalizeFirst is true).
strip0x(String value) → String
Removes the '0x' prefix from a hexadecimal string if it exists.
toBytes(String v) → BuBytes
Decodes v as hex if it looks like a hex string, otherwise UTF-8 encodes it.
toJson<T extends Object?>(Object? data, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T
Converts a JSON-encoded string to a Dart object represented as a Map.
tryDecode(List<int>? value, {StringEncoding encoding = StringEncoding.utf8, bool allowInvalidOrMalformed = false, bool b64NoPadding = false, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → String?
Like decode, but returns null instead of throwing (or if value is null).
tryDecodeJson<T extends Object>(List<int> value, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T?
Attempts to decode a list of bytes value into a JSON object of type T, returning null if decoding or parsing fails.
tryEncode(String? value, {StringEncoding encoding = StringEncoding.utf8, bool validateB64Padding = true, bool allowUrlSafe = true, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → BuBytes?
Like encode, but returns null instead of throwing on failure (or if value is null).
tryEncodeJson(Object? json, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → BuBytes?
Attempts to encode a JSON-serializable json object into a list of bytes, returning null if the conversion to JSON string fails.
tryFromJson(Object? data, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → String?
Converts a Dart object represented as a Map to a JSON-encoded string if possible.
tryToBytes(String? v) → BuBytes?
Like toBytes, but returns null instead of throwing (or if v is null).
tryToJson<T extends Object?>(Object? data, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T?
Converts a JSON-encoded string to a Dart object represented as a Map if possible.