ASCII
A utility library to perate on ASCII strings.
Interface
contains
It checks if string a contains string b.
@param a: A string.
@param b: Another string
@return bool. True if
a
containsb
.
Aborts
b
is longer thana
.
append
Appends a
and b
@param a: The first subtring.
@param b: The second substring.
@return String.
b
os 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.
@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
j
is greater thans
.if
j
is smaller thani
.
into_char
It returns the Char
at index i
from string
.
@param string: The string that contains the
Char
.@param i: i The index of the
Char
we want to grab.@return Char. The
Char
at indexi
.
Aborts
i
is out of bounds
to_lower_case
It lowercases the string.
@param string: The string we wish to lowercase.
@return String. The lowercase
string
to_upper_case
It uppercases the 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.
@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.
@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.
@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.
@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.
@param addr: A 32-byte address.
@return String. The
ascii::String
representation ofaddr
.
u8_to_ascii
Converts a u8 num
to an ascii character.
@param num: decimal representation of an ASCII character.
@return u8. The
ascii::String
code fornum
.
ascii_to_u8
Converts an ASCII character to its decimal representation u8.
@param char: ASCII character.
@return u8. The decimal representation of
char
.
Last updated