3636
3737gen_slice (i16 , int16_t );
3838gen_simple_slice (i32 , int32_t );
39- gen_slice (str , char );
39+ gen_slice (str , const char );
4040#undef gen_slice
4141#undef gen_simple_slice
4242
@@ -64,7 +64,7 @@ typedef enum {
6464} char_types ;
6565
6666typedef struct {
67- char * data ;
67+ const char * data ;
6868 size_t size ;
6969} fzf_string_t ;
7070
@@ -124,16 +124,18 @@ static char *trim_left(char *str, size_t *len, char trim) {
124124 return str ;
125125}
126126
127- static bool has_prefix (char * str , char * prefix , size_t prefix_len ) {
127+ static bool has_prefix (const char * str , const char * prefix , size_t prefix_len ) {
128128 return strncmp (prefix , str , prefix_len ) == 0 ;
129129}
130130
131- static bool has_suffix (char * str , size_t len , char * suffix , size_t suffix_len ) {
131+ static bool has_suffix (const char * str , size_t len , const char * suffix ,
132+ size_t suffix_len ) {
132133 return len >= suffix_len &&
133134 strncmp (slice_str (str , len - suffix_len , len ).data , suffix ,
134135 suffix_len ) == 0 ;
135136}
136137
138+ // TODO(conni2461): REFACTOR
137139static char * str_replace (char * orig , char * rep , char * with ) {
138140 char * result , * ins , * tmp ;
139141 size_t len_rep , len_with , len_front , count ;
@@ -173,6 +175,7 @@ static char *str_replace(char *orig, char *rep, char *with) {
173175 return result ;
174176}
175177
178+ // TODO(conni2461): REFACTOR
176179static char * str_tolower (char * str , size_t size ) {
177180 char * lower_str = (char * )malloc ((size + 1 ) * sizeof (char ));
178181 for (size_t i = 0 ; i < size ; i ++ ) {
@@ -339,7 +342,7 @@ static int32_t try_skip(fzf_string_t *input, bool case_sensitive, byte b,
339342 return from + idx ;
340343}
341344
342- static bool is_ascii (char * runes , size_t size ) {
345+ static bool is_ascii (const char * runes , size_t size ) {
343346 // TODO(conni2461): future use
344347 /* for (size_t i = 0; i < size; i++) { */
345348 /* if (runes[i] >= 256) { */
@@ -349,7 +352,7 @@ static bool is_ascii(char *runes, size_t size) {
349352 return true;
350353}
351354
352- static int32_t ascii_fuzzy_index (fzf_string_t * input , char * pattern ,
355+ static int32_t ascii_fuzzy_index (fzf_string_t * input , const char * pattern ,
353356 size_t size , bool case_sensitive ) {
354357 if (!is_ascii (pattern , size )) {
355358 return -1 ;
@@ -498,8 +501,8 @@ static fzf_result_t __fuzzy_match_v1(bool case_sensitive, bool normalize,
498501}
499502
500503fzf_result_t fzf_fuzzy_match_v1 (bool case_sensitive , bool normalize ,
501- char * input , char * pattern , bool with_pos ,
502- fzf_slab_t * slab ) {
504+ const char * input , const char * pattern ,
505+ bool with_pos , fzf_slab_t * slab ) {
503506 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
504507 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
505508 return __fuzzy_match_v1 (case_sensitive , normalize , & input_wrap , & pattern_wrap ,
@@ -753,8 +756,8 @@ static fzf_result_t __fuzzy_match_v2(bool case_sensitive, bool normalize,
753756}
754757
755758fzf_result_t fzf_fuzzy_match_v2 (bool case_sensitive , bool normalize ,
756- char * input , char * pattern , bool with_pos ,
757- fzf_slab_t * slab ) {
759+ const char * input , const char * pattern ,
760+ bool with_pos , fzf_slab_t * slab ) {
758761 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
759762 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
760763 return __fuzzy_match_v2 (case_sensitive , normalize , & input_wrap , & pattern_wrap ,
@@ -829,8 +832,8 @@ static fzf_result_t __exact_match_naive(bool case_sensitive, bool normalize,
829832}
830833
831834fzf_result_t fzf_exact_match_naive (bool case_sensitive , bool normalize ,
832- char * input , char * pattern , bool with_pos ,
833- fzf_slab_t * slab ) {
835+ const char * input , const char * pattern ,
836+ bool with_pos , fzf_slab_t * slab ) {
834837 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
835838 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
836839 return __exact_match_naive (case_sensitive , normalize , & input_wrap ,
@@ -872,8 +875,9 @@ static fzf_result_t __prefix_match(bool case_sensitive, bool normalize,
872875 return (fzf_result_t ){(int32_t )start , (int32_t )end , score , NULL };
873876}
874877
875- fzf_result_t fzf_prefix_match (bool case_sensitive , bool normalize , char * input ,
876- char * pattern , bool with_pos , fzf_slab_t * slab ) {
878+ fzf_result_t fzf_prefix_match (bool case_sensitive , bool normalize ,
879+ const char * input , const char * pattern ,
880+ bool with_pos , fzf_slab_t * slab ) {
877881 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
878882 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
879883 return __prefix_match (case_sensitive , normalize , & input_wrap , & pattern_wrap ,
@@ -918,8 +922,9 @@ static fzf_result_t __suffix_match(bool case_sensitive, bool normalize,
918922 return (fzf_result_t ){(int32_t )start , (int32_t )end , score , NULL };
919923}
920924
921- fzf_result_t fzf_suffix_match (bool case_sensitive , bool normalize , char * input ,
922- char * pattern , bool with_pos , fzf_slab_t * slab ) {
925+ fzf_result_t fzf_suffix_match (bool case_sensitive , bool normalize ,
926+ const char * input , const char * pattern ,
927+ bool with_pos , fzf_slab_t * slab ) {
923928 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
924929 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
925930 return __suffix_match (case_sensitive , normalize , & input_wrap , & pattern_wrap ,
@@ -944,10 +949,9 @@ static fzf_result_t __equal_match(bool case_sensitive, bool normalize,
944949 bool match = true;
945950 if (normalize ) {
946951 // TODO(conni2461): to rune
947- char * runes = text -> data ;
948952 for (size_t idx = 0 ; idx < len_pattern ; idx ++ ) {
949953 char pchar = pattern -> data [idx ];
950- char c = runes [trimmed_len + idx ];
954+ char c = text -> data [trimmed_len + idx ];
951955 if (!case_sensitive ) {
952956 c = (char )tolower (c );
953957 }
@@ -958,11 +962,9 @@ static fzf_result_t __equal_match(bool case_sensitive, bool normalize,
958962 }
959963 } else {
960964 // TODO(conni2461): to rune
961- char * runes = text -> data ;
962-
963965 for (size_t idx = 0 ; idx < len_pattern ; idx ++ ) {
964966 char pchar = pattern -> data [idx ];
965- char c = runes [trimmed_len + idx ];
967+ char c = text -> data [trimmed_len + idx ];
966968 if (!case_sensitive ) {
967969 c = (char )tolower (c );
968970 }
@@ -982,8 +984,9 @@ static fzf_result_t __equal_match(bool case_sensitive, bool normalize,
982984 return (fzf_result_t ){-1 , -1 , 0 , NULL };
983985}
984986
985- fzf_result_t fzf_equal_match (bool case_sensitive , bool normalize , char * input ,
986- char * pattern , bool with_pos , fzf_slab_t * slab ) {
987+ fzf_result_t fzf_equal_match (bool case_sensitive , bool normalize ,
988+ const char * input , const char * pattern ,
989+ bool with_pos , fzf_slab_t * slab ) {
987990 fzf_string_t input_wrap = {.data = input , .size = strlen (input )};
988991 fzf_string_t pattern_wrap = {.data = pattern , .size = strlen (pattern )};
989992 return __equal_match (case_sensitive , normalize , & input_wrap , & pattern_wrap ,
@@ -1039,6 +1042,7 @@ static fzf_result_t fzf_call_alg(fzf_term_t *term, bool normalize,
10391042 (fzf_string_t * )term -> text , with_pos , slab );
10401043}
10411044
1045+ // TODO(conni2461): REFACTOR
10421046/* assumption (maybe i change that later)
10431047 * - always v2 alg
10441048 * - bool extended always true (thats the whole point of this isn't it)
@@ -1182,7 +1186,8 @@ void fzf_free_pattern(fzf_pattern_t *pattern) {
11821186 free (pattern );
11831187}
11841188
1185- int32_t fzf_get_score (char * text , fzf_pattern_t * pattern , fzf_slab_t * slab ) {
1189+ int32_t fzf_get_score (const char * text , fzf_pattern_t * pattern ,
1190+ fzf_slab_t * slab ) {
11861191 fzf_string_t input = {.data = text , .size = strlen (text )};
11871192
11881193 if (pattern -> only_inv ) {
@@ -1225,7 +1230,7 @@ int32_t fzf_get_score(char *text, fzf_pattern_t *pattern, fzf_slab_t *slab) {
12251230 return total_score ;
12261231}
12271232
1228- fzf_position_t * fzf_get_positions (char * text , fzf_pattern_t * pattern ,
1233+ fzf_position_t * fzf_get_positions (const char * text , fzf_pattern_t * pattern ,
12291234 fzf_slab_t * slab ) {
12301235 fzf_string_t input = {.data = text , .size = strlen (text )};
12311236
0 commit comments