This is the method that evaluates any substitution statements on a datablock and does the actual replacement of substituted datablock fields. Much of the work is done by passing the statement to Con::evaluate() but first there are some key operations performed on the statement. -- Instances of "%%" in the statement are replaced with the id of the object. -- Instances of "##" are replaced wi
| 191 | // -- A result of "~0" will clear the original field to "" without producing an error message. |
| 192 | // |
| 193 | void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* obj, S32 index) |
| 194 | { |
| 195 | if (!dblock || !dblock->getClassRep()) |
| 196 | { |
| 197 | // error message |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | char obj_str[32]; |
| 202 | dStrcpy(obj_str, Con::getIntArg(obj->getId()), 32); |
| 203 | |
| 204 | char index_str[32]; |
| 205 | dStrcpy(index_str, Con::getIntArg(index), 32); |
| 206 | |
| 207 | for (S32 i = 0; i < substitutions.size(); i++) |
| 208 | { |
| 209 | if (substitutions[i]) |
| 210 | { |
| 211 | static char buffer[1024]; |
| 212 | static char* b_oob = &buffer[1024]; |
| 213 | char* b = buffer; |
| 214 | |
| 215 | // perform special token expansion (%% and ##) |
| 216 | const char* v = substitutions[i]->mValue; |
| 217 | while (*v != '\0') |
| 218 | { |
| 219 | // identify "%%" tokens and replace with <obj> id |
| 220 | if (v[0] == '%' && v[1] == '%') |
| 221 | { |
| 222 | const char* s = obj_str; |
| 223 | while (*s != '\0') |
| 224 | { |
| 225 | b[0] = s[0]; |
| 226 | b++; |
| 227 | s++; |
| 228 | } |
| 229 | v += 2; |
| 230 | } |
| 231 | // identify "##" tokens and replace with <index> value |
| 232 | else if (v[0] == '#' && v[1] == '#') |
| 233 | { |
| 234 | const char* s = index_str; |
| 235 | while (*s != '\0') |
| 236 | { |
| 237 | b[0] = s[0]; |
| 238 | b++; |
| 239 | s++; |
| 240 | } |
| 241 | v += 2; |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | b[0] = v[0]; |
| 246 | b++; |
| 247 | v++; |
| 248 | } |
| 249 | } |
| 250 |
no test coverage detected