ucx/string.h

Tue, 02 Oct 2012 13:43:17 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 02 Oct 2012 13:43:17 +0200
changeset 39
bf8ab7bb74ff
parent 38
35f67a8ef875
child 42
ff3dd1ee7dee
permissions
-rw-r--r--

added sstrsplit function

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

mercurial