sl@0: /*
sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description:
sl@0: * FUNCTION
sl@0: * <<strspn>>---find initial match
sl@0: * INDEX
sl@0: * strspn
sl@0: * ANSI_SYNOPSIS
sl@0: * #include <string.h>
sl@0: * size_t strspn(const char *<[s1]>, const char *<[s2]>);
sl@0: * TRAD_SYNOPSIS
sl@0: * #include <string.h>
sl@0: * size_t strspn(<[s1]>, <[s2]>)
sl@0: * char *<[s1]>;
sl@0: * char *<[s2]>;
sl@0: * This function computes the length of the initial segment of
sl@0: * the string pointed to by <[s1]> which consists entirely of
sl@0: * characters from the string pointed to by <[s2]> (excluding the
sl@0: * terminating null character).
sl@0: * RETURNS
sl@0: * <<strspn>> returns the length of the segment found.
sl@0: * PORTABILITY
sl@0: * <<strspn>> is ANSI C.
sl@0: * <<strspn>> requires no supporting OS subroutines.
sl@0: * QUICKREF
sl@0: * strspn ansi pure
sl@0: * 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: 
sl@0: #include <string.h>
sl@0: 
sl@0: /**
sl@0: Get length of substring composed of given characters.
sl@0: Scans s1 character by character, returning the number of characters read before 
sl@0: the first character not included in s2 is found.
sl@0: The search does not include terminating null-characters.
sl@0: @return the length of the initial substring of s1 
sl@0: that is only composed of characters included in s2.
sl@0: @param s1 Null-terminated string to be scanned. 
sl@0: @param s2 Null-terminated string containing character set.
sl@0: */
sl@0: EXPORT_C size_t
sl@0: strspn (const char *s1, const char *s2)
sl@0: {
sl@0:   const char *s = s1;
sl@0:   const char *c;
sl@0: 
sl@0:   while (*s1)
sl@0:     {
sl@0:       for (c = s2; *c; c++)
sl@0: 	{
sl@0: 	  if (*s1 == *c)
sl@0: 	    break;
sl@0: 	}
sl@0:       if (*c == '\0')
sl@0: 	break;
sl@0:       s1++;
sl@0:     }
sl@0: 
sl@0:   return s1 - s;
sl@0: }