string.l0
Module: std.string
Source: compiler/shared/l0/stdlib/std/string.l0 Language: Dea/L0
Imports / Includes
std.assertsys.rt
Symbols
- len_s
- is_empty_s
- char_at_s
- eq_s
- cmp_s
- concat_s
- slice_s
- byte_to_s
- bytes_to_s
- find_s
- find_last_s
- find_from_s
- contains_s
- starts_with_s
- ends_with_s
- is_space
- is_digit
- is_digit_base
- is_alpha
- is_alnum
- to_digit
- to_digit_base
- to_upper
- to_lower
- trim_s
- digit_to_char
Function len_s
1
func len_s(s: string) -> int
Returns the length of the given string.
Parameters:
s: The string.
Returns: The length of the string.
Function is_empty_s
1
func is_empty_s(s: string) -> bool
Checks if the given string is empty.
Parameters:
s: The string to check.
Returns: True if empty, false otherwise.
Function char_at_s
1
func char_at_s(s: string, index: int) -> byte
Returns the character code (0-255) at the specified index in the string.
Parameters:
s: The string.index: The index to access.
Returns: The character byte.
Function eq_s
1
func eq_s(a: string, b: string) -> bool
Compares two strings for equality.
Parameters:
a: The first string.b: The second string.
Returns: True if equal, false otherwise.
Function cmp_s
1
func cmp_s(a: string, b: string) -> int
Compares two strings lexicographically.
Parameters:
a: The first string.b: The second string.
Returns: A negative value if a < b, zero if a == b, positive if a > b.
Function concat_s
1
func concat_s(a: string, b: string) -> string
Concatenates two strings and returns the result.
Parameters:
a: The first string.b: The second string.
Returns: The combined string.
Function slice_s
1
func slice_s(s: string, start: int, end: int) -> string
Returns a slice of the string from start to end (exclusive).
Parameters:
s: The string.start: The starting index.end: The ending index.
Returns: The string slice.
Function byte_to_s
1
func byte_to_s(b: byte) -> string
Converts a single byte to a string.
Parameters:
b: The byte to convert.
Returns: A string containing the byte.
Function bytes_to_s
1
func bytes_to_s(bytes: byte*, len: int) -> string
Creates a string from a byte array of a given length.
Parameters:
bytes: The pointer to the byte array.len: The number of bytes to include.
Returns: New string containing the provided bytes.
Function find_s
1
func find_s(haystack: string, needle: string) -> int
Returns the index of the first occurrence of ‘needle’ in ‘haystack’, or -1 if not found.
Parameters:
haystack: The string to search in.needle: The string to search for.
Returns: The index of the first occurrence, or -1.
Function find_last_s
1
func find_last_s(haystack: string, needle: string) -> int
Returns the index of the last occurrence of ‘needle’ in ‘haystack’, or -1 if not found.
For empty needle, returns len_s(haystack).
Parameters:
haystack: The string to search in.needle: The string to search for.
Returns: The index of the last occurrence, or -1.
Function find_from_s
1
func find_from_s(haystack: string, needle: string, pos: int) -> int
Returns the index of the first occurrence of ‘needle’ in ‘haystack’ starting from ‘pos’, or -1 if not found.
Parameters:
haystack: The string to search in.needle: The string to search for.pos: The starting position.
Returns: The index of the first occurrence, or -1.
Function contains_s
1
func contains_s(haystack: string, needle: string) -> bool
Returns true if ‘haystack’ contains ‘needle’.
Parameters:
haystack: The string to search in.needle: The string to search for.
Returns: True if found, false otherwise.
Function starts_with_s
1
func starts_with_s(s: string, prefix: string) -> bool
Returns true if ‘s’ starts with ‘prefix’.
Parameters:
s: The string.prefix: The prefix string.
Returns: True if ‘s’ starts with ‘prefix’, false otherwise.
Function ends_with_s
1
func ends_with_s(s: string, suffix: string) -> bool
Returns true if ‘s’ ends with ‘suffix’.
Parameters:
s: The string.suffix: The suffix string.
Returns: True if ‘s’ ends with ‘suffix’, false otherwise.
Function is_space
1
func is_space(c: byte) -> bool
Checks if the given character is a whitespace character.
Parameters:
c: The character.
Returns: True if whitespace, false otherwise.
Function is_digit
1
func is_digit(c: byte) -> bool
Checks if the given character is a decimal digit.
Parameters:
c: The character.
Returns: True if a digit, false otherwise.
Function is_digit_base
1
func is_digit_base(c: byte, base: int) -> bool
Checks if the character is a valid digit in the specified base.
Parameters:
c: The character.base: The numeric base (2-16).
Returns: True if a valid digit, false otherwise.
Function is_alpha
1
func is_alpha(c: byte) -> bool
Checks if the character is an alphabetic character.
Parameters:
c: The character.
Returns: True if alphabetic, false otherwise.
Function is_alnum
1
func is_alnum(c: byte) -> bool
Checks if the character is alphanumeric.
Parameters:
c: The character.
Returns: True if alphanumeric, false otherwise.
Function to_digit
1
func to_digit(c: byte) -> int
Converts a numeric character to its integer value.
Parameters:
c: The character.
Returns: The integer value.
Function to_digit_base
1
func to_digit_base(c: byte, base: int) -> int?
Converts a character to its integer value in the specified base.
Parameters:
c: The character.base: The numeric base (2-16).
Returns: The integer value, or null if invalid.
Function to_upper
1
func to_upper(c: byte) -> byte
Converts a lowercase character to uppercase.
Parameters:
c: The character.
Returns: The uppercase character.
Function to_lower
1
func to_lower(c: byte) -> byte
Converts an uppercase character to lowercase.
Parameters:
c: The character.
Returns: The lowercase character.
Function trim_s
1
func trim_s(s: string) -> string
Removes leading and trailing whitespace from the input string.
Parameters:
s: The string to trim.
Returns: The trimmed string.
Function digit_to_char
1
func digit_to_char(d: int) -> byte
Converts a digit (0-15) to its character representation.
Parameters:
d: The digit value.
Returns: The character representation (‘0’-‘9’, ‘a’-‘f’).