1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRSTR.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* FUNCTION
1.19 +* <<strstr>>---find string segment
1.20 +* INDEX
1.21 +* strstr
1.22 +* ANSI_SYNOPSIS
1.23 +* #include <string.h>
1.24 +* char *strstr(const char *<[s1]>, const char *<[s2]>);
1.25 +* TRAD_SYNOPSIS
1.26 +* #include <string.h>
1.27 +* char *strstr(<[s1]>, <[s2]>)
1.28 +* char *<[s1]>;
1.29 +* char *<[s2]>;
1.30 +* Locates the first occurence in the string pointed to by <[s1]> of
1.31 +* the sequence of characters in the string pointed to by <[s2]>
1.32 +* (excluding the terminating null character).
1.33 +* RETURNS
1.34 +* Returns a pointer to the located string segment, or a null
1.35 +* pointer if the string <[s2]> is not found. If <[s2]> points to
1.36 +* a string with zero length, the <[s1]> is returned.
1.37 +* PORTABILITY
1.38 +* <<strstr>> is ANSI C.
1.39 +* <<strstr>> requires no supporting OS subroutines.
1.40 +* QUICKREF
1.41 +* strstr ansi pure
1.42 +*
1.43 +*
1.44 +*/
1.45 +
1.46 +
1.47 +
1.48 +#include <string.h>
1.49 +
1.50 +/**
1.51 +Find substring.
1.52 +Scans string1 for the first occurrence of string2.
1.53 +The search does not include terminating null-characters.
1.54 +@return A pointer to the first occurrence of lookfor in searchee.
1.55 +If lookfor is not found in searchee the function returns NULL.
1.56 +@param searchee Null-terminated string to search.
1.57 +@param lookfor Null-terminated string containing the substring to search for.
1.58 +*/
1.59 +EXPORT_C char *
1.60 +strstr (const char *searchee, const char *lookfor)
1.61 +{
1.62 + if (*searchee == 0)
1.63 + {
1.64 + if (*lookfor)
1.65 + return (char *) NULL;
1.66 + return (char *) searchee;
1.67 + }
1.68 +
1.69 + while (*searchee)
1.70 + {
1.71 + size_t i;
1.72 + i = 0;
1.73 +
1.74 + for (;;)
1.75 + {
1.76 + if (lookfor[i] == 0)
1.77 + {
1.78 + return (char *) searchee;
1.79 + }
1.80 +
1.81 + if (lookfor[i] != searchee[i])
1.82 + {
1.83 + break;
1.84 + }
1.85 + i++;
1.86 + }
1.87 + searchee++;
1.88 + }
1.89 +
1.90 + return (char *) NULL;
1.91 +}