genericopenlibs/cstdlib/LCHAR/STRCSPN.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 * <<strcspn>>---count chars not in string
       
    17 * INDEX
       
    18 * strcspn
       
    19 * ANSI_SYNOPSIS
       
    20 * size_t strcspn(const char *<[s1]>, const char *<[s2]>);
       
    21 * TRAD_SYNOPSIS
       
    22 * size_t strcspn(<[s1]>, <[s2]>)
       
    23 * char *<[s1]>;
       
    24 * char *<[s2]>;
       
    25 * This function computes the length of the initial part of
       
    26 * the string pointed to by <[s1]> which consists entirely of
       
    27 * characters <[NOT]> from the string pointed to by <[s2]>
       
    28 * (excluding the terminating null character).
       
    29 * RETURNS
       
    30 * <<strcspn>> returns the length of the substring found.
       
    31 * PORTABILITY
       
    32 * <<strcspn>> is ANSI C.
       
    33 * <<strcspn>> requires no supporting OS subroutines.
       
    34 * 
       
    35 *
       
    36 */
       
    37 
       
    38 
       
    39 
       
    40 #include <string.h>
       
    41 
       
    42 /**
       
    43 Search string for occurrence of character set.
       
    44 Scans s1 character by character, returning the number of characters read
       
    45 until the first occurrence of any character included in s2.
       
    46 The search includes terminating null-characters, so the function 
       
    47 will return the length of s1 if none of the characters included in s2 is in s1.
       
    48 @return the position in s1 of the first occurence of a component character of s2.
       
    49 @param s1 Null-terminated string to be scanned. 
       
    50 @param s2 Null-terminated string containing the character set to search for.
       
    51 */
       
    52 EXPORT_C size_t
       
    53 strcspn (const char *s1, const char *s2)
       
    54 {
       
    55   const char *s = s1;
       
    56   const char *c;
       
    57 
       
    58   while (*s1)
       
    59     {
       
    60       for (c = s2; *c; c++)
       
    61 	{
       
    62 	  if (*s1 == *c)
       
    63 	    break;
       
    64 	}
       
    65       if (*c)
       
    66 	break;
       
    67       s1++;
       
    68     }
       
    69 
       
    70   return s1 - s;
       
    71 }