core.strings¶
Null-terminated string manipulation library for the kernel.
Overview¶
core.strings provides a comprehensive set of routines for working with null-terminated (pchar) strings in a bare-metal environment. Because the kernel cannot use the Free Pascal runtime library string support, all allocation is performed through the kernel heap (kalloc/kfree) and all operations work on raw pointer-based C-style strings. The unit covers string creation, copying, comparison, searching, case conversion, concatenation, substring extraction, replacement, and conversion to and from integer types. A built-in UnitTest procedure exercises the full API and reports results via syslog.
Dependencies¶
core.util—memcpy,memset,HexCharToDecimalarch.x86.util— architecture-level utilitiesmemory.heap—kalloc,kfreecore.ds.lists— transitively requiredio.syslog— test output (implementation section only)
Functions and Procedures¶
stringNew¶
Allocates a new zero-initialised string buffer ofsize bytes plus a null terminator. Returns a pointer to the buffer.
stringCopy¶
Allocates and returns a heap copy ofstr.
stringSize¶
Returns the length ofstr in characters, excluding the null terminator. Returns 0 for nil.
stringEquals¶
Returnstrue if str1 and str2 have identical length and content.
stringToUpper¶
Returns a heap-allocated copy ofstr with all lowercase ASCII letters converted to uppercase.
stringToLower¶
Returns a heap-allocated copy ofstr with all uppercase ASCII letters converted to lowercase.
stringConcat¶
Returns a heap-allocated string containingstr1 followed by str2.
stringTrim¶
Returns a heap-allocated copy ofstr truncated to at most length characters. If length exceeds the string length, the full string is copied.
stringSub¶
Returns a heap-allocated substring ofstr beginning at byte offset start with at most size characters. Returns an empty string if start is past the end. If start + size exceeds the string length, the result is clamped to the end.
stringMatchAt¶
Returnstrue if find matches the characters in str starting at position pos. An empty find always returns true.
stringIndexOf¶
Returns the zero-based index of the first occurrence offind within str, or -1 if not found. An empty find returns 0.
stringContains¶
Returnstrue if sub appears anywhere within str.
stringReplace¶
Returns a heap-allocated copy ofstr with the first occurrence of find replaced by replace. If find is not present, a copy of str is returned unchanged.
stringToInt¶
Parses a decimal integer string and returns itsuint32 value. Non-digit characters are ignored.
intToString¶
Returns a heap-allocated decimal string representation ofi.
hexStringToInt¶
Parses a hexadecimal string (no0x prefix) and returns its uint32 value.
boolToString¶
Returns a heap-allocated string for the booleanb. When ext is true, returns 'true' or 'false'; when false, returns '1' or '0'.
UnitTest¶
Runs the complete string function test suite and logs a pass/fail summary to syslog under the'STRINGS' channel.
Notes¶
All functions returning pchar return newly heap-allocated strings. Callers are responsible for freeing the result with kfree when it is no longer needed.
stringReplace replaces only the first occurrence of find. There is no bulk-replace variant.