std::libc::string
LibC String
Null-terminated C string operations from string.h, exposed as
LibC::String.
Functions
| Function | Description |
|---|---|
strlen |
Length of null-terminated string |
strcmp |
Compare two strings (returns 0 if equal) |
strncmp |
Compare up to n bytes |
strcpy |
Copy string including null terminator |
strncpy |
Copy up to n bytes, null-padding if shorter |
strcat |
Append string to end of destination |
strncat |
Append up to n bytes |
strchr |
Find first occurrence of byte in string |
strrchr |
Find last occurrence of byte in string |
strstr |
Find first occurrence of substring |
strdup |
Duplicate string (caller must free) |
strerror |
Human-readable string for an errno value |
All functions operate on raw CType::CStr / CType::CConstStr pointers.
The caller is responsible for buffer sizes and null termination.
Do not use these APIs for Ignis String byte-length semantics; they are
raw C-string helpers and may stop at the first interior NUL byte.
Example
import LibC, CType from "std::libc";
function main(): i32 {
let msg: CType::CConstStr = "hello, world";
let len: CType::SizeT = LibC::String::strlen(msg);
// Duplicate and compare
let copy: CType::CStr = LibC::String::strdup(msg);
let eq: CType::CInt = LibC::String::strcmp(msg, copy);
LibC::Allocator::free(copy as CType::CVoidPtr);
// Find substring
let pos: CType::CStr = LibC::String::strstr(msg, "world");
return 0;
}
namespace __string_opsFunctions
function strcat(dest: *mut u8, src: *u8): *mut u8C strcat; appends src to dest.
function strchr(s: *u8, c: i32): *mut u8C strchr; returns the first matching byte in s.
function strcmp(s1: *u8, s2: *u8): i32C strcmp; compares two NUL-terminated strings.
function strcpy(dest: *mut u8, src: *u8): *mut u8C strcpy; copies a NUL-terminated string into dest.
function strdup(s: *u8): *mut u8C strdup; allocates a duplicate string with the C allocator.
function strerror(errnum: i32): *mut u8C strerror; returns a host-owned error message for errnum.
function strlen(s: *u8): u64C strlen; returns bytes before the first NUL.
function strncat(dest: *mut u8, src: *u8, n: u64): *mut u8C strncat; appends at most n bytes from src to dest.
function strncmp(s1: *u8, s2: *u8, n: u64): i32C strncmp; compares at most n bytes.
function strncpy(dest: *mut u8, src: *u8, n: u64): *mut u8C strncpy; copies at most n bytes into dest.
function strrchr(s: *u8, c: i32): *mut u8C strrchr; returns the last matching byte in s.
function strstr(haystack: *u8, needle: *u8): *mut u8C strstr; returns the first occurrence of needle.
namespace StringString operations (string.h)
Functions
function strcat(dest: *mut u8, src: *u8): *mut u8Appends src to the end of dest.
function strchr(s: *u8, c: i32): *mut u8Finds the first occurrence of byte c in string s.
function strcmp(s1: *u8, s2: *u8): i32Compares two null-terminated strings. Returns 0 if equal.
function strcpy(dest: *mut u8, src: *u8): *mut u8Copies src to dest including the null terminator.
function strdup(s: *u8): *mut u8Duplicates a string into newly allocated memory. Caller must free.
function strerror(errnum: i32): *mut u8Returns a human-readable string for the given error number.
function strlen(s: *u8): u64Returns the length of the null-terminated string s.
function strncat(dest: *mut u8, src: *u8, n: u64): *mut u8Appends at most n bytes of src to dest.
function strncmp(s1: *u8, s2: *u8, n: u64): i32Compares at most n bytes of two strings. Returns 0 if equal.
function strncpy(dest: *mut u8, src: *u8, n: u64): *mut u8Copies at most n bytes from src to dest, null-padding if src is shorter.
function strrchr(s: *u8, c: i32): *mut u8Finds the last occurrence of byte c in string s.
function strstr(haystack: *u8, needle: *u8): *mut u8Finds the first occurrence of needle in haystack.