genericopenlibs/cstdlib/LCHAR/STRCHR.C
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 * <<strchr>>---search for character in string
       
    17 * INDEX
       
    18 * strchr
       
    19 * ANSI_SYNOPSIS
       
    20 * #include <string.h>
       
    21 * char * strchr(const char *<[string]>, int <[c]>);
       
    22 * TRAD_SYNOPSIS
       
    23 * #include <string.h>
       
    24 * char * strchr(<[string]>, <[c]>);
       
    25 * char *<[string]>;
       
    26 * int *<[c]>;
       
    27 * This function finds the first occurence of <[c]> (converted to
       
    28 * a char) in the string pointed to by <[string]> (including the
       
    29 * terminating null character).
       
    30 * RETURNS
       
    31 * Returns a pointer to the located character, or a null pointer
       
    32 * if <[c]> does not occur in <[string]>.
       
    33 * PORTABILITY
       
    34 * <<strchr>> is ANSI C.
       
    35 * <<strchr>> requires no supporting OS subroutines.
       
    36 * QUICKREF
       
    37 * strchr ansi pure
       
    38 * 
       
    39 *
       
    40 */
       
    41 
       
    42 
       
    43 
       
    44 #include <string.h>
       
    45 
       
    46 /**
       
    47 Find character in string.
       
    48 Returns the first occurrence of i in string.
       
    49 The null-terminating character is included as part of the string 
       
    50 and can also be searched.
       
    51 @return a pointer to the first occurrence of i in string is returned.
       
    52 otherwise NULL is returned.
       
    53 @param s Null-terminated string scanned in the search. 
       
    54 @param i Character to be found.
       
    55 */
       
    56 EXPORT_C char *
       
    57 strchr (const char *s, int i)
       
    58 {
       
    59 	i = (char)i;
       
    60 
       
    61 	for (;;)
       
    62 	{
       
    63 		int c = *s++;
       
    64 		if (c == i)
       
    65 			return (char *) (s - 1);
       
    66 		if (c == 0)
       
    67 			return NULL;
       
    68 	}
       
    69 }
       
    70 
       
    71 EXPORT_C char *
       
    72 index (const char *s, int i)
       
    73 {
       
    74     return strchr(s, i);
       
    75 }