This is cUtils.c in view mode; [Download] [Up]
/* * cUtils.c * * Purpose: * These c routines implement a text search. * * You may freely copy, distribute, and reuse the code in this example. * NeXT disclaims any warranty of any kind, expressed or implied, as to its * fitness for any particular use. * * Written by: Mary McNabb * Created: Apr 91 * */ #import <strings.h> #import <libc.h> #import <zone.h> /* * Returns true if 'text' exists within 'string'. */ char *textInString(text, string, ignoreCase) char *text, *string; int ignoreCase; { int textLength, i; textLength = strlen(text); i = strlen(string) - textLength + 1; if (i <= 0) { return 0; } if (ignoreCase) { while (i--) { if (!strncasecmp(string++, text, textLength)) { return (string-1); } } } else { while (i--) { if (!strncmp(string++, text, textLength)) { return (string-1); } } } return 0; } /* * Returns true if 'text' exists within 'string' (searches in * reverse direction). */ char *textInStringReverse(text, string, stringStart, ignoreCase) char *text, *string, *stringStart; int ignoreCase; { int textLength; textLength = strlen(text); string -= textLength; if ((strlen(stringStart) - strlen(string)) < strlen(text)) { return 0; } if (ignoreCase) { while (string >= stringStart) { if (!strncasecmp(string--, text, textLength)) { return (string + 1); } } } else { while (string >= stringStart) { if (!strncmp(string--, text, textLength)) { return (string + 1); } } } return 0; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.