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; |