| 936 | using a multibyte-aware field delimiter parser. */ |
| 937 | |
| 938 | static void |
| 939 | cut_fields_mb_any (FILE *stream, bool whitespace_mode) |
| 940 | { |
| 941 | static char bytes_in[IO_BUFSIZE]; |
| 942 | mbbuf_t mbbuf; |
| 943 | struct mbfield_parser parser = |
| 944 | { |
| 945 | .whitespace_delimited = whitespace_mode, |
| 946 | .trim_outer_whitespace = trim_outer_whitespace, |
| 947 | .at_line_start = true, |
| 948 | .saved_g = { .ch = MBBUF_EOF } |
| 949 | }; |
| 950 | uintmax_t field_idx = 1; |
| 951 | bool found_any_selected_field = false; |
| 952 | bool buffer_first_field; |
| 953 | bool have_pending_line = false; |
| 954 | |
| 955 | current_rp = frp; |
| 956 | mbbuf_init (&mbbuf, bytes_in, sizeof bytes_in, stream); |
| 957 | |
| 958 | buffer_first_field = (suppress_non_delimited ^ !print_kth (1)); |
| 959 | |
| 960 | while (true) |
| 961 | { |
| 962 | if (field_idx == 1 && buffer_first_field) |
| 963 | { |
| 964 | idx_t n_bytes = 0; |
| 965 | enum field_terminator terminator |
| 966 | = scan_mb_field (&mbbuf, &parser, &have_pending_line, false, |
| 967 | &n_bytes); |
| 968 | if (terminator == FIELD_EOF && n_bytes == 0) |
| 969 | return; |
| 970 | |
| 971 | if (terminator != FIELD_DELIMITER) |
| 972 | { |
| 973 | if (!suppress_non_delimited) |
| 974 | { |
| 975 | write_bytes (field_1_buffer, n_bytes); |
| 976 | write_line_delim (); |
| 977 | } |
| 978 | |
| 979 | if (terminator == FIELD_EOF) |
| 980 | break; |
| 981 | |
| 982 | reset_field_line (&field_idx, &found_any_selected_field, |
| 983 | &have_pending_line, &parser); |
| 984 | continue; |
| 985 | } |
| 986 | |
| 987 | if (print_kth (1)) |
| 988 | { |
| 989 | write_bytes (field_1_buffer, n_bytes); |
| 990 | found_any_selected_field = true; |
| 991 | } |
| 992 | next_item (&field_idx); |
| 993 | } |
| 994 | |
| 995 | enum field_terminator terminator; |
no test coverage detected