| 862 | multibyte characters. */ |
| 863 | |
| 864 | static void |
| 865 | cut_characters_mode (FILE *stream, bool byte_mode) |
| 866 | { |
| 867 | uintmax_t idx = 0; |
| 868 | bool print_delimiter = false; |
| 869 | static char bytes_in[IO_BUFSIZE]; |
| 870 | mbbuf_t mbbuf; |
| 871 | |
| 872 | current_rp = frp; |
| 873 | mbbuf_init (&mbbuf, bytes_in, sizeof bytes_in, stream); |
| 874 | |
| 875 | while (true) |
| 876 | { |
| 877 | mcel_t g = mbbuf_get_char (&mbbuf); |
| 878 | |
| 879 | if (g.ch == line_delim) |
| 880 | reset_item_line (&idx, &print_delimiter); |
| 881 | else if (g.ch == MBBUF_EOF) |
| 882 | { |
| 883 | write_pending_line_delim (idx); |
| 884 | break; |
| 885 | } |
| 886 | else if (byte_mode) |
| 887 | { |
| 888 | bool first_selected_is_range_start = false; |
| 889 | bool seen_selected = false; |
| 890 | bool suffix_selected = true; |
| 891 | |
| 892 | for (idx_t i = 0; i < g.len; i++) |
| 893 | { |
| 894 | next_item (&idx); |
| 895 | if (print_kth (idx)) |
| 896 | { |
| 897 | if (!seen_selected) |
| 898 | { |
| 899 | seen_selected = true; |
| 900 | first_selected_is_range_start |
| 901 | = is_range_start_index (idx); |
| 902 | } |
| 903 | } |
| 904 | else if (seen_selected) |
| 905 | suffix_selected = false; |
| 906 | } |
| 907 | |
| 908 | if (seen_selected && suffix_selected) |
| 909 | write_selected_item (&print_delimiter,first_selected_is_range_start, |
| 910 | mbbuf_char_offset (&mbbuf, g), g.len); |
| 911 | } |
| 912 | else |
| 913 | { |
| 914 | next_item (&idx); |
| 915 | if (print_kth (idx)) |
| 916 | write_selected_item (&print_delimiter, |
| 917 | is_range_start_index (idx), |
| 918 | mbbuf_char_offset (&mbbuf, g), g.len); |
| 919 | } |
| 920 | } |
| 921 | } |
no test coverage detected