Simplify calling of rsindex() and strsearch()

Remove the 'how' parameter to rsindex(), making it reverse-search for only the first matching character,
as sindex() already does.  There are only two callers, and one already passed a hardcoded value of 1.

Also change rsindex() so that it starts searching at the character BEFORE the passed in position.  This
makes it easier to repeatedly call rsindex() in a loop to search for the Nth matching character, and
also fixes a technical instance of undefined behaviour where a pointer is decremented to point before
the start of the string.

Remove the 'mark' parameter to strsearch().  Instead, always forward-search from the beginning of the
string and reverse-search from the end of the string, as this is what the two callers want anyway.

Bump the module ABI version because these functions are exported to modules.
This commit is contained in:
Kevin Easton
2017-11-23 17:22:38 +11:00
parent de303ba554
commit ba1b9742ec
7 changed files with 36 additions and 49 deletions

View File

@@ -30,7 +30,7 @@ char * BX_upper (char *);
char * BX_lower (char *);
char *inv_strpbrk(const char *s, const char *reject);
char * BX_sindex (const char *, const char *);
char * BX_rsindex (const char *, const char *, const char *, int);
char * BX_rsindex (const char *, const char *, const char *);
char * BX_path_search (char *, char *);
char * BX_double_quote (const char *, const char *, char *);
@@ -133,7 +133,7 @@ char * base64_encode (const void *data, size_t size);
/* From words.c */
#define SOS -32767
#define EOS 32767
char *BX_strsearch(const char *, const char *, const char *, int);
char *BX_strsearch(const char *, const char *, int);
char *BX_move_to_word(const char *, int);
char *BX_move_word_rel(const char *, char **, int);
char *BX_extract(char *, int, int);

View File

@@ -10,7 +10,7 @@
* if we change the table below, we change this module number to the
* current date (YYYYMMDDxx where xx is a serial number).
*/
#define MODULE_VERSION 2017111401UL
#define MODULE_VERSION 2017112301UL
#include "struct.h"

View File

@@ -146,7 +146,7 @@ extern Function_ptr *global;
#define expand_twiddle (*(char * (*)(char *))global[EXPAND_TWIDDLE])
#define check_nickname (*(char * (*)(char *))global[CHECK_NICKNAME])
#define sindex (*(char * (*)(const char *, const char *))global[SINDEX])
#define rsindex (*(char * (*)(const char *, const char *, const char *, int))global[RSINDEX])
#define rsindex (*(char * (*)(const char *, const char *, const char *))global[RSINDEX])
#define is_number (*(int (*)(const char *))global[ISNUMBER])
#define rfgets (*(char * (*)(char *, int , FILE *))global[RFGETS])
#define path_search (*(char * (*)(char *, char *))global[PATH_SEARCH])
@@ -199,7 +199,7 @@ extern Function_ptr *global;
/* words.c reg.c */
#define strsearch (*(char *(*)(const char *, const char *, const char *, int ))global[STRSEARCH])
#define strsearch (*(char *(*)(const char *, const char *, int))global[STRSEARCH])
#define move_to_word (*(char *(*)(const char *, int))global[MOVE_TO_WORD])
#define move_word_rel (*(char *(*)(const char *, char **, int ))global[MOVE_WORD_REL])
#define extract (*(char *(*)(char *, int , int ))global[EXTRACT])