/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#include <string.h>

/** @addtogroup string */
/** @{ */

/**
*	Length of the initial segment of a string containing a set of characters.
*
*	The function returns the length of the initial segment of the string
*	\p str containing only characters that are not in \p set. If the \p set
*	is empty, then the length of the string str is is returned.
*
*	@param	str		Pointer to the string
*	@param	set		The set of characters that can not be in \p str
*	@return			The length of the initials segment of \p str that contains
*					only characters not in the \p set.
*/

size_t	strcspn( const char *str, const char *set )
{
int				map[ 8 ];
size_t			len;
unsigned char	c;

	map[ 0 ] = map[ 1 ] = map[ 2 ] = map[ 3 ] = 0;
	map[ 4 ] = map[ 5 ] = map[ 6 ] = map[ 7 ] = 0;

	while ( ( c = *set++ ) )

		map[ c >> 5 ] |= 1 << ( c & 31 );

	map[ 0 ] |= 1;

	for ( len = 0 ;; len++ ) {

		c = *str++;
		if ( map[ c >> 5 ] & ( 1 << ( c & 31 ) ) ) break;
	}

	return( len );
}

/** @} */

