9 #include "xmlrpc_config.h"
10 #include "xmlrpc-c/string_int.h"
15 xmlrpc_makePrintable_lp(const char * const input,
16 size_t const inputLength) {
17 /*----------------------------------------------------------------------------
18 Convert an arbitrary string of characters in length-pointer form to
19 printable ASCII. E.g. convert newlines to "\n".
21 Return the result in newly malloc'ed storage. Return NULL if we can't
23 -----------------------------------------------------------------------------*/
26 output = malloc(inputLength*4+1);
27 /* Worst case, we render a character like \x01 -- 4 characters */
30 unsigned int inputCursor, outputCursor;
32 for (inputCursor = 0, outputCursor = 0;
33 inputCursor < inputLength;
36 if (isprint(input[inputCursor]))
37 output[outputCursor++] = input[inputCursor];
38 else if (input[inputCursor] == '\n') {
39 output[outputCursor++] = '\\';
40 output[outputCursor++] = 'n';
41 } else if (input[inputCursor] == '\t') {
42 output[outputCursor++] = '\\';
43 output[outputCursor++] = 't';
44 } else if (input[inputCursor] == '\a') {
45 output[outputCursor++] = '\\';
46 output[outputCursor++] = 'a';
47 } else if (input[inputCursor] == '\r') {
48 output[outputCursor++] = '\\';
49 output[outputCursor++] = 'r';
50 } else if (input[inputCursor] == '\\') {
51 output[outputCursor++] = '\\';
52 output[outputCursor++] = '\\';
54 snprintf(&output[outputCursor], 5, "\\x%02x",
59 output[outputCursor++] = '\0';
67 xmlrpc_makePrintable(const char * const input) {
68 /*----------------------------------------------------------------------------
69 Convert an arbitrary string of characters (NUL-terminated, though) to
70 printable ASCII. E.g. convert newlines to "\n".
72 Return the result in newly malloc'ed storage. Return NULL if we can't
74 -----------------------------------------------------------------------------*/
75 return xmlrpc_makePrintable_lp(input, strlen(input));
81 xmlrpc_makePrintableChar(char const input) {
82 /*----------------------------------------------------------------------------
83 Return an ASCIIZ string consisting of the character 'input',
84 properly escaped so as to be printable. E.g., in C notation, '\n'
86 -----------------------------------------------------------------------------*/
90 retval = strdup("\\0");
97 retval = xmlrpc_makePrintable(buffer);