static pgNAME lower_or_remove_dquote()

in convert.c [3324:3371]


static pgNAME lower_or_remove_dquote(pgNAME nm, const UCHAR *src, int srclen, int ccsc)
{
	int	i, outlen;
	char *tc;
	UCHAR	tchar;
	BOOL	idQuote;
	encoded_str	encstr;

	if (nm.name)
		tc = realloc(nm.name, srclen + 1);
	else
		tc = malloc(srclen + 1);
	if (!tc)
	{
		NULL_THE_NAME(nm);
		return nm;
	}
	nm.name = tc;
	idQuote = (src[0] == IDENTIFIER_QUOTE);
	encoded_str_constr(&encstr, ccsc, (const char *) src);
	for (i = 0, tchar = encoded_nextchar(&encstr), outlen = 0; i < srclen; i++, tchar = encoded_nextchar(&encstr))
	{
		if (MBCS_NON_ASCII(encstr))
		{
			tc[outlen++] = tchar;
			continue;
		}
		if (idQuote)
		{
			if (IDENTIFIER_QUOTE == tchar)
			{
				if (0 == i)
					continue;
				if (i == srclen - 1)
					continue;
				i++;
				tchar = encoded_nextchar(&encstr);
			}
			tc[outlen++] = tchar;
		}
		else
		{
			tc[outlen++] = tolower(tchar);
		}
	}
	tc[outlen] = '\0';
	return nm;
}