diff options
author | mattkae <mattkae@protonmail.com> | 2022-05-11 09:23:58 -0400 |
---|---|---|
committer | mattkae <mattkae@protonmail.com> | 2022-05-11 09:23:58 -0400 |
commit | 3f4a0d5370ae6c34afe180df96add3b8522f4af1 (patch) | |
tree | ae901409e02bde8ee278475f8cf6818f8f680a60 /elpa/irony-20220110.849/server/src/support/iomanip_quoted.h |
initial commit
Diffstat (limited to 'elpa/irony-20220110.849/server/src/support/iomanip_quoted.h')
-rw-r--r-- | elpa/irony-20220110.849/server/src/support/iomanip_quoted.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/elpa/irony-20220110.849/server/src/support/iomanip_quoted.h b/elpa/irony-20220110.849/server/src/support/iomanip_quoted.h new file mode 100644 index 0000000..a8ca38b --- /dev/null +++ b/elpa/irony-20220110.849/server/src/support/iomanip_quoted.h @@ -0,0 +1,52 @@ +/**-*-C++-*- + * \file + * \brief Dumb implementation of something that might look like C++14 + * std::quoted. + * + * This file is distributed under the GNU General Public License. See + * COPYING for details. + */ + +#ifndef IRONY_MODE_SERVER_SUPPORT_IOMANIP_QUOTED_H_ +#define IRONY_MODE_SERVER_SUPPORT_IOMANIP_QUOTED_H_ + +#include <ostream> +#include <string> + +namespace support { +namespace detail { + +struct QuotedStringProxy { + QuotedStringProxy(const std::string &s) : s(s) { + } + + std::string s; +}; + +std::ostream &operator<<(std::ostream &os, const QuotedStringProxy &q) { + const std::string &s = q.s; + + os << '"'; + if (s.find_first_of("\"\\") == std::string::npos) { + os << s; + } else { + for (auto ch : s) { + if (ch == '\\' || ch == '"') + os << '\\'; + + os << ch; + } + } + os << '"'; + return os; +} + +} // namespace detail + +detail::QuotedStringProxy quoted(const std::string &s) { + return detail::QuotedStringProxy(s); +} + +} // namespace support + +#endif // IRONY_MODE_SERVER_SUPPORT_IOMANIP_QUOTED_H_ |