/****************************************************************************/
/*	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 */
/** @{ */

/**
*	Extracts a token from a string.
*
*	If the \p string pointer is NULL, then the function does nothing.
*	Otherwise, the function looks for the first occurence of any character
*	from the set \p delim in \p *string. If no occurence is found, then
*	\p *string is set to NULL. Otherwise, the occurence in \p *string is
*	replaced with a NUL and \p *string is set to the character just
*	after the occurence. That is, if \p *string points to the string
*	<c>"First Second"</c> and \p delim contains the string <c>" "</c>,
*	then this function will set \p string to the address of the letter 'S'
*	in the string and will replace the space between \p First and \p Second
*	with a NUL.
*	If the delimiter character set is empty, then it is treated as if it
*	was not found in the string.
*
*	@warning
*	This function is dangerous because it changes the original string.
*	Be very cautious when you are using it.
*
*	@param	string	Pointer to a pointer to a string
*	@param	delim	Pointer to a string of delimiter characters
*	@return			The original value of \p *string
*/

char	*strsep( char **string, const char *delim )
{
char	*start;
char	*where;

	if ( ( start = *string ) ) {

		if ( ( where = strpbrk( start, delim ) ) ) {

			*where = '\0';
			*string = where + 1;
		}
		else {

			*string = NULL;
		}
	}

	return( start );
}

/** @} */

