Changeset 3171 in MondoRescue for branches/3.0/mondo/src/lib
- Timestamp:
- Jul 28, 2013, 7:37:35 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/lib/mr_str.c
r2972 r3171 12 12 13 13 #include "mr_mem.h" 14 15 // to get bool type 16 #define _MY_STUFF_H_ 17 #include "my-stuff.h" 14 18 15 19 /** … … 66 70 * @note this function allocates memory that needs to be freed by caller 67 71 **/ 68 char *mr_stresc(char *instr, char *toesc, const char escchr ) {72 char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr) { 69 73 char *inptr = NULL; 70 74 char *retstr = NULL; … … 72 76 char *escptr = NULL; 73 77 int cnt = 0; 78 bool found = FALSE; 74 79 75 80 inptr = instr; 76 77 81 // Count how many characters need escaping. 78 82 while (*inptr != '\0') { … … 82 86 // Found it, skip the rest. 83 87 cnt++; 88 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 89 if (*inptr == specialchr) { 90 cnt += 2; 91 } 84 92 break; 85 93 } … … 88 96 inptr++; 89 97 } 98 90 99 inptr = instr; 91 92 100 retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1); 93 101 retptr = retstr; … … 99 107 if (*inptr == *escptr) { 100 108 // Found it, skip the rest. 101 *retptr = escchr; 102 retptr++; 109 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 110 if (*inptr == specialchr) { 111 *retptr = specialchr; 112 retptr++; 113 *retptr = escchr; 114 retptr++; 115 found = TRUE; 116 } else { 117 *retptr = escchr; 118 retptr++; 119 } 103 120 break; 104 121 } … … 108 125 retptr++; 109 126 inptr++; 127 if (found) { 128 // finish to put the remaining specialchr 129 *retptr = specialchr; 130 retptr++; 131 found = FALSE; 132 } 110 133 } 111 134 *retptr = '\0';
Note:
See TracChangeset
for help on using the changeset viewer.