sstr  1.0.1
sstr_t represent sequences of characters.
sstr

C/C++ CI

sstr_t are objects that represent sequences of characters. The standard C style string is a sequence of characters terminated by a null character, which is easy to cause buffer overflow. And it's annoying to pass pointer and length of string to every whare.

sstr_t supply a sstr_printf() function to format string.

The sequence of characters just like a string in C++, inside the sstr_t struct, it also has a null character at the end, so that we can use sstr_t as a C style string.

sstr_t contains a pointer to char sequence and its length, solves the security problems of standard C string. With functions bundle with sstr_t, you can easily manipulate the string just like standard C string, but in a safer way:

sstr_t stotal = sstr_new();
sstr_t s1 = sstr("hello");
sstr_t s2 = sstr("world");
sstr_append(stotal, s1);
sstr_append_of(stotal, " ", 1);
sstr_append(stotal, s2);
sstr_t result = sstr_printf("stotal=%S, c-str=%s, int=%d, long=%ld",
stotal, stotal, 123, (long)456);
puts(sstr_cstr(result));
sstr_free(result);
sstr_free(stotal);
char * sstr_cstr(sstr_t s)
Return C-style string representation of s.
Definition: sstr.c:85
void * sstr_t
sstr_t are objects that represent sequences of characters.
Definition: sstr.h:73
sstr_t sstr(const char *cstr)
Create a sstr_t from C-style (NULL-terminated) string str.
Definition: sstr.c:83
sstr_t sstr_printf(const char *fmt,...)
printf implement.
Definition: sstr.c:216
void sstr_append_of(sstr_t s, const void *data, size_t length)
Extends the sstr_t by appending additional characters in data with length of length at the end of its...
Definition: sstr.c:161
void sstr_append(sstr_t dst, sstr_t src)
Extends the sstr_t by appending additional characters contained in src.
Definition: sstr.c:168
sstr_t sstr_new()
Create an empty sstr_t.
Definition: sstr.c:41
void sstr_free(sstr_t s)
delete a sstr_t.
Definition: sstr.c:47