end -= 1; tmp = '%'; *end = NULL;
end -= 1; tmp = '%'; *end = nsnull;
RFC2231ParmFolding(const char *parmName, const char *charset, 				   const char *language, const char *parmValue){#define PR_MAX_FOLDING_LEN 75			// this is to gurantee the folded line will								// never be greater than 78 = 75 + CRLFLWSP	char *foldedParm = NULL;	char *dupParm = NULL;	PRInt32 parmNameLen = 0;	PRInt32 parmValueLen = 0;	PRInt32 charsetLen = 0;	PRInt32 languageLen = 0;	PRBool needEscape = PR_FALSE;	NS_ASSERTION(parmName && *parmName && parmValue && *parmValue, "null parameters");	if (!parmName || !*parmName || !parmValue || !*parmValue)		return NULL;	if ((charset && *charset && PL_strcasecmp(charset, "us-ascii") != 0) || 		(language && *language && PL_strcasecmp(language, "en") != 0 &&		 PL_strcasecmp(language, "en-us") != 0))		needEscape = PR_TRUE;	if (needEscape)		dupParm = NET_Escape(parmValue, URL_PATH);	else 		dupParm = PL_strdup(parmValue);	if (!dupParm)		return NULL;	if (needEscape)	{		parmValueLen = PL_strlen(dupParm);		parmNameLen = PL_strlen(parmName);	}	if (needEscape)		parmNameLen += 5;		// *=__'__'___ or *[0]*=__'__'__ or *[1]*=___	else		parmNameLen += 5;		// *[0]="___";	charsetLen = charset ? PL_strlen(charset) : 0;	languageLen = language ? PL_strlen(language) : 0;	if ((parmValueLen + parmNameLen + charsetLen + languageLen) <		PR_MAX_FOLDING_LEN)	{		foldedParm = PL_strdup(parmName);		if (needEscape)		{			StrAllocCat(foldedParm, "*=");			if (charsetLen)				StrAllocCat(foldedParm, charset);			StrAllocCat(foldedParm, "'");			if (languageLen)				StrAllocCat(foldedParm, language);			StrAllocCat(foldedParm, "'");		}		else			StrAllocCat(foldedParm, "=\"");		StrAllocCat(foldedParm, dupParm);		if (!needEscape)			StrAllocCat(foldedParm, "\"");		goto done;	}	else	{		int curLineLen = 0;		int counter = 0;		char digits[32];		char *start = dupParm;		char *end = NULL;		char tmp = 0;		while (parmValueLen > 0)		{			curLineLen = 0;			if (counter == 0) {				PR_FREEIF(foldedParm)				foldedParm = PL_strdup(parmName);			}			else {				if (needEscape)					StrAllocCat(foldedParm, "\r\n ");				else					StrAllocCat(foldedParm, ";\r\n ");				StrAllocCat(foldedParm, parmName);			}			XP_SPRINTF(digits, "*%d", counter);			StrAllocCat(foldedParm, digits);			curLineLen += PL_strlen(digits);			if (needEscape)			{				StrAllocCat(foldedParm, "*=");				if (counter == 0)				{					if (charsetLen)						StrAllocCat(foldedParm, charset);					StrAllocCat(foldedParm, "'");					if (languageLen)						StrAllocCat(foldedParm, language);					StrAllocCat (foldedParm, "'");					curLineLen += charsetLen;					curLineLen += languageLen;				}			}			else			{				StrAllocCat(foldedParm, "=\"");			}			counter++;			curLineLen += parmNameLen;			if (parmValueLen <= PR_MAX_FOLDING_LEN - curLineLen)				end = start + parmValueLen;			else				end = start + (PR_MAX_FOLDING_LEN - curLineLen);			tmp = 0;			if (*end && needEscape)			{				// check to see if we are in the middle of escaped char				if (*end == '%')				{					tmp = '%'; *end = NULL;				}				else if (end-1 > start && *(end-1) == '%')				{					end -= 1; tmp = '%'; *end = NULL;				}				else if (end-2 > start && *(end-2) == '%')				{					end -= 2; tmp = '%'; *end = NULL;				}				else				{					tmp = *end; *end = NULL;				}			}			else			{				tmp = *end; *end = NULL;			}			StrAllocCat(foldedParm, start);			if (!needEscape)				StrAllocCat(foldedParm, "\"");			parmValueLen -= (end-start);			if (tmp)				*end = tmp;			start = end;		}	}done:	PR_FREEIF(dupParm);	return foldedParm;}