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