1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ucx/string.h Thu Jan 05 14:53:54 2012 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* 1.5 + * File: sstring.h 1.6 + * Author: olaf 1.7 + * 1.8 + * Created on 17. Juni 2010, 13:26 1.9 + */ 1.10 + 1.11 +#ifndef _SSTRING_H 1.12 +#define _SSTRING_H 1.13 + 1.14 +#define S(s) { s, sizeof(s)-1 } 1.15 +#define ST(s) sstrn(s, sizeof(s)-1) 1.16 + 1.17 +#ifdef __cplusplus 1.18 +extern "C" { 1.19 +#endif 1.20 + 1.21 +typedef struct sstring { 1.22 + char *ptr; 1.23 + size_t length; 1.24 +} sstr_t; 1.25 + 1.26 +/* 1.27 + * creates a new sstr_t from a null terminated string 1.28 + * 1.29 + * s null terminated string 1.30 + */ 1.31 +sstr_t sstr (char *s); 1.32 + 1.33 +/* 1.34 + * creates a new sstr_t from a string and length 1.35 + * 1.36 + * s string 1.37 + * n length of string 1.38 + */ 1.39 +sstr_t sstrn (char *s, size_t n); 1.40 + 1.41 + 1.42 +/* 1.43 + * gets the length of n sstr_t strings 1.44 + * 1.45 + * n number of strings 1.46 + * s string 1.47 + * ... strings 1.48 + */ 1.49 +size_t sstrnlen (size_t n, sstr_t s, ...); 1.50 + 1.51 + 1.52 +/* 1.53 + * concatenates n strings 1.54 + * 1.55 + * n number of strings 1.56 + * s new string with enough memory allocated 1.57 + * ... strings 1.58 + */ 1.59 +sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...); 1.60 + 1.61 + 1.62 +/* 1.63 + * 1.64 + */ 1.65 +sstr_t sstrsubs (sstr_t s, size_t start); 1.66 + 1.67 +/* 1.68 + * 1.69 + */ 1.70 +sstr_t sstrsubsl (sstr_t s, size_t start, size_t end); 1.71 + 1.72 + 1.73 +int sstrcmp(sstr_t s1, sstr_t s2); 1.74 + 1.75 +sstr_t sstrdub(sstr_t s); 1.76 + 1.77 +#ifdef __cplusplus 1.78 +} 1.79 +#endif 1.80 + 1.81 +#endif /* _SSTRING_H */