text.l0
Module: std.text
Source: compiler/shared/l0/stdlib/std/text.l0 Language: Dea/L0
Imports / Includes
std.vectorstd.assertstd.integerstd.stringsys.memorysys.rt
Symbols
- sb_create
- sb_append
- sb_append_int
- sb_append_byte
- sb_to_string
- sb_size
- sb_free
- cb_create
- cb_capacity
- cb_size
- cb_reserve
- cb_append
- cb_append_s
- cb_append_slice
- cb_append_int
- cb_reverse
- cb_to_string
- cb_clear
- cb_free
- to_upper_s
- to_lower_s
- repeat_s
- split_s
- _line_strip_trailing_cr
- lines_s
- join_s
- replace_s
- int_to_string_base
- reverse_s
- int_to_string
- int_to_hex_string
- int_to_bin_string
- bool_to_string
- string_to_bool
- byte_to_string
- byte_to_string_base
- string_to_int
- string_to_byte
- string_to_byte_base
- string_to_int_base
- StringBuffer
- CharBuffer
Function sb_create
1
func sb_create() -> StringBuffer*
Creates a new, empty StringBuffer .
Returns: A pointer to the newly created StringBuffer.
Function sb_append
1
func sb_append(self: StringBuffer*, s: string)
Appends a string to the StringBuffer .
Parameters:
self: The pointer to the StringBuffer.s: The string to append.
Function sb_append_int
1
func sb_append_int(self: StringBuffer*, value: int)
Appends an integer to the StringBuffer .
Parameters:
self: The pointer to the StringBuffer.value: The integer value to append.
Function sb_append_byte
1
func sb_append_byte(self: StringBuffer*, b: byte)
Appends a byte to the StringBuffer .
Parameters:
self: The pointer to the StringBuffer.b: The byte value to append.
Function sb_to_string
1
func sb_to_string(self: StringBuffer*) -> string
Converts the accumulated contents of the StringBuffer into a single string.
Parameters:
self: The pointer to the StringBuffer.
Returns: The final concatenated string.
Function sb_size
1
func sb_size(self: StringBuffer*) -> int
Returns the current total size of all strings in the StringBuffer .
Parameters:
self: The pointer to the StringBuffer.
Returns: The total size in bytes.
Function sb_free
1
func sb_free(self: StringBuffer*)
Free a StringBuffer and its accumulated string parts.
Parameters:
self: String buffer to free.
Function cb_create
1
func cb_create() -> CharBuffer*
Creates a new, empty CharBuffer .
Returns: A pointer to the newly created CharBuffer.
Function cb_capacity
1
func cb_capacity(self: CharBuffer*) -> int
Returns the current capacity of the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.
Returns: The total capacity.
Function cb_size
1
func cb_size(self: CharBuffer*) -> int
Returns the number of characters currently in the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.
Returns: The character count.
Function cb_reserve
1
func cb_reserve(self: CharBuffer*, total_capacity: int)
Ensures the CharBuffer has at least the specified capacity.
Parameters:
self: The pointer to the CharBuffer.total_capacity: The desired capacity.
Function cb_append
1
func cb_append(self: CharBuffer*, c: byte)
Appends a single character to the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.c: The character to append.
Function cb_append_s
1
func cb_append_s(self: CharBuffer*, s: string)
Appends a string to the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.s: The string to append.
Function cb_append_slice
1
func cb_append_slice(self: CharBuffer*, s: string, start: int, length: int)
Appends a slice of a string to the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.s: The string containing the slice.start: The starting index of the slice.length: The number of characters to append.
Function cb_append_int
1
func cb_append_int(self: CharBuffer*, value: int)
Appends an integer to the CharBuffer .
Parameters:
self: The pointer to the CharBuffer.value: The integer value to append.
Function cb_reverse
1
func cb_reverse(cb: CharBuffer*)
Reverses the contents of the CharBuffer in place.
Parameters:
cb: The pointer to the CharBuffer.
Function cb_to_string
1
func cb_to_string(self: CharBuffer*) -> string
Converts the accumulated characters in the CharBuffer into a string.
Parameters:
self: The pointer to the CharBuffer.
Returns: The final string.
Function cb_clear
1
func cb_clear(self: CharBuffer*)
Clears all characters from the CharBuffer without freeing memory.
Parameters:
self: The pointer to the CharBuffer.
Function cb_free
1
func cb_free(self: CharBuffer*)
Free a CharBuffer and its backing character storage.
Parameters:
self: Character buffer to free.
Function to_upper_s
1
func to_upper_s(s: string) -> string
Converts all characters in the input string to uppercase.
Parameters:
s: The string to convert.
Returns: The uppercase string.
Function to_lower_s
1
func to_lower_s(s: string) -> string
Converts all characters in the input string to lowercase.
Parameters:
s: The string to convert.
Returns: The lowercase string.
Function repeat_s
1
func repeat_s(s: string, count: int) -> string
Returns a new string that is the input string s repeated count times.
Parameters:
s: The string to repeat.count: The number of repetitions.
Returns: The repeated string.
Function split_s
1
func split_s(s: string, sep: string) -> StringVector*
Splits a string into parts based on a separator string.
Parameters:
s: The string to split.sep: The separator string.
Returns: A new StringVector containing the parts.
Function _line_strip_trailing_cr
1
func _line_strip_trailing_cr(s: string) -> string
Internal helper to strip a trailing CR from a line string.
Parameters:
s: The string.
Returns: The stripped string.
Function lines_s
1
func lines_s(s: string) -> StringVector*
Splits a string into lines, supporting both LF and CRLF.
Parameters:
s: The string to split into lines.
Returns: A new StringVector containing the lines.
Function join_s
1
func join_s(parts: StringVector*, sep: string) -> string
Joins parts of a string vector using a separator.
Parameters:
parts: The vector of string parts.sep: The separator string.
Returns: The single joined string.
Function replace_s
1
func replace_s(s: string, old: string, replacement: string) -> string
Replaces all occurrences of an old substring with a new replacement string.
Parameters:
s: The source string.old: The substring to replace.replacement: The replacement substring.
Returns: The modified string.
Function int_to_string_base
1
func int_to_string_base(value: int, base: int) -> string
Converts an integer to a string representation in the specified base.
Parameters:
value: The integer value.base: The numeric base (2-16).
Returns: The string representation.
Function reverse_s
1
func reverse_s(s: string) -> string
Reverses the characters in a string.
Parameters:
s: The string to reverse.
Returns: The reversed string.
Function int_to_string
1
func int_to_string(value: int) -> string
Converts an integer to its decimal string representation.
Parameters:
value: The integer value.
Returns: The decimal string.
Function int_to_hex_string
1
func int_to_hex_string(value: int) -> string
Converts an integer to its hexadecimal string representation.
Parameters:
value: The integer value.
Returns: The hex string.
Function int_to_bin_string
1
func int_to_bin_string(value: int) -> string
Converts an integer to its binary string representation.
Parameters:
value: The integer value.
Returns: The binary string.
Function bool_to_string
1
func bool_to_string(value: bool) -> string
Converts a boolean to its string representation (“true” or “false”).
Parameters:
value: The boolean value.
Returns: The string representation.
Function string_to_bool
1
func string_to_bool(s: string) -> bool?
Parses a string representation of a boolean.
Parameters:
s: The string to parse.
Returns: The boolean value, or null if invalid.
Function byte_to_string
1
func byte_to_string(value: byte) -> string
Converts a byte to its decimal string representation.
Parameters:
value: The byte value.
Returns: The decimal string.
Function byte_to_string_base
1
func byte_to_string_base(value: byte, base: int) -> string
Converts a byte to its string representation in the specified base.
Parameters:
value: The byte value.base: The numeric base (2-16).
Returns: The string representation.
Function string_to_int
1
func string_to_int(s: string) -> int?
Converts a decimal numeric string to an integer.
Returns null when parsing fails or overflows 32-bit signed range.
Parameters:
s: The string to parse.
Returns: The integer value, or null.
Function string_to_byte
1
func string_to_byte(s: string) -> byte?
Converts a decimal numeric string to a byte.
Parameters:
s: The string to parse.
Returns: The byte value, or null if invalid or out of range (0-255).
Function string_to_byte_base
1
func string_to_byte_base(s: string, base: int) -> byte?
Converts a numeric string in the specified base to a byte.
Parameters:
s: The string to parse.base: The numeric base (2-16).
Returns: The byte value, or null if invalid or out of range.
Function string_to_int_base
1
func string_to_int_base(s: string, base: int) -> int?
Converts a numeric string ‘s’ expressed in base ‘base’ to an integer.
Handles optional leading ‘-‘ for negative numbers and ignores leading zeros. No special prefixes like “0x” for hex or “0b” for binary are expected or allowed. Checks for overflow and invalid characters. Returns null if the string is not a valid 32-bit signed integer.
Parameters:
s: The string to parse.base: The numeric base (2-16).
Returns: The integer value, or null.
Struct StringBuffer
StringBuffer allows for efficient construction of strings by accumulating parts in a vector.
StringBuffer Field parts
1
parts: StringVector*
StringBuffer Field size
1
size: int
Struct CharBuffer
CharBuffer allows for efficient building of strings by accumulating individual characters.
CharBuffer Field chars
1
chars: VectorBase*