/* * Convert non-printable character to two or more printable characters in * "buf[]". "buf" needs to be able to hold five bytes. * Does NOT work for multi-byte characters, c must be <= 255. */ void transchar_nonprint(char_u *buf, int c) { if (c == NL) c = NUL; /* we use newline in place of a NUL */ else if (c == CAR && get_fileformat(curbuf) == EOL_MAC) c = NL; /* we use CR in place of NL in this case */ if (dy_flags & DY_UHEX) /* 'display' has "uhex" */ transchar_hex(buf, c); else if (c <= 0x7f) { /* 0x00 - 0x1f and 0x7f */ buf[0] = '^'; buf[1] = c ^ 0x40; /* DEL displayed as ^? */ buf[2] = NUL; } else if (enc_utf8 && c >= 0x80) { transchar_hex(buf, c); } else if (c >= ' ' + 0x80 && c <= '~' + 0x80) { /* 0xa0 - 0xfe */ buf[0] = '|'; buf[1] = c - 0x80; buf[2] = NUL; } else { /* 0x80 - 0x9f and 0xff */ /* * TODO: EBCDIC I don't know what to do with this chars, so I display * them as '~?' for now */ buf[0] = '~'; buf[1] = (c - 0x80) ^ 0x40; /* 0xff displayed as ~? */ buf[2] = NUL; } }
/// Convert non-printable character to two or more printable characters in /// "buf[]". "buf" needs to be able to hold five bytes. /// Does NOT work for multi-byte characters, c must be <= 255. /// /// @param buf /// @param c void transchar_nonprint(char_u *buf, int c) { if (c == NL) { // we use newline in place of a NUL c = NUL; } else if ((c == CAR) && (get_fileformat(curbuf) == EOL_MAC)) { // we use CR in place of NL in this case c = NL; } if (dy_flags & DY_UHEX) { // 'display' has "uhex" transchar_hex(buf, c); } else if (c <= 0x7f) { // 0x00 - 0x1f and 0x7f buf[0] = '^'; // DEL displayed as ^? buf[1] = c ^ 0x40; buf[2] = NUL; } else if (enc_utf8 && (c >= 0x80)) { transchar_hex(buf, c); } else if ((c >= ' ' + 0x80) && (c <= '~' + 0x80)) { // 0xa0 - 0xfe buf[0] = '|'; buf[1] = c - 0x80; buf[2] = NUL; } else { // 0x80 - 0x9f and 0xff buf[0] = '~'; buf[1] = (c - 0x80) ^ 0x40; buf[2] = NUL; } }
/// Convert non-printable characters to 2..4 printable ones /// /// @warning Does not work for multi-byte characters, c must be <= 255. /// /// @param[out] buf Buffer to store result in, must be able to hold at least /// 5 bytes (conversion result + NUL). /// @param[in] c Character to convert. NUL is assumed to be NL according to /// `:h NL-used-for-NUL`. void transchar_nonprint(char_u *buf, int c) { if (c == NL) { // we use newline in place of a NUL c = NUL; } else if ((c == CAR) && (get_fileformat(curbuf) == EOL_MAC)) { // we use CR in place of NL in this case c = NL; } assert(c <= 0xff); if (dy_flags & DY_UHEX || c > 0x7f) { // 'display' has "uhex" transchar_hex((char *)buf, c); } else { // 0x00 - 0x1f and 0x7f buf[0] = '^'; // DEL displayed as ^? buf[1] = (char_u)(c ^ 0x40); buf[2] = NUL; } }
/* * Convert non-printable character to two or more printable characters in * "buf[]". "buf" needs to be able to hold five bytes. * Does NOT work for multi-byte characters, c must be <= 255. */ void transchar_nonprint(char_u *buf, int c) { if (c == NL) c = NUL; /* we use newline in place of a NUL */ else if (c == CAR && get_fileformat(curbuf) == EOL_MAC) c = NL; /* we use CR in place of NL in this case */ if (dy_flags & DY_UHEX) /* 'display' has "uhex" */ transchar_hex(buf, c); #ifdef EBCDIC /* For EBCDIC only the characters 0-63 and 255 are not printable */ else if (CtrlChar(c) != 0 || c == DEL) #else else if (c <= 0x7f) /* 0x00 - 0x1f and 0x7f */ #endif { buf[0] = '^'; #ifdef EBCDIC if (c == DEL) buf[1] = '?'; /* DEL displayed as ^? */ else buf[1] = CtrlChar(c); #else buf[1] = c ^ 0x40; /* DEL displayed as ^? */ #endif buf[2] = NUL; } #ifdef FEAT_MBYTE else if (enc_utf8 && c >= 0x80) { transchar_hex(buf, c); } #endif #ifndef EBCDIC else if (c >= ' ' + 0x80 && c <= '~' + 0x80) /* 0xa0 - 0xfe */ { buf[0] = '|'; buf[1] = c - 0x80; buf[2] = NUL; } #else else if (c < 64) { buf[0] = '~'; buf[1] = MetaChar(c); buf[2] = NUL; } #endif else /* 0x80 - 0x9f and 0xff */ { /* * TODO: EBCDIC I don't know what to do with this chars, so I display * them as '~?' for now */ buf[0] = '~'; #ifdef EBCDIC buf[1] = '?'; /* 0xff displayed as ~? */ #else buf[1] = (c - 0x80) ^ 0x40; /* 0xff displayed as ~? */ #endif buf[2] = NUL; } }