ucx/string.c

changeset 69
fb59270b1de3
parent 68
88dbea299440
child 71
303dabadff1c
equal deleted inserted replaced
68:88dbea299440 69:fb59270b1de3
4 * 4 *
5 * Created on 17. Juni 2010, 13:27 5 * Created on 17. Juni 2010, 13:27
6 */ 6 */
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 #include <strings.h> 9 #include <string.h>
10 #include <stdarg.h> 10 #include <stdarg.h>
11 11
12 #include "string.h" 12 #include "string.h"
13 13
14 sstr_t sstr(char *s) { 14 sstr_t sstr(char *s) {
108 size_t nmax = *n; 108 size_t nmax = *n;
109 *n = 1; 109 *n = 1;
110 110
111 /* special case: exact match - no processing needed */ 111 /* special case: exact match - no processing needed */
112 if (s.length == d.length && strncmp(s.ptr, d.ptr, s.length) == 0) { 112 if (s.length == d.length && strncmp(s.ptr, d.ptr, s.length) == 0) {
113 result = malloc(sizeof(sstr_t)); 113 result = (sstr_t*) malloc(sizeof(sstr_t));
114 result[0] = sstrn("", 0); 114 result[0] = sstrn("", 0);
115 return result; 115 return result;
116 } 116 }
117 sstr_t sv = sstrdup(s); 117 sstr_t sv = sstrdup(s);
118 118
135 i += d.length; 135 i += d.length;
136 } 136 }
137 } 137 }
138 if ((*n) == nmax) break; 138 if ((*n) == nmax) break;
139 } 139 }
140 result = malloc(sizeof(sstr_t) * (*n)); 140 result = (sstr_t*) malloc(sizeof(sstr_t) * (*n));
141 141
142 char *pptr = sv.ptr; 142 char *pptr = sv.ptr;
143 for (int i = 0 ; i < *n ; i++) { 143 for (int i = 0 ; i < *n ; i++) {
144 size_t l = strlen(pptr); 144 size_t l = strlen(pptr);
145 char* ptr = malloc(l + 1); 145 char* ptr = (char*) malloc(l + 1);
146 memcpy(ptr, pptr, l); 146 memcpy(ptr, pptr, l);
147 ptr[l] = 0; 147 ptr[l] = 0;
148 148
149 result[i] = sstrn(ptr, l); 149 result[i] = sstrn(ptr, l);
150 pptr += l + d.length; 150 pptr += l + d.length;

mercurial