@@ -478,43 +478,39 @@ static int find_unique(const char *choice, struct menu_stuff *menu_stuff)
478478 */
479479static int parse_choice (struct menu_stuff * menu_stuff ,
480480 int is_single ,
481- struct strbuf input ,
481+ char * input ,
482482 int * * chosen )
483483{
484- struct strbuf * * choice_list , * * ptr ;
484+ struct string_list choice = STRING_LIST_INIT_NODUP ;
485+ struct string_list_item * item ;
485486 int nr = 0 ;
486487 int i ;
487488
488- if (is_single ) {
489- choice_list = strbuf_split_max (& input , '\n' , 0 );
490- } else {
491- char * p = input .buf ;
492- do {
493- if (* p == ',' )
494- * p = ' ' ;
495- } while (* p ++ );
496- choice_list = strbuf_split_max (& input , ' ' , 0 );
497- }
489+ string_list_split_in_place_f (& choice , input ,
490+ is_single ? "\n" : ", " , -1 ,
491+ STRING_LIST_SPLIT_TRIM );
498492
499- for ( ptr = choice_list ; * ptr ; ptr ++ ) {
500- char * p ;
501- int choose = 1 ;
493+ for_each_string_list_item ( item , & choice ) {
494+ const char * string ;
495+ int choose ;
502496 int bottom = 0 , top = 0 ;
503497 int is_range , is_number ;
504498
505- strbuf_trim ( * ptr ) ;
506- if (!( * ptr ) -> len )
499+ string = item -> string ;
500+ if (!* string )
507501 continue ;
508502
509503 /* Input that begins with '-'; unchoose */
510- if (* ( * ptr ) -> buf == '-' ) {
504+ if (string [ 0 ] == '-' ) {
511505 choose = 0 ;
512- strbuf_remove ((* ptr ), 0 , 1 );
506+ string ++ ;
507+ } else {
508+ choose = 1 ;
513509 }
514510
515511 is_range = 0 ;
516512 is_number = 1 ;
517- for (p = ( * ptr ) -> buf ; * p ; p ++ ) {
513+ for (const char * p = string ; * p ; p ++ ) {
518514 if ('-' == * p ) {
519515 if (!is_range ) {
520516 is_range = 1 ;
@@ -532,27 +528,27 @@ static int parse_choice(struct menu_stuff *menu_stuff,
532528 }
533529
534530 if (is_number ) {
535- bottom = atoi (( * ptr ) -> buf );
531+ bottom = atoi (string );
536532 top = bottom ;
537533 } else if (is_range ) {
538- bottom = atoi (( * ptr ) -> buf );
534+ bottom = atoi (string );
539535 /* a range can be specified like 5-7 or 5- */
540- if (!* (strchr (( * ptr ) -> buf , '-' ) + 1 ))
536+ if (!* (strchr (string , '-' ) + 1 ))
541537 top = menu_stuff -> nr ;
542538 else
543- top = atoi (strchr (( * ptr ) -> buf , '-' ) + 1 );
544- } else if (!strcmp (( * ptr ) -> buf , "*" )) {
539+ top = atoi (strchr (string , '-' ) + 1 );
540+ } else if (!strcmp (string , "*" )) {
545541 bottom = 1 ;
546542 top = menu_stuff -> nr ;
547543 } else {
548- bottom = find_unique (( * ptr ) -> buf , menu_stuff );
544+ bottom = find_unique (string , menu_stuff );
549545 top = bottom ;
550546 }
551547
552548 if (top <= 0 || bottom <= 0 || top > menu_stuff -> nr || bottom > top ||
553549 (is_single && bottom != top )) {
554550 clean_print_color (CLEAN_COLOR_ERROR );
555- printf (_ ("Huh (%s)?\n" ), ( * ptr ) -> buf );
551+ printf (_ ("Huh (%s)?\n" ), string );
556552 clean_print_color (CLEAN_COLOR_RESET );
557553 continue ;
558554 }
@@ -561,7 +557,7 @@ static int parse_choice(struct menu_stuff *menu_stuff,
561557 (* chosen )[i - 1 ] = choose ;
562558 }
563559
564- strbuf_list_free ( choice_list );
560+ string_list_clear ( & choice , 0 );
565561
566562 for (i = 0 ; i < menu_stuff -> nr ; i ++ )
567563 nr += (* chosen )[i ];
@@ -631,7 +627,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
631627
632628 nr = parse_choice (stuff ,
633629 opts -> flags & MENU_OPTS_SINGLETON ,
634- choice ,
630+ choice . buf ,
635631 & chosen );
636632
637633 if (opts -> flags & MENU_OPTS_SINGLETON ) {
@@ -679,12 +675,13 @@ static int filter_by_patterns_cmd(void)
679675{
680676 struct dir_struct dir = DIR_INIT ;
681677 struct strbuf confirm = STRBUF_INIT ;
682- struct strbuf * * ignore_list ;
683- struct string_list_item * item ;
684678 struct pattern_list * pl ;
685679 int changed = -1 , i ;
686680
687681 for (;;) {
682+ struct string_list ignore_list = STRING_LIST_INIT_NODUP ;
683+ struct string_list_item * item ;
684+
688685 if (!del_list .nr )
689686 break ;
690687
@@ -702,14 +699,15 @@ static int filter_by_patterns_cmd(void)
702699 break ;
703700
704701 pl = add_pattern_list (& dir , EXC_CMDL , "manual exclude" );
705- ignore_list = strbuf_split_max (& confirm , ' ' , 0 );
706702
707- for (i = 0 ; ignore_list [i ]; i ++ ) {
708- strbuf_trim (ignore_list [i ]);
709- if (!ignore_list [i ]-> len )
710- continue ;
703+ string_list_split_in_place_f (& ignore_list , confirm .buf , " " , -1 ,
704+ STRING_LIST_SPLIT_TRIM );
711705
712- add_pattern (ignore_list [i ]-> buf , "" , 0 , pl , - (i + 1 ));
706+ for (i = 0 ; i < ignore_list .nr ; i ++ ) {
707+ item = & ignore_list .items [i ];
708+ if (!* item -> string )
709+ continue ;
710+ add_pattern (item -> string , "" , 0 , pl , - (i + 1 ));
713711 }
714712
715713 changed = 0 ;
@@ -730,7 +728,7 @@ static int filter_by_patterns_cmd(void)
730728 clean_print_color (CLEAN_COLOR_RESET );
731729 }
732730
733- strbuf_list_free ( ignore_list );
731+ string_list_clear ( & ignore_list , 0 );
734732 dir_clear (& dir );
735733 }
736734
0 commit comments