Append to the sds string "s" an escaped string representation where * all the non-printable characters (tested with isprint()) are turned into * escapes in the form "\n\r\a...." or "\x ". * * After the call, the modified sds string is no longer valid and all the * references must be substituted with the new pointer returned by the call. */
| 882 | * After the call, the modified sds string is no longer valid and all the |
| 883 | * references must be substituted with the new pointer returned by the call. */ |
| 884 | sds sdscatrepr(sds s, const char *p, size_t len) { |
| 885 | s = sdscatlen(s,"\"",1); |
| 886 | while(len--) { |
| 887 | switch(*p) { |
| 888 | case '\\': |
| 889 | case '"': |
| 890 | s = sdscatprintf(s,"\\%c",*p); |
| 891 | break; |
| 892 | case '\n': s = sdscatlen(s,"\\n",2); break; |
| 893 | case '\r': s = sdscatlen(s,"\\r",2); break; |
| 894 | case '\t': s = sdscatlen(s,"\\t",2); break; |
| 895 | case '\a': s = sdscatlen(s,"\\a",2); break; |
| 896 | case '\b': s = sdscatlen(s,"\\b",2); break; |
| 897 | default: |
| 898 | if (isprint(*p)) |
| 899 | s = sdscatprintf(s,"%c",*p); |
| 900 | else |
| 901 | s = sdscatprintf(s,"\\x%02x",(unsigned char)*p); |
| 902 | break; |
| 903 | } |
| 904 | p++; |
| 905 | } |
| 906 | return sdscatlen(s,"\"",1); |
| 907 | } |
| 908 | |
| 909 | /* Helper function for sdssplitargs() that returns non zero if 'c' |
| 910 | * is a valid hex digit. */ |
no test coverage detected