Interface

interface Parsable<T>

public interface Parsable<T> {
    static func parse(value: String): T
    static func tryParse(value: String): Option<T>
}

Description: Provides unified methods to parse strings to specific types.

This interface provides two methods: parse and tryParse. The parse method throws an exception when parsing fails. The tryParse method returns the result encapsulated with Option. If parsing fails, the tryParse method returns None. In this package, the basic types, such as Bool, Rune, Float16, and Int64, have implemented this interface. This interface can be used to convert strings to these types.

static func parse(String)

static func parse(value: String): T

Description: Parses a string into a specific type.

Parameters:

  • value: String: string to be parsed

Returns:

  • T: value after conversion

static func tryParse(String)

static func tryParse(value: String): Option<T>

Description: Parses a string into a specific type.

Parameters:

  • value: String: string to be parsed

Returns:

  • Option<T>: value after conversion. If the conversion fails, Option<T>.None is returned.

extend Bool <: Parsable<Bool>

extend Bool <: Parsable<Bool>

Description: Implements related operation functions of converting a Bool literal string to a Bool value.

Parent Type:

static func parse(String)

public static func parse(data: String): Bool

Description: Converts a Bool literal string to a Bool value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

static func tryParse(String)

public static func tryParse(data: String): Option<Bool>

Description: Converts a Bool literal string to an Option<Bool> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Float16 <: Parsable<Float16>

extend Float16 <: Parsable<Float16>

Description: Implements related operation functions of converting a Float16 literal string to a Float16 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Float16

Description: Converts a Float16 literal string to a Float16 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string does not comply with the floating-point number syntax, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Float16>

Description: Converts a Float16 literal string to an Option<Float16> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Float32 <: Parsable<Float32>

extend Float32 <: Parsable<Float32>

Description: Implements related operation functions of converting a Float32 literal string to a Float32 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Float32

Description: Converts a Float32 literal string to a Float32 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string does not comply with the floating-point number syntax, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Float32>

Description: Converts a Float32 literal string to an Option<Float32> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Float64 <: Parsable<Float64>

extend Float64 <: Parsable<Float64>

Description: Implements related operation functions of converting a Float64 literal string to a Float64 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Float64

Description: Converts a Float64 literal string to a Float64 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string does not comply with the floating-point number syntax, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Float64>

Description: Converts a Float64 literal string to an Option<Float64> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Int16 <: Parsable<Int16>

extend Int16 <: Parsable<Int16>

Description: Implements related operation functions of converting an Int16 literal string to an Int16 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Int16

Description: Converts an Int16 literal string to an Int16 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is +, the conversion fails, the value after conversion exceeds the range of Int16, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Int16>

Description: Converts an Int16 literal string to an Option<Int16> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Int32 <: Parsable<Int32>

extend Int32 <: Parsable<Int32>

Description: Implements related operation functions of converting an Int32 literal string to an Int32 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Int32

Description: Converts an Int32 literal string to an Int32 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is +, the conversion fails, the value after conversion exceeds the range of Int32, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Int32>

Description: Converts an Int32 literal string to an Option<Int32> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Int64 <: Parsable<Int64>

extend Int64 <: Parsable<Int64>

Description: Implements related operation functions of converting an Int64 literal string to an Int64 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Int64

Description: Converts an Int64 literal string to an Int64 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is +, the conversion fails, the value after conversion exceeds the range of Int64, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Int64>

Description: Converts an Int64 literal string to an Option<Int64> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Int8 <: Parsable<Int8>

extend Int8 <: Parsable<Int8>

Description: Implements related operation functions of converting an Int8 literal string to an Int8 value.

Parent Type:

static func parse(String)

public static func parse(data: String): Int8

Description: Converts an Int8 literal string to an Int8 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is +, the conversion fails, the value after conversion exceeds the range of Int8, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Int8>

Description: Converts an Int8 literal string to an Option<Int8> value.

Parameters:

  • data: String: string to be converted

Returns:

extend Rune <: Parsable<Rune>

extend Rune <: Parsable<Rune>

Description: Implements related operation functions of converting a Rune literal string to a Rune value.

Parent Type:

static func parse(String)

public static func parse(data: String): Rune

Description: Converts a Rune literal string to a Rune value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the conversion fails, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<Rune>

Description: Converts a Rune literal string to an Option<Rune> value.

Parameters:

  • data: String: string to be converted

Returns:

extend UInt16 <: Parsable<UInt16>

extend UInt16 <: Parsable<UInt16>

Description: Implements related operation functions of converting a UInt16 literal string to a UInt16 value.

Parent Type:

static func parse(String)

public static func parse(data: String): UInt16

Description: Converts a UInt16 literal string to a UInt16 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is + or -, the conversion fails, the value after conversion exceeds the range of UInt16, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<UInt16>

Description: Converts a UInt16 literal string to an Option<UInt16> value.

Parameters:

  • data: String: string to be converted

Returns:

extend UInt32 <: Parsable<UInt32>

extend UInt32 <: Parsable<UInt32>

Description: Implements related operation functions of converting a UInt32 literal string to a UInt32 value.

Parent Type:

static func parse(String)

public static func parse(data: String): UInt32

Description: Converts a UInt32 literal string to a UInt32 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is + or -, the conversion fails, the value after conversion exceeds the range of UInt32, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<UInt32>

Description: Converts a UInt32 literal string to an Option<UInt32> value.

Parameters:

  • data: String: string to be converted

Returns:

extend UInt64 <: Parsable<UInt64>

extend UInt64 <: Parsable<UInt64>

Description: Implements related operation functions of converting a UInt64 literal string to a UInt64 value.

Parent Type:

static func parse(String)

public static func parse(data: String): UInt64

Description: Converts a UInt64 literal string to a UInt64 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is + or -, the conversion fails, the value after conversion exceeds the range of UInt64, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<UInt64>

Description: Converts a UInt64 literal string to an Option<UInt64> value.

Parameters:

  • data: String: string to be converted

Returns:

extend UInt8 <: Parsable<UInt8>

extend UInt8 <: Parsable<UInt8>

Description: Implements related operation functions of converting a UInt8 literal string to a UInt8 value.

Parent Type:

static func parse(String)

public static func parse(data: String): UInt8

Description: Converts a UInt8 literal string to a UInt8 value.

Parameters:

  • data: String: string to be converted

Returns:

Throws:

  • IllegalArgumentException: If the string is empty, the first character of the string is + or -, the conversion fails, the value after conversion exceeds the range of UInt8, or the string contains an invalid UTF-8 character, this exception is thrown.

static func tryParse(String)

public static func tryParse(data: String): Option<UInt8>

Description: Converts a UInt8 literal string to an Option<UInt8> value.

Parameters:

  • data: String: string to be converted

Returns: