1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRSPN.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,75 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* FUNCTION
1.19 +* <<strspn>>---find initial match
1.20 +* INDEX
1.21 +* strspn
1.22 +* ANSI_SYNOPSIS
1.23 +* #include <string.h>
1.24 +* size_t strspn(const char *<[s1]>, const char *<[s2]>);
1.25 +* TRAD_SYNOPSIS
1.26 +* #include <string.h>
1.27 +* size_t strspn(<[s1]>, <[s2]>)
1.28 +* char *<[s1]>;
1.29 +* char *<[s2]>;
1.30 +* This function computes the length of the initial segment of
1.31 +* the string pointed to by <[s1]> which consists entirely of
1.32 +* characters from the string pointed to by <[s2]> (excluding the
1.33 +* terminating null character).
1.34 +* RETURNS
1.35 +* <<strspn>> returns the length of the segment found.
1.36 +* PORTABILITY
1.37 +* <<strspn>> is ANSI C.
1.38 +* <<strspn>> requires no supporting OS subroutines.
1.39 +* QUICKREF
1.40 +* strspn ansi pure
1.41 +*
1.42 +*
1.43 +*/
1.44 +
1.45 +
1.46 +
1.47 +#include <string.h>
1.48 +
1.49 +/**
1.50 +Get length of substring composed of given characters.
1.51 +Scans s1 character by character, returning the number of characters read before
1.52 +the first character not included in s2 is found.
1.53 +The search does not include terminating null-characters.
1.54 +@return the length of the initial substring of s1
1.55 +that is only composed of characters included in s2.
1.56 +@param s1 Null-terminated string to be scanned.
1.57 +@param s2 Null-terminated string containing character set.
1.58 +*/
1.59 +EXPORT_C size_t
1.60 +strspn (const char *s1, const char *s2)
1.61 +{
1.62 + const char *s = s1;
1.63 + const char *c;
1.64 +
1.65 + while (*s1)
1.66 + {
1.67 + for (c = s2; *c; c++)
1.68 + {
1.69 + if (*s1 == *c)
1.70 + break;
1.71 + }
1.72 + if (*c == '\0')
1.73 + break;
1.74 + s1++;
1.75 + }
1.76 +
1.77 + return s1 - s;
1.78 +}