os/ossrv/genericopenlibs/cstdlib/LCHAR/STRCSPN.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LCHAR/STRCSPN.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,71 @@
     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 +* <<strcspn>>---count chars not in string
    1.20 +* INDEX
    1.21 +* strcspn
    1.22 +* ANSI_SYNOPSIS
    1.23 +* size_t strcspn(const char *<[s1]>, const char *<[s2]>);
    1.24 +* TRAD_SYNOPSIS
    1.25 +* size_t strcspn(<[s1]>, <[s2]>)
    1.26 +* char *<[s1]>;
    1.27 +* char *<[s2]>;
    1.28 +* This function computes the length of the initial part of
    1.29 +* the string pointed to by <[s1]> which consists entirely of
    1.30 +* characters <[NOT]> from the string pointed to by <[s2]>
    1.31 +* (excluding the terminating null character).
    1.32 +* RETURNS
    1.33 +* <<strcspn>> returns the length of the substring found.
    1.34 +* PORTABILITY
    1.35 +* <<strcspn>> is ANSI C.
    1.36 +* <<strcspn>> requires no supporting OS subroutines.
    1.37 +* 
    1.38 +*
    1.39 +*/
    1.40 +
    1.41 +
    1.42 +
    1.43 +#include <string.h>
    1.44 +
    1.45 +/**
    1.46 +Search string for occurrence of character set.
    1.47 +Scans s1 character by character, returning the number of characters read
    1.48 +until the first occurrence of any character included in s2.
    1.49 +The search includes terminating null-characters, so the function 
    1.50 +will return the length of s1 if none of the characters included in s2 is in s1.
    1.51 +@return the position in s1 of the first occurence of a component character of s2.
    1.52 +@param s1 Null-terminated string to be scanned. 
    1.53 +@param s2 Null-terminated string containing the character set to search for.
    1.54 +*/
    1.55 +EXPORT_C size_t
    1.56 +strcspn (const char *s1, const char *s2)
    1.57 +{
    1.58 +  const char *s = s1;
    1.59 +  const char *c;
    1.60 +
    1.61 +  while (*s1)
    1.62 +    {
    1.63 +      for (c = s2; *c; c++)
    1.64 +	{
    1.65 +	  if (*s1 == *c)
    1.66 +	    break;
    1.67 +	}
    1.68 +      if (*c)
    1.69 +	break;
    1.70 +      s1++;
    1.71 +    }
    1.72 +
    1.73 +  return s1 - s;
    1.74 +}