[793] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: stristr.c 1673 2012-12-30 18:51:01Z gyoung $
|
---|
| 5 |
|
---|
| 6 | Copyright (c) 1993-98 M. Kimes
|
---|
[1348] | 7 | Copyright (c) 2003, 2008 Steven H.Levine
|
---|
[793] | 8 |
|
---|
| 9 | Case insensitive strings
|
---|
| 10 |
|
---|
| 11 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
| 12 |
|
---|
| 13 | ***********************************************************************/
|
---|
| 14 |
|
---|
[2] | 15 | #include <string.h>
|
---|
| 16 | #include <ctype.h>
|
---|
| 17 |
|
---|
[907] | 18 | #include <os2.h>
|
---|
| 19 |
|
---|
[1183] | 20 | #include "stristr.h"
|
---|
| 21 |
|
---|
| 22 | CHAR *stristr(const register CHAR * t, const CHAR * s)
|
---|
[551] | 23 | {
|
---|
[1673] | 24 | // case-insensitive strstr()
|
---|
[2] | 25 |
|
---|
[1183] | 26 | const register CHAR *t1, *s1;
|
---|
[2] | 27 |
|
---|
| 28 | while (*t) {
|
---|
| 29 | t1 = t;
|
---|
| 30 | s1 = s;
|
---|
| 31 | while (*s1) {
|
---|
[551] | 32 | if (toupper(*s1) != toupper(*t))
|
---|
| 33 | break;
|
---|
[2] | 34 | else {
|
---|
[551] | 35 | s1++;
|
---|
| 36 | t++;
|
---|
[2] | 37 | }
|
---|
| 38 | }
|
---|
| 39 | if (!*s1)
|
---|
[1183] | 40 | return (CHAR *)t1;
|
---|
[2] | 41 | t = t1 + 1;
|
---|
| 42 | }
|
---|
| 43 | return NULL;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[1193] | 46 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 47 | CHAR *strnistr(register CHAR * t, CHAR * s, LONG len)
|
---|
| 48 | {
|
---|
[1673] | 49 | // case-insensitive strnstr()
|
---|
[2] | 50 |
|
---|
| 51 | register CHAR *s1;
|
---|
[551] | 52 | register LONG len2;
|
---|
[2] | 53 |
|
---|
| 54 | len2 = 0;
|
---|
| 55 | while (len > len2) {
|
---|
| 56 | s1 = s;
|
---|
| 57 | while (len2 < len) {
|
---|
[551] | 58 | if (toupper(*s1) != toupper(t[len2]))
|
---|
| 59 | break;
|
---|
[2] | 60 | else {
|
---|
[551] | 61 | len2++;
|
---|
| 62 | s1++;
|
---|
[2] | 63 | }
|
---|
| 64 | }
|
---|
| 65 | if (!*s1)
|
---|
| 66 | return t + (len2 - strlen(s));
|
---|
| 67 | len2++;
|
---|
| 68 | }
|
---|
| 69 | return NULL;
|
---|
| 70 | }
|
---|
[1183] | 71 | #endif
|
---|
[2] | 72 |
|
---|
[551] | 73 | CHAR *strnstr(register CHAR * t, CHAR * s, LONG len)
|
---|
| 74 | {
|
---|
[2] | 75 | register CHAR *s1;
|
---|
[551] | 76 | register LONG len2;
|
---|
[2] | 77 |
|
---|
| 78 | len2 = 0;
|
---|
| 79 | while (len > len2) {
|
---|
| 80 | s1 = s;
|
---|
| 81 | while (len2 < len) {
|
---|
| 82 | if (*s1 != t[len2])
|
---|
[551] | 83 | break;
|
---|
[2] | 84 | else {
|
---|
[551] | 85 | len2++;
|
---|
| 86 | s1++;
|
---|
[2] | 87 | }
|
---|
| 88 | }
|
---|
| 89 | if (!*s1)
|
---|
| 90 | return t + (len2 - strlen(s));
|
---|
| 91 | len2++;
|
---|
| 92 | }
|
---|
| 93 | return NULL;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[551] | 96 | CHAR *findstring(CHAR * findthis, ULONG lenthis, CHAR * findin,
|
---|
| 97 | ULONG lenin, BOOL sensitive)
|
---|
| 98 | {
|
---|
| 99 | register CHAR *this, *in;
|
---|
| 100 | register ULONG lenthis2, lenin2;
|
---|
[2] | 101 |
|
---|
[551] | 102 | if (!findthis || !findin || !lenthis || !lenin)
|
---|
[2] | 103 | return NULL;
|
---|
| 104 | do {
|
---|
| 105 | this = findthis;
|
---|
| 106 | lenthis2 = lenthis;
|
---|
| 107 | in = findin;
|
---|
| 108 | lenin2 = lenin;
|
---|
[551] | 109 | while (lenthis2 && lenin2) {
|
---|
| 110 | if (!sensitive) {
|
---|
| 111 | if (toupper(*this) != toupper(*in))
|
---|
| 112 | break;
|
---|
| 113 | else {
|
---|
| 114 | this++;
|
---|
| 115 | in++;
|
---|
| 116 | lenthis2--;
|
---|
| 117 | lenin2--;
|
---|
| 118 | }
|
---|
[2] | 119 | }
|
---|
| 120 | else {
|
---|
[551] | 121 | if (*this != *in)
|
---|
| 122 | break;
|
---|
| 123 | else {
|
---|
| 124 | this++;
|
---|
| 125 | in++;
|
---|
| 126 | lenthis2--;
|
---|
| 127 | lenin2--;
|
---|
| 128 | }
|
---|
[2] | 129 | }
|
---|
| 130 | }
|
---|
[551] | 131 | if (lenthis2) {
|
---|
[2] | 132 | lenin--;
|
---|
| 133 | findin++;
|
---|
| 134 | }
|
---|
[551] | 135 | } while (lenin && lenthis2);
|
---|
[2] | 136 | return (lenthis2) ? NULL : in - lenthis;
|
---|
| 137 | }
|
---|
[793] | 138 |
|
---|
| 139 | #pragma alloc_text(MISC8,stristr,strnstr,strnistr,findstring)
|
---|