Thu, 11 Oct 2012 16:29:30 +0200
removed const from string.*
1 /*
2 * File: sstring.h
3 * Author: olaf
4 *
5 * Created on 17. Juni 2010, 13:26
6 */
8 #ifndef _SSTRING_H
9 #define _SSTRING_H
11 #include <stddef.h>
13 /* use macros for literals only */
14 #define S(s) { s, sizeof(s)-1 }
15 #define ST(s) sstrn(s, sizeof(s)-1)
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
21 typedef struct sstring {
22 char *ptr;
23 size_t length;
24 } sstr_t;
26 /*
27 * creates a new sstr_t from a null terminated string
28 *
29 * s null terminated string
30 */
31 sstr_t sstr(char *s);
33 /*
34 * creates a new sstr_t from a string and length
35 *
36 * s string
37 * n length of string
38 */
39 sstr_t sstrn(char *s, size_t n);
42 /*
43 * gets the length of n sstr_t strings
44 *
45 * n number of strings
46 * s string
47 * ... strings
48 */
49 size_t sstrnlen(size_t n, sstr_t s, ...);
52 /*
53 * concatenates n strings
54 *
55 * n number of strings
56 * s new string with enough memory allocated
57 * ... strings
58 */
59 sstr_t sstrncat(size_t n, sstr_t s, sstr_t c1, ...);
62 /*
63 *
64 */
65 sstr_t sstrsubs(sstr_t s, size_t start);
67 /*
68 *
69 */
70 sstr_t sstrsubsl(sstr_t s, size_t start, size_t length);
72 /*
73 * splits s into n parts
74 *
75 * s the string to split
76 * d the delimiter string
77 * n the maximum size of the resulting list
78 * a size of 0 indicates an unbounded list size
79 * the actual size of the list will be stored here
80 *
81 * Hint: use this value to avoid dynamic reallocation of the result list
82 *
83 * Returns a list of the split strings
84 * NOTE: this list needs to be freed manually after usage
85 *
86 * Returns NULL on error
87 */
88 sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n);
90 int sstrcmp(sstr_t s1, sstr_t s2);
92 sstr_t sstrdup(sstr_t s);
94 #ifdef __cplusplus
95 }
96 #endif
98 #endif /* _SSTRING_H */