MCPcopy Create free account
hub / github.com/apache/impala / ShellEscape

Function ShellEscape

be/src/gutil/strings/escaping.cc:1807–1831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1805"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.=/:,@";
1806
1807string ShellEscape(StringPiece src) {
1808 if (!src.empty() && // empty string needs quotes
1809 src.find_first_not_of(kDontNeedShellEscapeChars) == StringPiece::npos) {
1810 // only contains chars that don't need quotes; it's fine
1811 return src.ToString();
1812 } else if (src.find('\'') == StringPiece::npos) {
1813 // no single quotes; just wrap it in single quotes
1814 return StrCat("'", src, "'");
1815 } else {
1816 // needs double quote escaping
1817 string result = "\"";
1818 for (char c : src) {
1819 switch (c) {
1820 case '\\':
1821 case '$':
1822 case '"':
1823 case '`':
1824 result.push_back('\\');
1825 };
1826 result.push_back(c);
1827 }
1828 result.push_back('"');
1829 return result;
1830 }
1831}
1832
1833static const char kHexTable[513]=
1834 "000102030405060708090a0b0c0d0e0f"

Callers 1

ShellEscapeCommandLineFunction · 0.85

Calls 6

find_first_not_ofMethod · 0.80
push_backMethod · 0.80
StrCatFunction · 0.70
emptyMethod · 0.45
ToStringMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected