genericopenlibs/cstdlib/LCHAR/STRSPN.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 * <<strspn>>---find initial match
       
    17 * INDEX
       
    18 * strspn
       
    19 * ANSI_SYNOPSIS
       
    20 * #include <string.h>
       
    21 * size_t strspn(const char *<[s1]>, const char *<[s2]>);
       
    22 * TRAD_SYNOPSIS
       
    23 * #include <string.h>
       
    24 * size_t strspn(<[s1]>, <[s2]>)
       
    25 * char *<[s1]>;
       
    26 * char *<[s2]>;
       
    27 * This function computes the length of the initial segment of
       
    28 * the string pointed to by <[s1]> which consists entirely of
       
    29 * characters from the string pointed to by <[s2]> (excluding the
       
    30 * terminating null character).
       
    31 * RETURNS
       
    32 * <<strspn>> returns the length of the segment found.
       
    33 * PORTABILITY
       
    34 * <<strspn>> is ANSI C.
       
    35 * <<strspn>> requires no supporting OS subroutines.
       
    36 * QUICKREF
       
    37 * strspn ansi pure
       
    38 * 
       
    39 *
       
    40 */
       
    41 
       
    42 
       
    43 
       
    44 #include <string.h>
       
    45 
       
    46 /**
       
    47 Get length of substring composed of given characters.
       
    48 Scans s1 character by character, returning the number of characters read before 
       
    49 the first character not included in s2 is found.
       
    50 The search does not include terminating null-characters.
       
    51 @return the length of the initial substring of s1 
       
    52 that is only composed of characters included in s2.
       
    53 @param s1 Null-terminated string to be scanned. 
       
    54 @param s2 Null-terminated string containing character set.
       
    55 */
       
    56 EXPORT_C size_t
       
    57 strspn (const char *s1, const char *s2)
       
    58 {
       
    59   const char *s = s1;
       
    60   const char *c;
       
    61 
       
    62   while (*s1)
       
    63     {
       
    64       for (c = s2; *c; c++)
       
    65 	{
       
    66 	  if (*s1 == *c)
       
    67 	    break;
       
    68 	}
       
    69       if (*c == '\0')
       
    70 	break;
       
    71       s1++;
       
    72     }
       
    73 
       
    74   return s1 - s;
       
    75 }