Tue, 02 Oct 2012 13:43:17 +0200
added sstrsplit function
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 #define S(s) { s, sizeof(s)-1 }
14 #define ST(s) sstrn(s, sizeof(s)-1)
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
20 typedef struct sstring {
21 char *ptr;
22 size_t length;
23 } sstr_t;
25 /*
26 * creates a new sstr_t from a null terminated string
27 *
28 * s null terminated string
29 */
30 sstr_t sstr (char *s);
32 /*
33 * creates a new sstr_t from a string and length
34 *
35 * s string
36 * n length of string
37 */
38 sstr_t sstrn (char *s, size_t n);
41 /*
42 * gets the length of n sstr_t strings
43 *
44 * n number of strings
45 * s string
46 * ... strings
47 */
48 size_t sstrnlen (size_t n, sstr_t s, ...);
51 /*
52 * concatenates n strings
53 *
54 * n number of strings
55 * s new string with enough memory allocated
56 * ... strings
57 */
58 sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...);
61 /*
62 *
63 */
64 sstr_t sstrsubs (sstr_t s, size_t start);
66 /*
67 *
68 */
69 sstr_t sstrsubsl (sstr_t s, size_t start, size_t end);
71 /*
72 * splits s into n parts
73 *
74 * s the string to split
75 * d the delimiter string
76 * n the maximum size of the resulting list
77 * a size of 0 indicates an unbounded list size
78 * the actual size of the list will be stored here
79 *
80 * Hint: use this value to avoid dynamic reallocation of the result list
81 *
82 * Returns a list of the split strings
83 * NOTE: this list needs to be freed manually after usage
84 *
85 * Returns NULL on error
86 */
87 sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n);
89 int sstrcmp(sstr_t s1, sstr_t s2);
91 sstr_t sstrdup(sstr_t s);
93 #ifdef __cplusplus
94 }
95 #endif
97 #endif /* _SSTRING_H */