| 124 | |
| 125 | template<typename T> |
| 126 | static String TQuoted(const T *ptr, int len) |
| 127 | { |
| 128 | std::vector<T> quoted; |
| 129 | quoted.reserve(len*2); |
| 130 | |
| 131 | unsigned int bs_count = 0; |
| 132 | for(int j=0;j<len;j++) |
| 133 | { |
| 134 | T c = ptr[j]; |
| 135 | switch( c ) |
| 136 | { |
| 137 | case '"': |
| 138 | // Double backslashes. |
| 139 | for (int k=0;k<bs_count*2;k++) |
| 140 | quoted.push_back('\\'); |
| 141 | bs_count = 0; |
| 142 | quoted.push_back('\\'); |
| 143 | quoted.push_back('"'); |
| 144 | break; |
| 145 | case '\\': |
| 146 | // Don't know if we need to double yet. |
| 147 | bs_count++; |
| 148 | break; |
| 149 | default: |
| 150 | // Normal char |
| 151 | for (int k=0;k<bs_count;k++) |
| 152 | quoted.push_back('\\'); |
| 153 | bs_count = 0; |
| 154 | quoted.push_back(c); |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | // Add remaining backslashes, if any. |
| 159 | for (int k=0;k<bs_count*2;k++) |
| 160 | quoted.push_back('\\'); |
| 161 | int qlen = (int)quoted.size(); |
| 162 | quoted.push_back('\0'); |
| 163 | |
| 164 | return String::create( "ed[0], qlen ); |
| 165 | } |
| 166 | |
| 167 | static String quoteString(String v) |
| 168 | { |
no test coverage detected