static void screen_write_cached(const uchar_t *data, uint16_t len) { if (terminal_is_utf8()) { _write_helper((const char *) data, len, NULL); } else { convert(CONVERT_U2G, (const char *) data, len, NULL, 0, _write_helper, NULL); } }
static wchar_t get_next_wchar(editor_t *editor) { const char *buffer = NULL; size_t bytes = 0; char utf8_buffer[8] = { '\0' }; int ch = terminal_getchar(); editor->input_buffer[(int) editor->pending_bytes++] = ch; if (terminal_is_utf8()) { buffer = editor->input_buffer; bytes = editor->pending_bytes; } else { if (editor->pending_bytes > 1) { convert(CONVERT_G2U, editor->input_buffer, editor->pending_bytes, utf8_buffer, sizeof(utf8_buffer), NULL, NULL); editor->pending_bytes = 0; if (utf8_buffer[0] != '\0') { buffer = utf8_buffer; bytes = strlen(utf8_buffer); } } else if (!(ch & 0x80)) { editor->pending_bytes = 0; return ch; } } if (buffer) { wchar_t wc = next_wchar(&buffer, &bytes); if ((wc && wc != WEOF) || editor->pending_bytes == sizeof(editor->input_buffer)) { editor->pending_bytes = 0; return wc; } } return 0; }