| 178 | |
| 179 | |
| 180 | const char* removeUnit(const char *string, U32 index, const char *set) |
| 181 | { |
| 182 | U32 sz; |
| 183 | const char *start = string; |
| 184 | AssertFatal( dStrlen(string) + 1 < sizeof( _returnBuffer ), "Size of returned string too large for return buffer" ); |
| 185 | |
| 186 | char *ret = &_returnBuffer[0]; |
| 187 | ret[0] = '\0'; |
| 188 | |
| 189 | while(index--) |
| 190 | { |
| 191 | sz = dStrcspn(string, set); |
| 192 | // if there was no unit out there... return the original string |
| 193 | if(string[sz] == 0) |
| 194 | return start; |
| 195 | else |
| 196 | string += (sz + 1); |
| 197 | } |
| 198 | // copy first chunk |
| 199 | sz = (U32)(string-start); |
| 200 | dStrncpy(ret, start, sz); |
| 201 | ret[sz] = 0; |
| 202 | |
| 203 | // copy remaining chunks |
| 204 | sz = dStrcspn(string, set); // skip chunk we're removing |
| 205 | |
| 206 | if(string[sz] == 0) { // if that was the last... |
| 207 | if(string != start) { |
| 208 | ret[string - start - 1] = 0; // then kill any trailing delimiter |
| 209 | } |
| 210 | return ret; // and bail |
| 211 | } |
| 212 | |
| 213 | string += sz + 1; // skip the extra field delimiter |
| 214 | dStrcat(ret, string); |
| 215 | return ret; |
| 216 | } |
| 217 | }; |