MCPcopy Create free account
hub / github.com/assaultcube/AC / escapestring

Function escapestring

source/src/protocol.cpp:434–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

432// counterpart of filterrichtext
433
434const char *escapestring(const char *s, bool force, bool noquotes, vector<char> *buf)
435{
436 static vector<char> strbuf[3];
437 static int stridx = 0;
438 extern bool isdedicated;
439 if(noquotes) force = false;
440 if(!s) return force ? "\"\"" : "";
441 if(!force && !*(s + strcspn(s, "\"/\\;()[] \f\t\a\n\r$"))) return s;
442 if(!buf) buf = &strbuf[stridx++];
443 stridx %= 3;
444 buf->setsize(0);
445 if(!noquotes) buf->add('"');
446 for(; *s; s++) switch(*s)
447 {
448 case '\n': buf->put("\\n", 2); break;
449 case '\r': buf->put("\\n", 2); break;
450 case '\t': buf->put("\\t", 2); break;
451 case '\a': buf->put("\\a", 2); break;
452 case '\f': buf->put("\\f", 2); break;
453 case '"': buf->put("\\\"", 2); break;
454 case '\\': buf->put("\\\\", 2); break;
455 case ' ': if(isdedicated) { buf->put("\\_", 2); break; }
456 default: buf->add(*s); break;
457 }
458 if(!noquotes) buf->add('"');
459 buf->add(0);
460 return buf->getbuf();
461}
462
463// ensures, that d is either two lowercase chars or ""
464

Callers 15

enumtodoentitiesFunction · 0.85
loopvjFunction · 0.85
loopvFunction · 0.85
loopvFunction · 0.85
command.cppFile · 0.85
enumaliasFunction · 0.85
writecfgFunction · 0.85
loopvFunction · 0.85
modeinfoFunction · 0.85
enumfilesFunction · 0.85
writeMethod · 0.85
worldio.cppFile · 0.85

Calls 4

setsizeMethod · 0.80
addMethod · 0.45
putMethod · 0.45
getbufMethod · 0.45

Tested by

no test coverage detected