| 1805 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.=/:,@"; |
| 1806 | |
| 1807 | string 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 | |
| 1833 | static const char kHexTable[513]= |
| 1834 | "000102030405060708090a0b0c0d0e0f" |
no test coverage detected