ucx/string.h

Thu, 11 Oct 2012 16:29:30 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 11 Oct 2012 16:29:30 +0200
changeset 68
88dbea299440
parent 67
27e67e725d35
child 69
fb59270b1de3
permissions
-rw-r--r--

removed const from string.*

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

mercurial