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