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

Function setUnit

engine/source/string/stringUnit.cpp:136–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134
135
136 const char* setUnit(const char *string, U32 index, const char *replace, const char *set)
137 {
138 U32 sz;
139 const char *start = string;
140
141 AssertFatal( dStrlen(string) + dStrlen(replace) + 1 < sizeof( _returnBuffer ), "Size of returned string too large for return buffer" );
142
143 char *ret = &_returnBuffer[0];
144 ret[0] = '\0';
145 U32 padCount = 0;
146
147 while(index--)
148 {
149 sz = dStrcspn(string, set);
150 if(string[sz] == 0)
151 {
152 string += sz;
153 padCount = index + 1;
154 break;
155 }
156 else
157 string += (sz + 1);
158 }
159 // copy first chunk
160 sz = (U32)(string-start);
161 dStrncpy(ret, start, sz);
162 for(U32 i = 0; i < padCount; i++)
163 ret[sz++] = set[0];
164
165 // replace this unit
166 ret[sz] = '\0';
167 dStrcat(ret, replace);
168
169 // copy remaining chunks
170 sz = dStrcspn(string, set); // skip chunk we're replacing
171 if(!sz && !string[sz])
172 return ret;
173
174 string += sz;
175 dStrcat(ret, string);
176 return ret;
177 }
178
179
180 const char* removeUnit(const char *string, U32 index, const char *set)

Callers 3

parseFontMethod · 0.50
readBMFontMethod · 0.50

Calls 4

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

Tested by

no test coverage detected