| 493 | } |
| 494 | |
| 495 | static void set_line_contents(std::string new_line, std::string & line, std::vector<int> & widths, size_t & char_pos, |
| 496 | size_t & byte_pos) { |
| 497 | move_to_line_start(char_pos, byte_pos, widths); |
| 498 | clear_current_line(widths); |
| 499 | |
| 500 | line = std::move(new_line); |
| 501 | widths.clear(); |
| 502 | byte_pos = 0; |
| 503 | char_pos = 0; |
| 504 | |
| 505 | size_t idx = 0; |
| 506 | while (idx < line.size()) { |
| 507 | size_t advance = 0; |
| 508 | char32_t cp = decode_utf8(line, idx, advance); |
| 509 | int expected_width = estimateWidth(cp); |
| 510 | int real_width = put_codepoint(line.c_str() + idx, advance, expected_width); |
| 511 | if (real_width < 0) real_width = 0; |
| 512 | widths.push_back(real_width); |
| 513 | idx += advance; |
| 514 | ++char_pos; |
| 515 | byte_pos = idx; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | static void move_to_line_start(size_t & char_pos, size_t & byte_pos, const std::vector<int> & widths) { |
| 520 | int back_width = 0; |
no test coverage detected