//-----------------------------------------------------------------------------
// Copyright © 2004 - Philip Howard - All rights reserved
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//-----------------------------------------------------------------------------
// package	libh/string
// homepage	http://libh.slashusr.org/
//-----------------------------------------------------------------------------
// author	Philip Howard
// email	libh at ipal dot org
// homepage	http://phil.ipal.org/
//-----------------------------------------------------------------------------
// This file is best viewed using a fixed spaced font such as Courier
// and in a display at least 120 columns wide.
//-----------------------------------------------------------------------------

#include "string_lib.h"

__PROTO_BEGIN__
//-----------------------------------------------------------------------------
// function	split_sep_find_clist
//
// purpose	Find the start and end of the next separator and update the
//		split state for the new position.
//
//		The separator is any character found in a specified list given
//		as a string.
//
// argument	1 (split_p) pointer to split state
//
// returns	(int) -1 : error
//		(int)  0 : separator found
//		(int)  1 : end of string, not found
//-----------------------------------------------------------------------------
int
split_sep_find_clist (
    split_p		arg_split
    )
__PROTO_END__
{
    char *	str_ptr		;
    char *	str_end		;
    char *	list_ptr	;
    char *	list_end	;


    str_ptr = arg_split->next_ptr;
    str_end = arg_split->data_end;
    list_ptr = arg_split->sep.data.ptr;
    list_end = arg_split->sep.data.end;

    //-- Find start of separator.
    while ( str_ptr < str_end ) {
	char *	list_index	;
	int	str_ch		;

	str_ch = * str_ptr;
	list_index = list_ptr;
	while ( list_index < list_end && str_ch != * list_index ) ++ list_index;
	if ( list_index < list_end ) break;
	++ str_ptr;
    }

    //-- The separator or end of string is the end of this part.
    arg_split->part_end = str_ptr;

    //-- If end of string, return not found
    if ( str_ptr >= str_end ) {
	arg_split->next_ptr = NULL;
	return 1;
    }

    //-- Find end of separator.
    ++ str_ptr;
    arg_split->next_ptr = str_ptr;

    //-- Return success.
    return 0;
}

