Use const variables in eval as much as possible.

This commit is contained in:
Danila Fedorin 2017-07-20 22:09:42 -07:00
parent 6d520028b4
commit 600f169b5b
2 changed files with 9 additions and 9 deletions

View File

@ -25,7 +25,7 @@ struct eval_s {
/**
* The input being evaluated.
*/
char* string;
const char* string;
/**
* The current index in the input.
*/
@ -96,7 +96,7 @@ liblex_result eval_config_free(eval_config* config);
* @param pattern_id the id to associate with the pattern
* @return LIBLEX_SUCCESS if all goes well, or LIBLEX_MALLOC if there was an allocation failure.
*/
liblex_result eval_config_add(eval_config* config, char* pattern, int pattern_id);
liblex_result eval_config_add(eval_config* config, const char* pattern, int pattern_id);
/**
* Evaluates / finds a single word.
* @param string the string to evaluate.
@ -105,7 +105,7 @@ liblex_result eval_config_add(eval_config* config, char* pattern, int pattern_id
* @param match pointer to where to store the newly created match.
* @return LIBLEX_SUCCESS if all goes well, or LIBLEX_MALLOC if there was an allocation failure.
*/
liblex_result eval_word(char* string, size_t index, eval_config* config, match* match);
liblex_result eval_word(const char* string, size_t index, eval_config* config, match* match);
/**
* Evaluates input starting at the index until it reaches the null terminator,
* adding the best matches to the linked list.
@ -115,7 +115,7 @@ liblex_result eval_word(char* string, size_t index, eval_config* config, match*
* @param matches the linked list to populate with matches
* @return LIBLEX_SUCCESS if all goes well, or LIBLEX_MALLOC if there was an allocation failure.
*/
liblex_result eval_all(char* string, size_t index, eval_config* config, ll* matches);
liblex_result eval_all(const char* string, size_t index, eval_config* config, ll* matches);
/**
* Function intended to be passed to "foreach" calls in libds.
* Since eval_all creates a lot of matches and puts them all in a linked list,

View File

@ -14,7 +14,7 @@ static liblex_result foreach_errors[2] = {
void eval_config_init(eval_config* config){
ll_init(&config->states);
}
liblex_result eval_config_add(eval_config* config, char* ptrn, int pattern_id){
liblex_result eval_config_add(eval_config* config, const char* ptrn, int pattern_id){
liblex_result result;
pattern* new_pattern = malloc(sizeof(*new_pattern));
if(new_pattern){
@ -154,7 +154,7 @@ int _eval_foreach_find_match(void *data, va_list args){
return 0;
}
liblex_result eval_word(char* string, size_t index, eval_config* config, match* mtch){
liblex_result eval_word(const char* string, size_t index, eval_config* config, match* mtch){
liblex_result result = LIBLEX_SUCCESS;
eval evl;
evl.index = evl.begin = index;
@ -177,8 +177,8 @@ liblex_result eval_word(char* string, size_t index, eval_config* config, match*
int largest_id = -1;
ll_foreach(&evl.matches, NULL, compare_always, _eval_foreach_find_match, &largest_id, mtch);
} else {
mtch->from = -1;
mtch->to = -1;
mtch->from = 0;
mtch->to = 0;
mtch->pattern = -1;
}
@ -189,7 +189,7 @@ liblex_result eval_word(char* string, size_t index, eval_config* config, match*
return result;
}
liblex_result eval_all(char* string, size_t index, eval_config* config, ll* matches){
liblex_result eval_all(const char* string, size_t index, eval_config* config, ll* matches){
liblex_result result = LIBLEX_SUCCESS;
match* new_match = NULL;
int done = 0;