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