diff options
author | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-12-03 03:01:24 +0000 |
commit | b8d4bb76703bcb15578e2b23c5d256532180b894 (patch) | |
tree | bedd1df7a00521a2bd986b3c0289d6556a59e39b /support/texlab/crates/bibutils_sys/src/strsearch.c | |
parent | 02e4625a78a5029e8b5dc2a4ec70193b232f497e (diff) |
CTAN sync 201912030301
Diffstat (limited to 'support/texlab/crates/bibutils_sys/src/strsearch.c')
-rw-r--r-- | support/texlab/crates/bibutils_sys/src/strsearch.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/support/texlab/crates/bibutils_sys/src/strsearch.c b/support/texlab/crates/bibutils_sys/src/strsearch.c new file mode 100644 index 0000000000..86a427610f --- /dev/null +++ b/support/texlab/crates/bibutils_sys/src/strsearch.c @@ -0,0 +1,41 @@ +/* strsearch.c + * + * Copyright (c) Chris Putnam 1995-2019 + * + * Source code released under the GPL version 2 + * + * strsearch() locates a case-independent substring + * e.g. a case-independent version of strstr() + * + * returns pointer to first occurrence of substring needle in + * the string haystack when found, NULL if not found + * + * '\0' characters terminating strings are not compared + * + * strsearch returns haystack when needle is empty as per strstr() + * conventions + * + */ +#include <stdio.h> +#include <ctype.h> +#include "strsearch.h" + +char *strsearch (const char *haystack, const char *needle) +{ + char *returnptr=NULL; + unsigned long pos=0; + + if ( !(*needle) ) returnptr = (char *) haystack; + + while (*(haystack+pos) && returnptr==NULL) { + if ( toupper((unsigned char)*(haystack+pos)) == toupper((unsigned char)*(needle+pos)) ) + pos++; + else { + pos = 0; + haystack++; + } + if ( ! (*(needle+pos)) ) returnptr = (char *) haystack; + } + return returnptr; +} + |