| 2695 | } |
| 2696 | |
| 2697 | static void expand_tabs(hoedown_buffer *ob, const uint8_t *line, size_t size) |
| 2698 | { |
| 2699 | /* This code makes two assumptions: |
| 2700 | * - Input is valid UTF-8. (Any byte with top two bits 10 is skipped, |
| 2701 | * whether or not it is a valid UTF-8 continuation byte.) |
| 2702 | * - Input contains no combining characters. (Combining characters |
| 2703 | * should be skipped but are not.) |
| 2704 | */ |
| 2705 | size_t i = 0, tab = 0; |
| 2706 | |
| 2707 | while (i < size) { |
| 2708 | size_t org = i; |
| 2709 | |
| 2710 | while (i < size && line[i] != '\t') { |
| 2711 | /* ignore UTF-8 continuation bytes */ |
| 2712 | if ((line[i] & 0xc0) != 0x80) |
| 2713 | tab++; |
| 2714 | i++; |
| 2715 | } |
| 2716 | |
| 2717 | if (i > org) |
| 2718 | hoedown_buffer_put(ob, line + org, i - org); |
| 2719 | |
| 2720 | if (i >= size) |
| 2721 | break; |
| 2722 | |
| 2723 | do { |
| 2724 | hoedown_buffer_putc(ob, ' '); tab++; |
| 2725 | } while (tab % 4); |
| 2726 | |
| 2727 | i++; |
| 2728 | } |
| 2729 | } |
| 2730 | |
| 2731 | /********************** |
| 2732 | * EXPORTED FUNCTIONS * |
no test coverage detected