os/ossrv/genericopenlibs/cstdlib/LCHAR/STRSTR.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * FUNCTION
    16 * <<strstr>>---find string segment
    17 * INDEX
    18 * strstr
    19 * ANSI_SYNOPSIS
    20 * #include <string.h>
    21 * char *strstr(const char *<[s1]>, const char *<[s2]>);
    22 * TRAD_SYNOPSIS
    23 * #include <string.h>
    24 * char *strstr(<[s1]>, <[s2]>)
    25 * char *<[s1]>;
    26 * char *<[s2]>;
    27 * Locates the first occurence in the string pointed to by <[s1]> of
    28 * the sequence of characters in the string pointed to by <[s2]>
    29 * (excluding the terminating null  character).
    30 * RETURNS
    31 * Returns a pointer to the located string segment, or a null
    32 * pointer if the string <[s2]> is not found. If <[s2]> points to
    33 * a string with zero length, the <[s1]> is returned.
    34 * PORTABILITY
    35 * <<strstr>> is ANSI C.
    36 * <<strstr>> requires no supporting OS subroutines.
    37 * QUICKREF
    38 * strstr ansi pure
    39 * 
    40 *
    41 */
    42 
    43 
    44 
    45 #include <string.h>
    46 
    47 /**
    48 Find substring.
    49 Scans string1 for the first occurrence of string2.
    50 The search does not include terminating null-characters.
    51 @return A pointer to the first occurrence of lookfor in searchee.
    52 If lookfor is not found in searchee the function returns NULL.
    53 @param searchee Null-terminated string to search. 
    54 @param lookfor Null-terminated string containing the substring to search for.
    55 */
    56 EXPORT_C char *
    57 strstr (const char *searchee, const char *lookfor)
    58 {
    59   if (*searchee == 0)
    60     {
    61       if (*lookfor)
    62 	return (char *) NULL;
    63       return (char *) searchee;
    64     }
    65 
    66   while (*searchee)
    67     {
    68       size_t i;
    69       i = 0;
    70 
    71       for (;;)
    72 	{
    73 	  if (lookfor[i] == 0)
    74 	    {
    75 	      return (char *) searchee;
    76 	    }
    77 
    78 	  if (lookfor[i] != searchee[i])
    79 	    {
    80 	      break;
    81 	    }
    82 	  i++;
    83 	}
    84       searchee++;
    85     }
    86 
    87   return (char *) NULL;
    88 }