| 288 | // returns dst |
| 289 | |
| 290 | char *filtertext(char *dst, const char *src, int flags, int len) |
| 291 | { |
| 292 | char *res = dst; |
| 293 | bool nowhite = (flags & FTXT_NOWHITE) != 0, // removes all whitespace; adding ALLOWBLANKS, ALLOWNL or ALLOWTAB enables exceptions |
| 294 | allowblanks = (flags & FTXT_ALLOWBLANKS) != 0, // only in combination with FTXT_NOWHITE |
| 295 | allownl = (flags & FTXT_ALLOWNL) != 0, // only in combination with FTXT_NOWHITE |
| 296 | allowtab = (flags & FTXT_ALLOWTAB) != 0, // only in combination with FTXT_NOWHITE |
| 297 | nocolor = (flags & FTXT_NOCOLOR) != 0, // removes all '\f' + following char |
| 298 | tabtoblank = (flags & FTXT_TABTOBLANK) != 0, // replaces \t with single blanks |
| 299 | fillblanks = (flags & FTXT_FILLBLANKS) != 0, // convert ' ' to '_' |
| 300 | safecs = (flags & FTXT_SAFECS) != 0, // removes all special chars that may execute commands when evaluate arguments; the argument still requires encapsulation by "" |
| 301 | leet = (flags & FTXT_LEET) != 0, // translates leetspeak |
| 302 | toupp = (flags & FTXT_TOUPPER) != 0, // translates to all-uppercase |
| 303 | tolow = (flags & FTXT_TOLOWER) != 0, // translates to all-lowercase |
| 304 | filename = (flags & FTXT_FILENAME) != 0, // strict a-z, 0-9 and "-_.()" (also translates "[]" and "{}" to "()"), removes everything between '<' and '>' |
| 305 | allowslash = (flags & FTXT_ALLOWSLASH) != 0, // only in combination with FTXT_FILENAME or FTXT_MAPNAME |
| 306 | mapname = (flags & FTXT_MAPNAME) != 0, // only allows lowercase chars, digits, '_', '-' and '.'; probably should be used in combination with TOLOWER |
| 307 | cropwhitelead = (flags & FTXT_CROPWHITE_LEAD) != 0, // removes leading whitespace |
| 308 | cropwhitetrail = (flags & FTXT_CROPWHITE_TRAIL) != 0, // removes trailing whitespace |
| 309 | pass = false; |
| 310 | if(leet || mapname) nocolor = true; |
| 311 | #ifdef FILENAMESALLLOWERCASE |
| 312 | if(filename) tolow = true; |
| 313 | #endif |
| 314 | bool trans = toupp || tolow || leet || filename || fillblanks; |
| 315 | char *lastwhite = NULL; |
| 316 | bool insidepointybrackets = false; |
| 317 | for(int c = *src; c; c = *++src) |
| 318 | { |
| 319 | c &= 0x7F; // 7-bit ascii. not negotiable. |
| 320 | pass = false; |
| 321 | if(trans) |
| 322 | { |
| 323 | if(leet) |
| 324 | { |
| 325 | const char *org = "1374@5$2!*#%80|+", |
| 326 | *asc = "letaassziohzhoit", |
| 327 | *a = strchr(org, c); |
| 328 | if(a) c = asc[a - org]; |
| 329 | } |
| 330 | if(filename) |
| 331 | { |
| 332 | if(c == '>') insidepointybrackets = false; |
| 333 | else if(c == '<') insidepointybrackets = true; |
| 334 | if(insidepointybrackets || c == '>') continue; // filter anything between '<' and '>' as this may contain commands for texture loading |
| 335 | const char *org = "[]{}\\", |
| 336 | *asc = "()()/", |
| 337 | *a = strchr(org, c); |
| 338 | if(a) c = asc[a - org]; |
| 339 | } |
| 340 | if(tolow) c = tolower(c); |
| 341 | else if(toupp) c = toupper(c); |
| 342 | if(fillblanks && c == ' ') c = '_'; |
| 343 | } |
| 344 | if(filename && !(islower(c) |
| 345 | #ifndef FILENAMESALLLOWERCASE |
| 346 | || isupper(c) |
| 347 | #endif |
no outgoing calls
no test coverage detected