leaf.InsertWithConversion("%2F", (PRUint32)aOffset);
leaf.Insert("%2F", (PRUint32)aOffset);
FileSystemDataSource::GetFolderList(nsIRDFResource *source, PRBool allowHidden,				PRBool onlyFirst, nsISimpleEnumerator** aResult){	nsresult	rv;	nsCOMPtr<nsISupportsArray> nameArray;	rv = NS_NewISupportsArray(getter_AddRefs(nameArray));	if (NS_FAILED(rv)) return rv;	const char		*parentURI = nsnull;	rv = source->GetValueConst(&parentURI);	if (NS_FAILED(rv)) return(rv);	if (!parentURI)	return(NS_ERROR_UNEXPECTED);	nsCOMPtr<nsIURI>	fileURI;	if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(fileURI), parentURI)))		return(rv);	if (!fileURI)	return(NS_ERROR_UNEXPECTED);	nsCOMPtr<nsIChannel>	channel;	if (NS_FAILED(rv = NS_OpenURI(getter_AddRefs(channel), fileURI, nsnull, nsnull)))		return(rv);	if (!channel)	return(NS_ERROR_UNEXPECTED);	nsCOMPtr<nsIFileChannel>	fileChannel = do_QueryInterface(channel);	if (!fileChannel)	return(NS_ERROR_UNEXPECTED);	nsCOMPtr<nsIFile>	aDir;	if (NS_FAILED(rv = fileChannel->GetFile(getter_AddRefs(aDir))))		return(rv);	nsCOMPtr<nsISimpleEnumerator>	dirContents;	if (NS_FAILED(rv = aDir->GetDirectoryEntries(getter_AddRefs(dirContents))))		return(rv);	if (!dirContents)	return(NS_ERROR_UNEXPECTED);	PRBool			hasMore;	while(NS_SUCCEEDED(rv = dirContents->HasMoreElements(&hasMore)) &&		(hasMore == PR_TRUE))	{		nsCOMPtr<nsISupports>	isupports;		if (NS_FAILED(rv = dirContents->GetNext(getter_AddRefs(isupports))))			break;		nsCOMPtr<nsIFile>	aFile = do_QueryInterface(isupports);		if (!aFile)	break;		if (allowHidden == PR_FALSE)		{			PRBool			hiddenFlag = PR_FALSE;			if (NS_FAILED(rv = aFile->IsHidden(&hiddenFlag)))				break;			if (hiddenFlag == PR_TRUE)	continue;		}		PRUnichar		*leafUni = nsnull;		if (NS_FAILED(rv = aFile->GetUnicodeLeafName(&leafUni)))			break;		if (!leafUni)	break;		nsAutoString		fullURI;		fullURI.AssignWithConversion(parentURI);		if (fullURI.Last() != PRUnichar('/'))		{			fullURI.Append(PRUnichar('/'));		}		nsAutoString		leaf(leafUni);		Recycle(leafUni);		leafUni = nsnull;		// we need to escape this leaf name;		// for now, let's just hack it and encode spaces and slashes		PRInt32			aOffset;		while ((aOffset = leaf.FindChar(' ')) >= 0)		{			leaf.Cut((PRUint32)aOffset, 1);			leaf.InsertWithConversion("%20", (PRUint32)aOffset);		}		while ((aOffset = leaf.FindChar('/')) >= 0)		{			leaf.Cut((PRUint32)aOffset, 1);			leaf.InsertWithConversion("%2F", (PRUint32)aOffset);		}		// append the encoded name		fullURI.Append(leaf);		PRBool			dirFlag = PR_FALSE;		if (NS_FAILED(rv = aFile->IsDirectory(&dirFlag)))			break;		if (dirFlag == PR_TRUE)		{			// XXX hmmm, causes problems getting name,			// so comment it out for the short term//			fullURI.Append(PRUnichar('/'));		}		nsCOMPtr<nsIRDFResource>	fileRes;		gRDFService->GetUnicodeResource(fullURI.GetUnicode(), getter_AddRefs(fileRes));		nameArray->AppendElement(fileRes);		if (onlyFirst == PR_TRUE)	break;	}	nsISimpleEnumerator* result = new nsArrayEnumerator(nameArray);	if (! result)		return NS_ERROR_OUT_OF_MEMORY;	NS_ADDREF(result);	*aResult = result;	return NS_OK;}