source: trunk/dll/stristr.c@ 1570

Last change on this file since 1570 was 1348, checked in by Gregg Young, 17 years ago

More code cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
RevLine 
[793]1
2/***********************************************************************
3
4 $Id: stristr.c 1348 2008-12-20 04:25:22Z 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// static CHAR *strnistr(register CHAR * t, CHAR * s, LONG len);
23
24CHAR *stristr(const register CHAR * t, const CHAR * s)
25// CHAR *stristr(register CHAR * t, CHAR * s)
[551]26{
[2]27 /* case-insensitive strstr() */
28
[1183]29 const register CHAR *t1, *s1;
[2]30
31 while (*t) {
32 t1 = t;
33 s1 = s;
34 while (*s1) {
[551]35 if (toupper(*s1) != toupper(*t))
36 break;
[2]37 else {
[551]38 s1++;
39 t++;
[2]40 }
41 }
42 if (!*s1)
[1183]43 return (CHAR *)t1;
[2]44 t = t1 + 1;
45 }
46 return NULL;
47}
48
[1193]49#if 0 // JBS 11 Sep 08
[551]50CHAR *strnistr(register CHAR * t, CHAR * s, LONG len)
51{
[2]52 /* case-insensitive strnstr() */
53
54 register CHAR *s1;
[551]55 register LONG len2;
[2]56
57 len2 = 0;
58 while (len > len2) {
59 s1 = s;
60 while (len2 < len) {
[551]61 if (toupper(*s1) != toupper(t[len2]))
62 break;
[2]63 else {
[551]64 len2++;
65 s1++;
[2]66 }
67 }
68 if (!*s1)
69 return t + (len2 - strlen(s));
70 len2++;
71 }
72 return NULL;
73}
[1183]74#endif
[2]75
[551]76CHAR *strnstr(register CHAR * t, CHAR * s, LONG len)
77{
[2]78 /* strnstr() */
79
80 register CHAR *s1;
[551]81 register LONG len2;
[2]82
83 len2 = 0;
84 while (len > len2) {
85 s1 = s;
86 while (len2 < len) {
87 if (*s1 != t[len2])
[551]88 break;
[2]89 else {
[551]90 len2++;
91 s1++;
[2]92 }
93 }
94 if (!*s1)
95 return t + (len2 - strlen(s));
96 len2++;
97 }
98 return NULL;
99}
100
[551]101CHAR *findstring(CHAR * findthis, ULONG lenthis, CHAR * findin,
102 ULONG lenin, BOOL sensitive)
103{
104 register CHAR *this, *in;
105 register ULONG lenthis2, lenin2;
[2]106
[551]107 if (!findthis || !findin || !lenthis || !lenin)
[2]108 return NULL;
109 do {
110 this = findthis;
111 lenthis2 = lenthis;
112 in = findin;
113 lenin2 = lenin;
[551]114 while (lenthis2 && lenin2) {
115 if (!sensitive) {
116 if (toupper(*this) != toupper(*in))
117 break;
118 else {
119 this++;
120 in++;
121 lenthis2--;
122 lenin2--;
123 }
[2]124 }
125 else {
[551]126 if (*this != *in)
127 break;
128 else {
129 this++;
130 in++;
131 lenthis2--;
132 lenin2--;
133 }
[2]134 }
135 }
[551]136 if (lenthis2) {
[2]137 lenin--;
138 findin++;
139 }
[551]140 } while (lenin && lenthis2);
[2]141 return (lenthis2) ? NULL : in - lenthis;
142}
[793]143
144#pragma alloc_text(MISC8,stristr,strnstr,strnistr,findstring)
Note: See TracBrowser for help on using the repository browser.