os/ossrv/genericopenlibs/cstdlib/LCHAR/STRPBRK.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 * <<strpbrk>>---find chars in string
    17 * INDEX
    18 * strpbrk
    19 * ANSI_SYNOPSIS
    20 * #include <string.h>
    21 * char *strpbrk(const char *<[s1]>, const char *<[s2]>);
    22 * TRAD_SYNOPSIS
    23 * #include <string.h>
    24 * char *strpbrk(<[s1]>, <[s2]>)
    25 * char *<[s1]>;
    26 * char *<[s2]>;
    27 * This function locates the first occurence in the string
    28 * pointed to by <[s1]> of any character in string pointed to by
    29 * <[s2]> (excluding the terminating null character).
    30 * RETURNS
    31 * <<strpbrk>> returns a pointer to the character found in <[s1]>, or a
    32 * null pointer if no character from <[s2]> occurs in <[s1]>.
    33 * PORTABILITY
    34 * <<strpbrk>> requires no supporting OS subroutines.
    35 * 
    36 *
    37 */
    38 
    39 
    40 
    41 #include <string.h>
    42 
    43 /**
    44 Scan string for specified characters.
    45 Scans string1 character by character, returning a pointer to the first character
    46 that matches with any of the characters in string2.
    47 The search does not includes the terminating null-characters.
    48 @return A pointer to the first appearance in string1 of a character specified in s2.
    49 If none of the characters specified in s2 exists in s1, a NULL pointer is returned.
    50 @param s1 Null-terminated string to be scanned. 
    51 @param s2 Null-terminated string containing the character set to search for.
    52 */
    53 EXPORT_C char *
    54 strpbrk (const char *s1, const char *s2)
    55 {
    56   const char *c = s2;
    57   if (!*s1)
    58     return (char *) NULL;
    59 
    60   while (*s1)
    61     {
    62       for (c = s2; *c; c++)
    63 	{
    64 	  if (*s1 == *c)
    65 	    break;
    66 	}
    67       if (*c)
    68 	break;
    69       s1++;
    70     }
    71 
    72   if (*c == '\0')
    73     s1 = NULL;
    74 
    75   return (char *) s1;
    76 }