| 262 | } |
| 263 | |
| 264 | void fx_escape(txMachine* the) |
| 265 | { |
| 266 | static const char ICACHE_RODATA_ATTR gxSet[128] = { |
| 267 | /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ |
| 268 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x */ |
| 269 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 1x */ |
| 270 | 0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1, /* 2x !"#$%&'()*+,-./ */ |
| 271 | 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, /* 3x 0123456789:;<=>? */ |
| 272 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 4x @ABCDEFGHIJKLMNO */ |
| 273 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1, /* 5X PQRSTUVWXYZ[\]^_ */ |
| 274 | 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 6x `abcdefghijklmno */ |
| 275 | 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0 /* 7X pqrstuvwxyz{|}~ */ |
| 276 | }; |
| 277 | txString src; |
| 278 | txInteger length; |
| 279 | txInteger c; |
| 280 | txString dst; |
| 281 | |
| 282 | if (mxArgc < 1) { |
| 283 | mxResult->value.string = mxUndefinedString.value.string; |
| 284 | mxResult->kind = mxUndefinedString.kind; |
| 285 | return; |
| 286 | } |
| 287 | src = fxToString(the, mxArgv(0)); |
| 288 | length = 0; |
| 289 | while (((src = mxStringByteDecode(src, &c))) && (c != C_EOF)) { |
| 290 | if ((c < 128) && c_read8(gxSet + (int)c)) |
| 291 | length = fxAddChunkSizes(the, length, 1); |
| 292 | else if (c < 256) |
| 293 | length = fxAddChunkSizes(the, length, 3); |
| 294 | else if (c < 0x10000) |
| 295 | length = fxAddChunkSizes(the, length, 6); |
| 296 | else |
| 297 | length = fxAddChunkSizes(the, length, 12); |
| 298 | } |
| 299 | length = fxAddChunkSizes(the, length, 1); |
| 300 | if (length == (src - mxArgv(0)->value.string)) { |
| 301 | mxResult->value.string = mxArgv(0)->value.string; |
| 302 | mxResult->kind = mxArgv(0)->kind; |
| 303 | return; |
| 304 | } |
| 305 | mxResult->value.string = fxNewChunk(the, length); |
| 306 | mxResult->kind = XS_STRING_KIND; |
| 307 | src = mxArgv(0)->value.string; |
| 308 | dst = mxResult->value.string; |
| 309 | while (((src = mxStringByteDecode(src, &c))) && (c != C_EOF)) { |
| 310 | if ((c < 128) && c_read8(gxSet + (int)c)) |
| 311 | *dst++ = (char)c; |
| 312 | else if (c < 256) { |
| 313 | *dst++ = '%'; |
| 314 | dst = fxStringifyHexEscape(dst, c); |
| 315 | } |
| 316 | else { |
| 317 | *dst++ = '%'; |
| 318 | *dst++ = 'u'; |
| 319 | dst = fxStringifyUnicodeEscape(dst, c, '%'); |
| 320 | } |
| 321 | } |
nothing calls this directly
no test coverage detected