블로그 (Blog)/개발로그 (Devlogs)
Simple Dynamic Strings
ihmin
2024. 3. 15. 11:00
홈페이지: https://github.com/antirez/sds
C용 스트링 처리 라이브러리로.. 아래를 지원
Concatenating, Formatting, Trimming strings and getting ranges, Fast number to string operations, String copying, Quoting strings, Tokenization, String joining
아래는 concat의 예제로 메모리를 자동으로 동적 할당.
#include <sds.h>
void test(char **s)
{
*s = sdscat(*s, "foo");
*s = sdscat(*s, "bar");
*s = sdscat(*s, "123");
}
void main(void)
{
sds s;
s = sdsempty();
s = sdscat(s, "foo");
s = sdscat(s, "bar");
s = sdscat(s, "123");
printf("%s\n", s);
sdsfree(s);
s = sdsempty();
test(&s);
printf("%s\n", s);
sdsfree(s);
}