/src/node/src/embedded_data.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "embedded_data.h" |
2 | | #include <vector> |
3 | | |
4 | | namespace node { |
5 | 0 | std::string ToOctalString(const uint8_t ch) { |
6 | | // We can print most printable characters directly. The exceptions are '\' |
7 | | // (escape characters), " (would end the string), and ? (trigraphs). The |
8 | | // latter may be overly conservative: we compile with C++17 which doesn't |
9 | | // support trigraphs. |
10 | 0 | if (ch >= ' ' && ch <= '~' && ch != '\\' && ch != '"' && ch != '?') { |
11 | 0 | return std::string(1, static_cast<char>(ch)); |
12 | 0 | } |
13 | | // All other characters are blindly output as octal. |
14 | 0 | const char c0 = '0' + ((ch >> 6) & 7); |
15 | 0 | const char c1 = '0' + ((ch >> 3) & 7); |
16 | 0 | const char c2 = '0' + (ch & 7); |
17 | 0 | return std::string("\\") + c0 + c1 + c2; |
18 | 0 | } |
19 | | |
20 | 0 | std::vector<std::string> GetOctalTable() { |
21 | 0 | size_t size = 1 << 8; |
22 | 0 | std::vector<std::string> code_table(size); |
23 | 0 | for (size_t i = 0; i < size; ++i) { |
24 | 0 | code_table[i] = ToOctalString(static_cast<uint8_t>(i)); |
25 | 0 | } |
26 | 0 | return code_table; |
27 | 0 | } |
28 | | |
29 | 0 | const std::string& GetOctalCode(uint8_t index) { |
30 | 0 | static std::vector<std::string> table = GetOctalTable(); |
31 | 0 | return table[index]; |
32 | 0 | } |
33 | | } // namespace node |