static void ascii_printable_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, bool bind_friendly) { if (bind_friendly && must_escape(wc)) { std::swprintf(buf, buf_len, L"\\%c", wc); } else { std::swprintf(buf, buf_len, L"%c", wc); } }
static char *char_to_symbol(wchar_t wc, bool bind_friendly) { static char buf[128]; if (wc < ' ') { // ASCII control character. if (ctrl_symbolic_names[wc]) { if (bind_friendly) { snprintf(buf, sizeof(buf), "%s", ctrl_symbolic_names[wc]); } else { snprintf(buf, sizeof(buf), "\\c%c (or %s)", wc + 64, ctrl_symbolic_names[wc]); } } else { snprintf(buf, sizeof(buf), "\\c%c", wc + 64); } } else if (wc == ' ') { // The "space" character. if (bind_friendly) { snprintf(buf, sizeof(buf), "\\x%X", wc); } else { snprintf(buf, sizeof(buf), "\\x%X (aka \"space\")", wc); } } else if (wc == 0x7F) { // The "del" character. if (bind_friendly) { snprintf(buf, sizeof(buf), "\\x%X", wc); } else { snprintf(buf, sizeof(buf), "\\x%X (aka \"del\")", wc); } } else if (wc < 0x80) { // ASCII characters that are not control characters. if (bind_friendly && must_escape(wc)) { snprintf(buf, sizeof(buf), "\\%c", wc); } else { snprintf(buf, sizeof(buf), "%c", wc); } } else if (wc <= 0xFFFF) { snprintf(buf, sizeof(buf), "\\u%04X", wc); } else { snprintf(buf, sizeof(buf), "\\U%06X", wc); } return buf; }