printf("RL: '%s'  -  '%s'\n", title.ToNewCString(), child.ToNewCString());
printf("RL: '%s'  -  '%s'\n", NS_LossyConvertUCS2toASCII(title).get(), NS_LossyConvertUCS2toASCII(child).get());
RelatedLinksStreamListener::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,		nsIInputStream *aIStream, PRUint32 sourceOffset, PRUint32 aLength){	nsresult	rv = NS_OK;	if (aLength < 1)	return(rv);	PRUint32	count;	char		*buffer = new char[ aLength ];	if (!buffer)	return(NS_ERROR_OUT_OF_MEMORY);	if (NS_FAILED(rv = aIStream->Read(buffer, aLength, &count)) || count == 0)	{#ifdef	DEBUG		printf("Related Links datasource read failure.\n");#endif		delete []buffer;		return(rv);	}	if (count != aLength)	{#ifdef	DEBUG		printf("Related Links datasource read # of bytes failure.\n");#endif		delete []buffer;		return(NS_ERROR_UNEXPECTED);	}	if (mUnicodeDecoder)	{		char			*aBuffer = buffer;		PRInt32			unicharBufLen = 0;		mUnicodeDecoder->GetMaxLength(aBuffer, aLength, &unicharBufLen);		PRUnichar		*unichars = new PRUnichar [ unicharBufLen+1 ];		do		{			PRInt32		srcLength = aLength;			PRInt32		unicharLength = unicharBufLen;			rv = mUnicodeDecoder->Convert(aBuffer, &srcLength, unichars, &unicharLength);			unichars[unicharLength]=0;  //add this since the unicode converters can't be trusted to do so.			// Move the nsParser.cpp 00 -> space hack to here so it won't break UCS2 file			// Hack Start			for(PRInt32 i=0;i<unicharLength;i++)				if(0x0000 == unichars[i])	unichars[i] = 0x0020;			// Hack End			mBuffer.Append(unichars, unicharLength);			// if we failed, we consume one byte by replace it with U+FFFD			// and try conversion again.			if(NS_FAILED(rv))			{				mUnicodeDecoder->Reset();				mBuffer.Append( (PRUnichar)0xFFFD);				if(((PRUint32) (srcLength + 1)) > aLength)					srcLength = aLength;				else 					srcLength++;				aBuffer += srcLength;				aLength -= srcLength;			}		} while (NS_FAILED(rv) && (aLength > 0));		delete [] unichars;		unichars = nsnull;	}	else	{		mBuffer.AppendWithConversion(buffer, aLength);	}	delete [] buffer;	buffer = nsnull;	// parse out any available lines	while (PR_TRUE)	{		PRInt32 eol = mBuffer.FindCharInSet("\r\n");		if (eol < 0)		{			break;		}		nsAutoString	oneLiner;		if (eol >= 0)		{			mBuffer.Left(oneLiner, eol);			mBuffer.Cut(0, eol+1);		}		if (oneLiner.Length() < 1)	break;#if 0		printf("RL: '%s'\n", oneLiner.ToNewCString());#endif		// yes, very primitive RDF parsing follows		nsAutoString	child, title;		child.Truncate();		title.Truncate();		// get href		PRInt32 theStart = oneLiner.Find("<child href=\"", PR_TRUE);		if (theStart == 0)		{			// get child href			theStart += PL_strlen("<child href=\"");			oneLiner.Cut(0, theStart);			PRInt32 theEnd = oneLiner.FindChar('"');			if (theEnd > 0)			{				oneLiner.Mid(child, 0, theEnd);			}			// get child name			theStart = oneLiner.Find("name=\"", PR_TRUE);			if (theStart >= 0)			{				theStart += PL_strlen("name=\"");				oneLiner.Cut(0, theStart);				theEnd = oneLiner.FindChar('"');				if (theEnd > 0)				{					oneLiner.Mid(title, 0, theEnd);				}			}		}		// check for separator		else if ((theStart = oneLiner.Find("<child instanceOf=\"Separator1\"/>", PR_TRUE)) == 0)		{			nsCOMPtr<nsIRDFResource>	newSeparator;			if (NS_SUCCEEDED(rv = gRDFService->GetAnonymousResource(getter_AddRefs(newSeparator))))			{				mDataSource->Assert(newSeparator, kRDF_type, kNC_BookmarkSeparator, PR_TRUE);				nsIRDFResource	*parent = kNC_RelatedLinksRoot;				PRInt32		numParents = mParentArray.Count();				if (numParents > 0)				{					parent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));				}				mDataSource->Assert(parent, kNC_Child, newSeparator, PR_TRUE);			}		}		else		{			theStart = oneLiner.Find("<Topic name=\"", PR_TRUE);			if (theStart == 0)			{				// get topic name				theStart += PL_strlen("<Topic name=\"");				oneLiner.Cut(0, theStart);				PRInt32 theEnd = oneLiner.FindChar('"');				if (theEnd > 0)				{					oneLiner.Mid(title, 0, theEnd);				}				nsCOMPtr<nsIRDFResource>	newTopic;				if (NS_SUCCEEDED(rv = gRDFService->GetAnonymousResource(getter_AddRefs(newTopic))))				{					mDataSource->Assert(newTopic, kRDF_type, kNC_RelatedLinksTopic, PR_TRUE);					if (title.Length() > 0)					{                        Unescape(title);						const PRUnichar		*titleName = title.get();						if (nsnull != titleName)						{							nsCOMPtr<nsIRDFLiteral> nameLiteral;							if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(titleName, getter_AddRefs(nameLiteral))))							{								mDataSource->Assert(newTopic, kNC_Name, nameLiteral, PR_TRUE);							}						}					}					mParentArray.AppendElement(newTopic);				}			}			else			{				theStart = oneLiner.Find("</Topic>", PR_TRUE);				if (theStart == 0)				{					PRInt32		numParents = mParentArray.Count();					if (numParents > 0)					{						nsIRDFResource	*aChild = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));						mParentArray.RemoveElementAt(numParents - 1);						nsIRDFResource	*aParent = kNC_RelatedLinksRoot;						if (numParents > 1)						{							aParent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 2));						}						mDataSource->Assert(aParent, kNC_Child, aChild, PR_TRUE);					}				}			}		}		if (child.Length() > 0)		{#if 0			printf("RL: '%s'  -  '%s'\n", title.ToNewCString(), child.ToNewCString());#endif			const PRUnichar	*url = child.get();			if (nsnull != url)			{				nsCOMPtr<nsIRDFResource>	relatedLinksChild;				rv = gRDFService->GetAnonymousResource(getter_AddRefs(relatedLinksChild));				if (NS_SUCCEEDED(rv))				{					title.Trim(" ");					if (title.Length() > 0)					{                        Unescape(title);						const PRUnichar	*name = title.get();						if (nsnull != name)						{							nsCOMPtr<nsIRDFLiteral>	nameLiteral;							if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(name, getter_AddRefs(nameLiteral))))							{								mDataSource->Assert(relatedLinksChild, kNC_Name, nameLiteral, PR_TRUE);							}						}					}					// all related links are anonymous, so save off the "#URL" attribute					nsCOMPtr<nsIRDFLiteral>	urlLiteral;					if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(url, getter_AddRefs(urlLiteral))))					{						mDataSource->Assert(relatedLinksChild, kNC_URL, urlLiteral, PR_TRUE);					}					nsIRDFResource	*parent;					PRInt32	numParents = mParentArray.Count();					if (numParents > 0)					{						parent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));					}					else					{						parent = kNC_RelatedLinksRoot;					}					mDataSource->Assert(parent, kNC_Child, relatedLinksChild, PR_TRUE);				}			}		}	}	return(rv);}