François Degros | 899487c | 2019-07-12 11:57:52 +1000 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "cros-disks/quote.h" |
| 6 | |
| 7 | #include <iomanip> |
| 8 | |
| 9 | namespace cros_disks { |
| 10 | |
François Degros | ca45086 | 2021-01-14 14:40:02 +1100 | [diff] [blame] | 11 | static const char kRedacted[] = "(redacted)"; |
| 12 | |
François Degros | 899487c | 2019-07-12 11:57:52 +1000 | [diff] [blame] | 13 | std::ostream& operator<<(std::ostream& out, Quoter<const char*> quoter) { |
| 14 | const char* const s = quoter.ref; |
François Degros | ca45086 | 2021-01-14 14:40:02 +1100 | [diff] [blame] | 15 | if (!s) |
| 16 | return out << "(null)"; |
| 17 | |
| 18 | if (quoter.redacted) |
| 19 | return out << kRedacted; |
| 20 | |
| 21 | return out << std::quoted(s, '\''); |
François Degros | 899487c | 2019-07-12 11:57:52 +1000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | std::ostream& operator<<(std::ostream& out, Quoter<std::string> quoter) { |
François Degros | ca45086 | 2021-01-14 14:40:02 +1100 | [diff] [blame] | 25 | if (quoter.redacted) |
| 26 | return out << kRedacted; |
| 27 | |
François Degros | 899487c | 2019-07-12 11:57:52 +1000 | [diff] [blame] | 28 | return out << std::quoted(quoter.ref, '\''); |
| 29 | } |
| 30 | |
| 31 | std::ostream& operator<<(std::ostream& out, Quoter<base::FilePath> quoter) { |
François Degros | ca45086 | 2021-01-14 14:40:02 +1100 | [diff] [blame] | 32 | if (quoter.redacted) |
| 33 | return out << kRedacted; |
| 34 | |
François Degros | 899487c | 2019-07-12 11:57:52 +1000 | [diff] [blame] | 35 | return out << std::quoted(quoter.ref.value(), '\''); |
| 36 | } |
| 37 | |
| 38 | } // namespace cros_disks |