ASCII
A utility library to perate on ASCII strings.
Interface
contains
It checks if string a contains string b.
public fun contains(a: String, b: String): bool@param a: A string.
@param b: Another string
@return bool. True if
acontainsb.
Aborts
bis longer thana.
append
Appends a and b
public fun append(a: String, b: String): String@param a: The first subtring.
@param b: The second substring.
@return String.
bos longer thana`a` + `b` => "hello" `append` "world" => "helloworld".
slice
Returns a [i, j) slice of the string starting at index i and going up to, but not including, index j.
public fun append(a: String, b: String): String@param s: The string that will be sliced.
@param i: The first index of the substring.
@param j: The last index of the substring. This character is not included.
@return String. The substring.
Aborts
if
jis greater thans.if
jis smaller thani.
into_char
It returns the Char at index i from string.
public fun into_char(string: &String, i: u64): Char@param string: The string that contains the
Char.@param i: i The index of the
Charwe want to grab.@return Char. The
Charat indexi.
Aborts
iis out of bounds
to_lower_case
It lowercases the string.
public fun to_lower_case(string: String): String@param string: The string we wish to lowercase.
@return String. The lowercase
string
to_upper_case
It uppercases the string.
public fun to_upper_case(string: String): String@param string: The string we wish to lowercase.
@return String. The lowercase
string
u128_to_string
Converts a u128 to its ascii::String decimal representation.
public fun u128_to_string(value: u128): String@param value: A u128.
@return String. The string representation of
value. E.g. 128 => "128".
u128_to_hex_string
Converts a u128 to its ascii::String hexadecimal representation.
public fun u128_to_hex_string(value: u128): String @param value: A u128.
@return String. The HEX string representation of
value. E.g. 10 => "0xA".
u128_to_hex_string_to_fixed_length
Converts a u128 to its ascii::String hexadecimal representation with fixed length (in whole bytes). The returned String is 2 * length + 2(with '0x') in size.
public fun u128_to_hex_string_fixed_length(value: u128, length: u128): String@param value: A u128.
@param length: length of the string.
@return String. The HEX string representation of
value. E.g. 10 => "0xA".
bytes_to_hex_string
Converts a vector<u8> to its ascii::String hexadecimal representation.
public fun bytes_to_hex_string(bytes: vector<u8>): String@param value A u128.
@return String. The HEX string representation of
bytes. E.g. 0b1010 => "0x0A".
addr_into_string
Converts an address addr to its ascii::String representation. Addresses are 32 bytes, whereas the string-encoded address is 64 bytes. Outputted strings do not include the 0x prefix.
public fun addr_into_string(addr: address): String@param addr: A 32-byte address.
@return String. The
ascii::Stringrepresentation ofaddr.
u8_to_ascii
Converts a u8 num to an ascii character.
public fun u8_to_ascii(num: u8): u8@param num: decimal representation of an ASCII character.
@return u8. The
ascii::Stringcode fornum.
ascii_to_u8
Converts an ASCII character to its decimal representation u8.
public fun ascii_to_u8(char: u8): u8@param char: ASCII character.
@return u8. The decimal representation of
char.
Last updated
Was this helpful?