MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / removeUnit

Function removeUnit

engine/source/string/stringUnit.cpp:180–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

untagMethod · 0.85

Calls 4

dStrlenFunction · 0.70
dStrcspnFunction · 0.50
dStrncpyFunction · 0.50
dStrcatFunction · 0.50

Tested by

no test coverage detected