mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 20:57:56 +00:00
New "str.h" functions: strn_str_cmp(), strn_str_casecmp()
This commit is contained in:
parent
fcb6600cd6
commit
5013424ab1
18
str.c
18
str.c
@ -131,6 +131,24 @@ int strncase_startswith(const char *str, size_t len, const char *substring, cons
|
||||
return 1;
|
||||
}
|
||||
|
||||
int strn_str_cmp(const char *str1, size_t len1, const char *str2)
|
||||
{
|
||||
int r = strncmp(str1, str2, len1);
|
||||
if (r)
|
||||
return r;
|
||||
size_t len2 = strlen(str2);
|
||||
return len1 < len2 ? -1 : len1 > len2 ? 1 : 0;
|
||||
}
|
||||
|
||||
int strn_str_casecmp(const char *str1, size_t len1, const char *str2)
|
||||
{
|
||||
int r = strncasecmp(str1, str2, len1);
|
||||
if (r)
|
||||
return r;
|
||||
size_t len2 = strlen(str2);
|
||||
return len1 < len2 ? -1 : len1 > len2 ? 1 : 0;
|
||||
}
|
||||
|
||||
int parse_argv(char *cmdline, char delim, char **argv, int max_argv)
|
||||
{
|
||||
int argc=0;
|
||||
|
16
str.h
16
str.h
@ -119,6 +119,22 @@ int strcase_startswith(const char *str, const char *substring, const char **afte
|
||||
*/
|
||||
int strncase_startswith(const char *str, size_t len, const char *substring, const char **afterp);
|
||||
|
||||
/* Compare the given string 'str1' of a given length 'len1' with a given nul-terminated string
|
||||
* 'str2'. Equivalent to { str1[len1] = '\0'; return strcmp(str1, str2); } except without modifying
|
||||
* str1[].
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int strn_str_cmp(const char *str1, size_t len1, const char *str2);
|
||||
|
||||
/* Compare case-insenstivively the given string 'str1' of a given length 'len1' with a given
|
||||
* nul-terminated string 'str2'. Equivalent to { str1[len1] = '\0'; return strcasecmp(str1, str2);
|
||||
* } except without modifying str1[].
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
int strn_str_casecmp(const char *str1, size_t len1, const char *str2);
|
||||
|
||||
/* like strstr(3), but doesn't depend on null termination.
|
||||
*
|
||||
* @author Paul Gardner-Stephen <paul@servalproject.org>
|
||||
|
Loading…
Reference in New Issue
Block a user