line-ed: add unicode support
This commit is contained in:
+22
-12
@@ -19,29 +19,39 @@ void alloc_empty_history_entry(struct line_ed *ed)
|
||||
|
||||
void save_buf_to_history(struct line_ed *ed)
|
||||
{
|
||||
fx_string *cur
|
||||
= (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
|
||||
fx_string_replace_all(cur, ed->l_buf);
|
||||
fx_string *cur = (fx_string *)fx_array_get(
|
||||
ed->l_history,
|
||||
ed->l_history_pos);
|
||||
fx_string_clear(cur);
|
||||
fx_string_append_wstr(cur, ed->l_buf);
|
||||
}
|
||||
|
||||
void append_buf_to_history(struct line_ed *ed)
|
||||
{
|
||||
fx_string *cur
|
||||
= (fx_string *)fx_array_get(ed->l_history, ed->l_history_pos);
|
||||
fx_string *cur = (fx_string *)fx_array_get(
|
||||
ed->l_history,
|
||||
ed->l_history_pos);
|
||||
char s[] = {'\n', 0};
|
||||
fx_string_append_cstr(cur, s);
|
||||
fx_string_append_cstr(cur, ed->l_buf);
|
||||
fx_string_append_wstr(cur, ed->l_buf);
|
||||
}
|
||||
|
||||
void load_buf_from_history(struct line_ed *ed)
|
||||
{
|
||||
fx_string *cur
|
||||
= (fx_string *)fx_array_at(ed->l_history, ed->l_history_pos);
|
||||
size_t len
|
||||
= MIN((size_t)(ed->l_buf_end - ed->l_buf - 1),
|
||||
fx_string_get_size(cur, FX_STRLEN_NORMAL));
|
||||
fx_string *cur = (fx_string *)fx_array_at(
|
||||
ed->l_history,
|
||||
ed->l_history_pos);
|
||||
size_t len = MIN(
|
||||
(size_t)(ed->l_buf_end - ed->l_buf - 1),
|
||||
fx_string_get_size(cur, FX_STRLEN_CODEPOINTS));
|
||||
|
||||
const char *src = fx_string_get_cstr(cur);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
fx_wchar ch_src = fx_wchar_utf8_codepoint_decode(src);
|
||||
ed->l_buf[i] = ch_src;
|
||||
src += fx_wchar_utf8_codepoint_stride(src);
|
||||
}
|
||||
|
||||
memcpy(ed->l_buf, fx_string_get_cstr(cur), len);
|
||||
ed->l_buf[len] = '\0';
|
||||
|
||||
unsigned int x = 0, y = 0;
|
||||
|
||||
Reference in New Issue
Block a user