Fixed buffer resizing, made string utilities more modular, and added several new utilities, some which do not require a null termination, potentially avoiding the need to copy a string. Also some substring utilities using the Rabin-Karp algorithm were added.

This commit is contained in:
Jim Monte 2019-12-09 00:27:03 -05:00 committed by Holger Vogt
parent 814d1f07d6
commit bb10b84045
2 changed files with 2 additions and 4 deletions

View File

@ -98,8 +98,6 @@ inline char *copy_substring(const char *str, const char *end)
/* Like scannum but *p_str is advanced past the number */
/* Try to identify an unsigned integer that begins a string. Stop when a
* non- numeric character is reached. There is no way to distinguish
* between a value of 0 and a string that does not contain a numeric
@ -114,7 +112,7 @@ inline int scannum(const char *str)
/* Determine whether sub is a substring of str. */
inline int substring(const char *sub, const char *str)
{
return strstr(sub, str) != (char *) NULL;
return strstr(str, sub) != (char *) NULL;
} /* end of function substring */
#ifdef CIDER

View File

@ -236,7 +236,7 @@ int get_int_n(const char *str, size_t n, int *p_value)
/* Test for overflow.
* If negative, can be 1 greater (-2**n vs 2**n -1) */
if (value - f_neg > INT_MAX) {
if (value - f_neg > (unsigned int) INT_MAX) {
return -2;
}