MCPcopy Create free account
hub / github.com/duckdb/duckdb / resolve_backslashes

Function resolve_backslashes

tools/shell/shell.cpp:1229–1270  ·  view source on GitHub ↗

** Do C-language style dequoting. ** ** \a -> alarm ** \b -> backspace ** \t -> tab ** \n -> newline ** \v -> vertical tab ** \f -> form feed ** \r -> carriage return ** \s -> space ** \" -> " ** \' -> ' ** \\ -> backslash ** \NNN -> ascii character NNN in octal */

Source from the content-addressed store, hash-verified

1227** \NNN -> ascii character NNN in octal
1228*/
1229static string resolve_backslashes(const string &z) {
1230 string result;
1231 for (idx_t pos = 0; pos < z.size(); pos++) {
1232 auto c = z[pos];
1233 if (c == '\\' && pos + 1 < z.size()) {
1234 c = z[++pos];
1235 if (c == 'a') {
1236 c = '\a';
1237 } else if (c == 'b') {
1238 c = '\b';
1239 } else if (c == 't') {
1240 c = '\t';
1241 } else if (c == 'n') {
1242 c = '\n';
1243 } else if (c == 'v') {
1244 c = '\v';
1245 } else if (c == 'f') {
1246 c = '\f';
1247 } else if (c == 'r') {
1248 c = '\r';
1249 } else if (c == '"') {
1250 c = '"';
1251 } else if (c == '\'') {
1252 c = '\'';
1253 } else if (c == '\\') {
1254 c = '\\';
1255 } else if (c >= '0' && c <= '7') {
1256 c -= '0';
1257 if (pos + 1 < z.size() && z[pos + 1] >= '0' && z[pos + 1] <= '7') {
1258 pos++;
1259 c = (c << 3) + z[pos] - '0';
1260 if (pos + 1 < z.size() && z[pos + 1] >= '0' && z[pos + 1] <= '7') {
1261 pos++;
1262 c = (c << 3) + z[pos] - '0';
1263 }
1264 }
1265 }
1266 }
1267 result += c;
1268 }
1269 return result;
1270}
1271
1272/*
1273** Interpret zArg as either an integer or a boolean value. Return 1 or 0

Callers 1

DoMetaCommandMethod · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected