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: * <>---count chars not in string sl@0: * INDEX sl@0: * strcspn sl@0: * ANSI_SYNOPSIS sl@0: * size_t strcspn(const char *<[s1]>, const char *<[s2]>); sl@0: * TRAD_SYNOPSIS sl@0: * size_t strcspn(<[s1]>, <[s2]>) sl@0: * char *<[s1]>; sl@0: * char *<[s2]>; sl@0: * This function computes the length of the initial part of sl@0: * the string pointed to by <[s1]> which consists entirely of sl@0: * characters <[NOT]> from the string pointed to by <[s2]> sl@0: * (excluding the terminating null character). sl@0: * RETURNS sl@0: * <> returns the length of the substring found. sl@0: * PORTABILITY sl@0: * <> is ANSI C. sl@0: * <> requires no supporting OS subroutines. sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: sl@0: /** sl@0: Search string for occurrence of character set. sl@0: Scans s1 character by character, returning the number of characters read sl@0: until the first occurrence of any character included in s2. sl@0: The search includes terminating null-characters, so the function sl@0: will return the length of s1 if none of the characters included in s2 is in s1. sl@0: @return the position in s1 of the first occurence of a component character of s2. sl@0: @param s1 Null-terminated string to be scanned. sl@0: @param s2 Null-terminated string containing the character set to search for. sl@0: */ sl@0: EXPORT_C size_t sl@0: strcspn (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) sl@0: break; sl@0: s1++; sl@0: } sl@0: sl@0: return s1 - s; sl@0: }