/*
 *  Remove leading & trailing letters in the list from the string s.
 *	Removal is done "in-place" in the string s.
 *	Returned value is merely the original s.
 */
#include <ncbi.h>
#include <gishlib.h>

CharPtr LIBCALL
str_trim(s, list)
	register CharPtr s, list;
{
	/* cmap[] is allocated on the stack, in case of interrupt */
	Byte cmap[1<<(CHAR_BIT*sizeof(Byte))];
	register BytePtr us = (BytePtr)s, ulist = (BytePtr)list;
	register BytePtr	start;

	if (*ulist == NULLB)
		return s;

	Nlm_MemSet((VoidPtr)cmap, 0, sizeof(cmap));
	while (*ulist != NULLB)
		cmap[*ulist++] = 1;

	while (cmap[*us] != NULLB)
		++us;

	start = us;

	/* Find end of string, then work backwards */
	while (*us != NULLB)
		++us;

	if (us == start) {
		*s = NULLB;
		return s;
	}

	while (cmap[*--us] != NULLB)
		*us = NULLB;
	Nlm_MemCpy((VoidPtr)s, (VoidPtr)start, us - start + 2);
	return s;
}
