[169] | 1 | #ifndef SH_STRING_H
|
---|
| 2 | #define SH_STRING_H
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | /* String definition and utility functions.
|
---|
| 6 | */
|
---|
| 7 | typedef struct sh_str_struct
|
---|
| 8 | {
|
---|
| 9 | char * str; /* always NULL terminated */
|
---|
| 10 | size_t len; /* without terminating \0 */
|
---|
| 11 | size_t siz; /* size of allocated buffer */
|
---|
| 12 | } sh_string;
|
---|
| 13 |
|
---|
| 14 | sh_string * sh_string_new(size_t size);
|
---|
| 15 | void sh_string_destroy(sh_string ** s);
|
---|
| 16 | #define sh_string_str(a) ((a)->str)
|
---|
| 17 | #define sh_string_len(a) ((a)->len)
|
---|
| 18 |
|
---|
| 19 | /* concat string to sh_string
|
---|
| 20 | */
|
---|
| 21 | sh_string * sh_string_cat_lchar(sh_string * s, char * str, size_t len);
|
---|
| 22 |
|
---|
| 23 | /* set sh_string from string
|
---|
| 24 | */
|
---|
| 25 | sh_string * sh_string_set_from_char(sh_string * s, char * str);
|
---|
| 26 |
|
---|
| 27 | /* create new sh_string from array of given length
|
---|
| 28 | */
|
---|
| 29 | sh_string * sh_string_new_from_lchar(char * str, size_t len);
|
---|
| 30 |
|
---|
| 31 | #define sh_string_copy(a) ((a) ? sh_string_new_from_lchar(((a)->str), ((a)->len)) : NULL)
|
---|
| 32 |
|
---|
| 33 | /* create new sh_string from three arrays of given length
|
---|
| 34 | */
|
---|
| 35 | sh_string * sh_string_new_from_lchar3(char * str1, size_t len1,
|
---|
| 36 | char * str2, size_t len2,
|
---|
| 37 | char * str3, size_t len3);
|
---|
| 38 |
|
---|
| 39 | /* Truncate to desired length.
|
---|
| 40 | */
|
---|
| 41 | sh_string * sh_string_truncate(sh_string * s, size_t len);
|
---|
| 42 |
|
---|
| 43 | /* If requested increase is zero, increase by default amount.
|
---|
| 44 | */
|
---|
| 45 | sh_string * sh_string_grow(sh_string * s, size_t increase);
|
---|
| 46 |
|
---|
| 47 | #endif
|
---|