| 9224 | // UnsignedChar is the unsigned version of Char, which is the type of c. |
| 9225 | template <typename UnsignedChar, typename Char> |
| 9226 | void PrintCharAndCodeTo(Char c, ostream* os) { |
| 9227 | // First, print c as a literal in the most readable form we can find. |
| 9228 | *os << ((sizeof(c) > 1) ? "L'" : "'"); |
| 9229 | const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os); |
| 9230 | *os << "'"; |
| 9231 | |
| 9232 | // To aid user debugging, we also print c's code in decimal, unless |
| 9233 | // it's 0 (in which case c was printed as '\\0', making the code |
| 9234 | // obvious). |
| 9235 | if (c == 0) |
| 9236 | return; |
| 9237 | *os << " (" << static_cast<int>(c); |
| 9238 | |
| 9239 | // For more convenience, we print c's code again in hexidecimal, |
| 9240 | // unless c was already printed in the form '\x##' or the code is in |
| 9241 | // [1, 9]. |
| 9242 | if (format == kHexEscape || (1 <= c && c <= 9)) { |
| 9243 | // Do nothing. |
| 9244 | } else { |
| 9245 | *os << ", 0x" << String::FormatHexInt(static_cast<UnsignedChar>(c)); |
| 9246 | } |
| 9247 | *os << ")"; |
| 9248 | } |
| 9249 | |
| 9250 | void PrintTo(unsigned char c, ::std::ostream* os) { |
| 9251 | PrintCharAndCodeTo<unsigned char>(c, os); |
nothing calls this directly
no outgoing calls
no test coverage detected