summaryrefslogtreecommitdiffstats
path: root/compat/strstr.c
blob: c83c2093c8435762f68f338c9936f4002056c253 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* 
 * strstr.c --
 *
 *	Source code for the "strstr" library routine.
 *
 * Copyright (c) 1988-1993 The Regents of the University of California.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: strstr.c,v 1.3 2002/01/26 01:10:08 dgp Exp $
 */

/*
 *----------------------------------------------------------------------
 *
 * strstr --
 *
 *	Locate the first instance of a substring in a string.
 *
 * Results:
 *	If string contains substring, the return value is the
 *	location of the first matching instance of substring
 *	in string.  If string doesn't contain substring, the
 *	return value is 0.  Matching is done on an exact
 *	character-for-character basis with no wildcards or special
 *	characters.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

char *
strstr(string, substring)
    register char *string;	/* String to search. */
    char *substring;		/* Substring to try to find in string. */
{
    register char *a, *b;

    /* First scan quickly through the two strings looking for a
     * single-character match.  When it's found, then compare the
     * rest of the substring.
     */

    b = substring;
    if (*b == 0) {
	return string;
    }
    for ( ; *string != 0; string += 1) {
	if (*string != *b) {
	    continue;
	}
	a = string;
	while (1) {
	    if (*b == 0) {
		return string;
	    }
	    if (*a++ != *b++) {
		break;
	    }
	}
	b = substring;
    }
    return NULL;
}
tcl.git/stats/tests/chanio.test?h=bug_3605401'>statsplain -rw-r--r--clock.test1907523logstatsplain -rw-r--r--cmdAH.test52111logstatsplain -rw-r--r--cmdIL.test25041logstatsplain -rw-r--r--cmdInfo.test3621logstatsplain -rw-r--r--cmdMZ.test12639logstatsplain -rw-r--r--compExpr-old.test37001logstatsplain -rw-r--r--compExpr.test17215logstatsplain -rw-r--r--compile.test25151logstatsplain -rw-r--r--concat.test1591logstatsplain -rw-r--r--config.test2244logstatsplain -rw-r--r--coroutine.test13394logstatsplain -rw-r--r--dcall.test1331logstatsplain -rw-r--r--dict.test42209logstatsplain -rw-r--r--dstring.test10130logstatsplain -rw-r--r--encoding.test18722logstatsplain -rw-r--r--env.test8503logstatsplain -rw-r--r--error.test32933logstatsplain -rw-r--r--eval.test2293logstatsplain -rw-r--r--event.test27800logstatsplain -rw-r--r--exec.test27248logstatsplain -rw-r--r--execute.test32685logstatsplain -rw-r--r--expr-old.test47229logstatsplain -rw-r--r--expr.test341360logstatsplain -rw-r--r--fCmd.test87821logstatsplain -rw-r--r--fileName.test56046logstatsplain -rw-r--r--fileSystem.test35837logstatsplain -rw-r--r--for-old.test1941logstatsplain -rw-r--r--for.test25280logstatsplain -rw-r--r--foreach.test7050logstatsplain -rw-r--r--format.test21017logstatsplain -rw-r--r--get.test4431logstatsplain -rw-r--r--history.test7999logstatsplain -rw-r--r--http.test19412logstatsplain -rw-r--r--http11.test23598logstatsplain -rw-r--r--httpd5685logstatsplain -rw-r--r--httpd11.tcl8214logstatsplain -rw-r--r--httpold.test7848logstatsplain -rw-r--r--if-old.test4769logstatsplain -rw-r--r--if.test30414logstatsplain -rw-r--r--incr-old.test2787logstatsplain -rw-r--r--incr.test17367logstatsplain -rw-r--r--indexObj.test5409logstatsplain -rw-r--r--info.test62719logstatsplain -rw-r--r--init.test6380logstatsplain -rw-r--r--interp.test102339logstatsplain -rw-r--r--io.test233167logstatsplain