src/table.c
static ssize_t
remove_ansi_escape_seq(char *line, ssize_t bytes)
{
	char	   *ptr = line;
	int			not_processed = bytes;
	char	   *writeptr = ptr;

	if (bytes == 0)
		return 0;

	/* fast mode, escape detection */
	while (not_processed > 0)
	{
		if (*ptr == '\x1b')
			break;

		not_processed -= 1;
		ptr += 1;
	}

	/* when there are not escape sequence, then returns original size */
	if (not_processed == 0)
		return bytes;

	writeptr = ptr;

	/*
	 * there are ANSI escape sequences, and
	 * we need to clean it.
	 */
	while (not_processed > 0)
	{
		if (*ptr != '\x1b')
		{
			*writeptr++ = *ptr++;
			not_processed -= 1;
		}
		else
		{
			if (not_processed > 2)
			{
				not_processed -= 2;
				ptr += 1;

				if (*ptr++ == '[')
				{
					while (not_processed-- > 0)
					{
						int		c = *ptr++;

						if (c)
						{
							if (c >= '@' && c <= '~')
								break;
						}
						else
							/* broken ascii escape sequence or end of line? */
							goto finish_deescape;
					}
				}
			}
			else
				break;
		}
	}

finish_deescape:

	*writeptr++ = '\0';

	return writeptr - line;
}
/*
 * Remove ANSI escape sequences from input line
 */
Remove ANSI escape sequences from input line
Remove ANSI escape sequences from input line
static ssize_t
remove_ansi_escape_seq(char *line, ssize_t bytes)
{
	char	   *ptr = line;
	int			not_processed = bytes;
	char	   *writeptr = ptr;
	if (bytes == 0)
		return 0;
	while (not_processed > 0)
	{
		if (*ptr == '\x1b')
			break;
		not_processed -= 1;
		ptr += 1;
	}
	if (not_processed == 0)
		return bytes;
	writeptr = ptr;
	while (not_processed > 0)
	{
		if (*ptr != '\x1b')
		{
			*writeptr++ = *ptr++;
			not_processed -= 1;
		}
		else
		{
			if (not_processed > 2)
			{
				not_processed -= 2;
				ptr += 1;
				if (*ptr++ == '[')
				{
					while (not_processed-- > 0)
					{
						int		c = *ptr++;
						if (c)
						{
							if (c >= '@' && c <= '~')
								break;
						}
						else
							goto finish_deescape;
					}
				}
			}
			else
				break;
		}
	}
finish_deescape:
	*writeptr++ = '\0';
	return writeptr - line;
}
static ssize_t remove_ansi_escape_seq ( char * line , ssize_t bytes ) { char * ptr = line ; int not_processed = bytes ; char * writeptr = ptr ; if ( bytes == 0 ) return 0 ; while ( not_processed > 0 ) { if ( * ptr == ' \x1b ' ) break ; not_processed -= 1 ; ptr += 1 ; } if ( not_processed == 0 ) return bytes ; writeptr = ptr ; while ( not_processed > 0 ) { if ( * ptr != ' \x1b ' ) { * writeptr ++ = * ptr ++ ; not_processed -= 1 ; } else { if ( not_processed > 2 ) { not_processed -= 2 ; ptr += 1 ; if ( * ptr ++ == ' ' ) { while ( not_processed -- > 0 ) { int c = * ptr ++ ; if ( c ) { if ( c >= ' ' && c <= ' ' ) break ; } else goto finish_deescape ; } } } else break ; } } finish_deescape : * writeptr ++ = ' \0 ' ; return writeptr - line ; }
Remove ANSI escape sequences from input line
Remove ANSI escape sequences from input line
/* fast mode, escape detection */ /* when there are not escape sequence, then returns original size */ /*
	 * there are ANSI escape sequences, and
	 * we need to clean it.
	 */ /* broken ascii escape sequence or end of line? */