diff -r 000000000000 -r e4d67989cc36 genericopenlibs/cstdlib/LCHAR/STRRCHR.C --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/genericopenlibs/cstdlib/LCHAR/STRRCHR.C Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* FUNCTION +* <>---reverse search for character in string +* INDEX +* strrchr +* ANSI_SYNOPSIS +* #include +* char * strrchr(const char *<[string]>, int <[c]>); +* TRAD_SYNOPSIS +* #include +* char * strrchr(<[string]>, <[c]>); +* char *<[string]>; +* int *<[c]>; +* This function finds the last occurence of <[c]> (converted to +* a char) in the string pointed to by <[string]> (including the +* terminating null character). +* RETURNS +* Returns a pointer to the located character, or a null pointer +* if <[c]> does not occur in <[string]>. +* PORTABILITY +* <> is ANSI C. +* <> requires no supporting OS subroutines. +* QUICKREF +* strrchr ansi pure +* +* +*/ + + + +#include + +/** +Find last occurrence of character in string. +Returns the last occurrence of c in string. +The null-terminating character is included as part of the string and can also be searched. +@return If character is found, a pointer to the last occurrence of c in string is returned. +If not, NULL is returned. +@param s Null-terminated string scanned in the search. +@param i Character to be found. +*/ +EXPORT_C char * +strrchr (const char *s, int i) +{ + const char *last = NULL; + i = (char)i; + + for (;;) + { + int c = *s++; + if (c == i) + last = s - 1; + if (c == 0) + break; + } + + return (char *) last; +} + +EXPORT_C char * +rindex (const char *s, int c) +{ + return strrchr (s, c); +}