| 8763 | // UnsignedChar is the unsigned version of Char, which is the type of c. |
| 8764 | template <typename UnsignedChar, typename Char> |
| 8765 | void PrintCharAndCodeTo(Char c, ostream* os) { |
| 8766 | // First, print c as a literal in the most readable form we can find. |
| 8767 | *os << ((sizeof(c) > 1) ? "L'" : "'"); |
| 8768 | const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os); |
| 8769 | *os << "'"; |
| 8770 | |
| 8771 | // To aid user debugging, we also print c's code in decimal, unless |
| 8772 | // it's 0 (in which case c was printed as '\\0', making the code |
| 8773 | // obvious). |
| 8774 | if (c == 0) |
| 8775 | return; |
| 8776 | *os << " (" << String::Format("%d", c).c_str(); |
| 8777 | |
| 8778 | // For more convenience, we print c's code again in hexidecimal, |
| 8779 | // unless c was already printed in the form '\x##' or the code is in |
| 8780 | // [1, 9]. |
| 8781 | if (format == kHexEscape || (1 <= c && c <= 9)) { |
| 8782 | // Do nothing. |
| 8783 | } else { |
| 8784 | *os << String::Format(", 0x%X", |
| 8785 | static_cast<UnsignedChar>(c)).c_str(); |
| 8786 | } |
| 8787 | *os << ")"; |
| 8788 | } |
| 8789 | |
| 8790 | void PrintTo(unsigned char c, ::std::ostream* os) { |
| 8791 | PrintCharAndCodeTo<unsigned char>(c, os); |
nothing calls this directly
no outgoing calls
no test coverage detected