MCPcopy Create free account
hub / github.com/coreutils/coreutils / cut_characters_mode

Function cut_characters_mode

src/cut.c:864–921  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

862 multibyte characters. */
863
864static void
865cut_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}

Callers 2

cut_bytes_no_splitFunction · 0.85
cut_charactersFunction · 0.85

Calls 9

mbbuf_initFunction · 0.85
mbbuf_get_charFunction · 0.85
reset_item_lineFunction · 0.85
write_pending_line_delimFunction · 0.85
next_itemFunction · 0.85
print_kthFunction · 0.85
is_range_start_indexFunction · 0.85
write_selected_itemFunction · 0.85
mbbuf_char_offsetFunction · 0.85

Tested by

no test coverage detected