| 452 | static void move_to_line_end(size_t & char_pos, size_t & byte_pos, const std::vector<int> & widths, const std::string & line); |
| 453 | |
| 454 | static void delete_at_cursor(std::string & line, std::vector<int> & widths, size_t & char_pos, size_t & byte_pos) { |
| 455 | if (char_pos >= widths.size()) { |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | size_t next_pos = next_utf8_char_pos(line, byte_pos); |
| 460 | int w = widths[char_pos]; |
| 461 | size_t char_len = next_pos - byte_pos; |
| 462 | |
| 463 | line.erase(byte_pos, char_len); |
| 464 | widths.erase(widths.begin() + char_pos); |
| 465 | |
| 466 | size_t p = byte_pos; |
| 467 | int tail_width = 0; |
| 468 | for (size_t i = char_pos; i < widths.size(); ++i) { |
| 469 | size_t following = next_utf8_char_pos(line, p); |
| 470 | put_codepoint(line.c_str() + p, following - p, widths[i]); |
| 471 | tail_width += widths[i]; |
| 472 | p = following; |
| 473 | } |
| 474 | |
| 475 | for (int i = 0; i < w; ++i) { |
| 476 | fputc(' ', out); |
| 477 | } |
| 478 | |
| 479 | move_cursor(-(tail_width + w)); |
| 480 | } |
| 481 | |
| 482 | static void clear_current_line(const std::vector<int> & widths) { |
| 483 | int total_width = 0; |
no test coverage detected