All pastes #151476 Raw Edit

Mine

public text v1 · immutable
#151476 ·published 2006-08-28 02:40 UTC
rendered paste body

char *trim(char *str)
{
  return strtrim(str, "\r\n\t ");
}

char	*strrtrim(char *str, const char *trim)
{
	char	*end;
	
	if(!str)
		return NULL;

	if(!trim)
		trim = " \t\n\r";
		
	end = str + strlen(str);

	while(end-- > str)
	{
		if(!strchr(trim, *end))
			return str;
		*end = 0;
	}
	return str;
}

char	*strltrim(char *str, const char *trim)
{
	if(!str)
		return NULL;
	
	if(!trim)
		trim = " \t\r\n";
	
	while(*str)
	{
		if(!strchr(trim, *str))
			return str;
		++str;
	}
	return str;
}

char	*strtrim(char *str, const char *trim)
{
	return strltrim(strrtrim(str, trim), trim);
}