StringUtils class
A utility class for working with strings and common string operations.
Constructors
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
0xprefix tovalue, unless it already has one. -
camelToSnake(
String input) → String -
Converts camelCase/PascalCase
inputto snake_case. -
decode(
List< int> value, {StringEncoding encoding = StringEncoding.utf8, bool allowInvalidOrMalformed = false, bool b64NoPadding = false, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → String -
Decodes
valueinto a string usingencoding(UTF-8 by default). -
decodeJson<
T extends Object?> (List< int> value, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T -
Decodes a list of bytes
valueinto a JSON object of typeT. -
encode(
String value, {StringEncoding encoding = StringEncoding.utf8, bool validateB64Padding = true, bool allowUrlSafe = true, Base58Alphabets base58alphabets = Base58Alphabets.bitcoin}) → BuBytes -
Encodes
valueinto bytes usingencoding(UTF-8 by default). -
encodeJson(
Object json, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → BuBytes -
Encodes a JSON-serializable
jsonobject 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
aandbrepresent the same hex value (case/0x-prefix insensitive). -
isBase58(
String input) → bool -
Whether
inputcontains only valid Base58 characters. -
isBase64(
String input, {bool validatePadding = true}) → bool -
Whether
inputcontains only valid Base64 characters. -
isHexadecimalNumber(
String v) → bool -
Whether
vis a valid hexadecimal number, with an optional0xprefix. -
isHexBytes(
String v, {int? lengthInBytes}) → bool -
Whether
vis a valid (even-length) hex string, with an optional0xprefix. IflengthInBytesis given, also checks the decoded length. -
normalizeHex(
String hexString, {bool with0x = false}) → String -
Like
_normalizeHex, but validateshexStringfirst. -
snakeToCamel(
String input, {required bool capitalizeFirst}) → String -
Converts snake_case/kebab-case
inputto camelCase (or PascalCase ifcapitalizeFirstis true). -
strip0x(
String value) → String - Removes the '0x' prefix from a hexadecimal string if it exists.
-
toBytes(
String v) → BuBytes -
Decodes
vas 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
valueis null). -
tryDecodeJson<
T extends Object> (List< int> value, {Object? reviver(Object?, Object?)?, JsonDecodeOptions? options}) → T? -
Attempts to decode a list of bytes
valueinto a JSON object of typeT, returningnullif 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
valueis null). -
tryEncodeJson(
Object? json, {String? indent, bool toStringEncodable = false, Object? toEncodable(dynamic)?, JsonEncodeOptions? options}) → BuBytes? -
Attempts to encode a JSON-serializable
jsonobject 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
vis 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.