Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_string.h
Go to the documentation of this file.
1
26#ifndef RTE_COMMON_STRING_H
27#define RTE_COMMON_STRING_H
28
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
38typedef struct rte_string_s
39{
42
51rte_status_t rte_string_init(rte_string_t *str, char *storage, size_t capacity);
52
60
67size_t rte_string_length(const rte_string_t *str);
68
80rte_status_t rte_string_c_str(rte_string_t *str, const char **out_cstr);
81
93rte_status_t rte_string_copy(rte_string_t *dest, const char *src);
94
106rte_status_t rte_string_copy_n(rte_string_t *dest, const char *src, size_t src_len);
107
118rte_status_t rte_string_concat(rte_string_t *dest, const char *src);
119
129rte_status_t rte_string_compare(const rte_string_t *a, const rte_string_t *b, int32_t *out_cmp);
130
144 bool *out_found, size_t *out_index);
145
159rte_status_t rte_string_find_substr(const rte_string_t *haystack, const rte_string_t *needle,
160 bool *out_found, size_t *out_index);
161
182rte_status_t rte_string_split_next(const rte_string_t *str, char delimiter,
183 size_t *io_cursor,
184 rte_const_buffer_t *out_token,
185 bool *out_has_token);
186
196rte_status_t rte_string_from_u32(rte_string_t *dest, uint32_t value);
204rte_status_t rte_string_from_i32(rte_string_t *dest, int32_t value);
212rte_status_t rte_string_from_u64(rte_string_t *dest, uint64_t value);
220rte_status_t rte_string_from_i64(rte_string_t *dest, int64_t value);
221
235rte_status_t rte_string_append_u32(rte_string_t *dest, uint32_t value);
254rte_status_t rte_string_append_u64(rte_string_t *dest, uint64_t value);
280rte_status_t rte_string_append_hex_u32(rte_string_t *dest, uint32_t value, uint8_t min_digits);
281
292rte_status_t rte_string_to_u32(const rte_string_t *str, uint32_t *out_value);
301rte_status_t rte_string_to_i32(const rte_string_t *str, int32_t *out_value);
310rte_status_t rte_string_to_u64(const rte_string_t *str, uint64_t *out_value);
319rte_status_t rte_string_to_i64(const rte_string_t *str, int64_t *out_value);
320
321#ifdef __cplusplus
322}
323#endif
324
325#endif /* RTE_COMMON_STRING_H */
326 /* STRING */
rte_status_t
Common result/status codes.
Definition rte_status.h:27
rte_status_t rte_string_to_u64(const rte_string_t *str, uint64_t *out_value)
As rte_string_to_u32(), for uint64_t.
Definition rte_string.c:586
rte_status_t rte_string_split_next(const rte_string_t *str, char delimiter, size_t *io_cursor, rte_const_buffer_t *out_token, bool *out_has_token)
Reentrant, bounded string splitting - unlike strtok(), all state is caller-owned via io_cursor,...
Definition rte_string.c:257
rte_status_t rte_string_from_i64(rte_string_t *dest, int64_t value)
Bounded base-10 itoa equivalent for int64_t. Replaces dest's content.
Definition rte_string.c:354
rte_status_t rte_string_from_i32(rte_string_t *dest, int32_t value)
Bounded base-10 itoa equivalent for int32_t. Replaces dest's content.
Definition rte_string.c:405
rte_status_t rte_string_copy(rte_string_t *dest, const char *src)
Bounded strcpy equivalent. Never calls strlen(src) - scans for a NUL only up to dest's capacity (REQ-...
Definition rte_string.c:68
rte_status_t rte_string_find_char(const rte_string_t *str, char c, bool *out_found, size_t *out_index)
Bounded strchr equivalent. "Not found" is a normal outcome, not an error - see out_found.
Definition rte_string.c:186
rte_status_t rte_string_find_substr(const rte_string_t *haystack, const rte_string_t *needle, bool *out_found, size_t *out_index)
Bounded strstr equivalent. "Not found" is a normal outcome, not an error - see out_found.
Definition rte_string.c:214
rte_status_t rte_string_append_i64(rte_string_t *dest, int64_t value)
Bounded base-10 append of an int64_t; a leading '-' is emitted for negative values....
Definition rte_string.c:476
rte_status_t rte_string_append_u32(rte_string_t *dest, uint32_t value)
Bounded base-10 append of a uint32_t to dest's existing content (unlike rte_string_from_u32(),...
Definition rte_string.c:501
size_t rte_string_length(const rte_string_t *str)
Returns a string's current length (not counting a NUL terminator).
Definition rte_string.c:28
rte_status_t rte_string_clear(rte_string_t *str)
Resets a string to empty. Capacity and storage are unchanged.
Definition rte_string.c:19
rte_status_t rte_string_concat(rte_string_t *dest, const char *src)
Bounded strcat equivalent. Never calls strlen(src) - scans for a NUL only up to dest's remaining capa...
Definition rte_string.c:100
rte_status_t rte_string_c_str(rte_string_t *str, const char **out_cstr)
Ensures a NUL terminator is present within capacity (without incrementing length) and returns a point...
Definition rte_string.c:37
rte_status_t rte_string_append_i32(rte_string_t *dest, int32_t value)
Bounded base-10 append of an int32_t; a leading '-' is emitted for negative values....
Definition rte_string.c:519
rte_status_t rte_string_append_hex_u32(rte_string_t *dest, uint32_t value, uint8_t min_digits)
Bounded append of a uint32_t formatted as lowercase hexadecimal (no "0x" prefix - the caller prepends...
Definition rte_string.c:537
rte_status_t rte_string_append_u64(rte_string_t *dest, uint64_t value)
Bounded base-10 append of a uint64_t. See rte_string_append_u32().
Definition rte_string.c:463
rte_status_t rte_string_init(rte_string_t *str, char *storage, size_t capacity)
Binds a string to caller-owned storage. Initial length is 0 (empty string).
Definition rte_string.c:10
rte_status_t rte_string_from_u64(rte_string_t *dest, uint64_t value)
Bounded base-10 itoa equivalent for uint64_t. Replaces dest's content.
Definition rte_string.c:341
rte_status_t rte_string_copy_n(rte_string_t *dest, const char *src, size_t src_len)
Bounded copy of an exact-length, not-necessarily-NUL-terminated source (e.g. a length-prefixed field)...
Definition rte_string.c:59
rte_status_t rte_string_to_i32(const rte_string_t *str, int32_t *out_value)
As rte_string_to_u32(), for int32_t; a leading '-' is accepted.
Definition rte_string.c:717
rte_status_t rte_string_to_i64(const rte_string_t *str, int64_t *out_value)
As rte_string_to_i32(), for int64_t.
Definition rte_string.c:625
rte_status_t rte_string_to_u32(const rte_string_t *str, uint32_t *out_value)
Bounded base-10 atoi equivalent for uint32_t.
Definition rte_string.c:700
rte_status_t rte_string_compare(const rte_string_t *a, const rte_string_t *b, int32_t *out_cmp)
Bounded strcmp equivalent. Compares up to the shorter string's length, then by length if that prefix ...
Definition rte_string.c:140
rte_status_t rte_string_from_u32(rte_string_t *dest, uint32_t value)
Bounded base-10 itoa equivalent for uint32_t. Replaces dest's content.
Definition rte_string.c:386
Cross-layer data buffer abstraction (ADR-002).
Common status/error codes returned by every Safe API Framework function. Shared across all OS Abstrac...
Common fixed-width types and the caller-owned-storage handle pattern used by every OAL service (see A...
Mutable, bounds-tracked view over caller-owned storage.
Definition rte_buffer.h:36
Read-only view of a buffer's currently valid bytes. Grants no write access to the underlying storage.
Definition rte_buffer.h:47
Bounded string: buf.length is the string length, not counting a NUL.
Definition rte_string.h:39
rte_buffer_t buf
Definition rte_string.h:40