rest of fix for #39172, i18n friendly subscribe dialog.

This commit is contained in:
sspitzer%netscape.com 2000-05-19 22:33:38 +00:00
parent 94b476cc20
commit 7b47f851a0
3 changed files with 48 additions and 1 deletions

View File

@ -58,7 +58,6 @@
#include "nsIEventQueueService.h"
#include "nsIMsgMailNewsUrl.h"
#include "nsIImapService.h"
#include "nsMsgUtils.h"
#include "nsITimer.h"
static NS_DEFINE_CID(kCImapHostSessionList, NS_IIMAPHOSTSESSIONLIST_CID);

View File

@ -531,3 +531,49 @@ CreateUtf7ConvertedStringFromUnicode(const PRUnichar * aSourceString)
}
return dstPtr;
}
nsresult CreateUnicodeStringFromUtf7(const char *aSourceString, PRUnichar **aUnicodeStr)
{
if (!aUnicodeStr)
return NS_ERROR_NULL_POINTER;
PRUnichar *convertedString = NULL;
nsresult res;
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
if(NS_SUCCEEDED(res) && (nsnull != ccm))
{
nsString aCharset; aCharset.AssignWithConversion("x-imap4-modified-utf7");
PRUnichar *unichars = nsnull;
PRInt32 unicharLength;
// convert utf7 to unicode
nsIUnicodeDecoder* decoder = nsnull;
res = ccm->GetUnicodeDecoder(&aCharset, &decoder);
if(NS_SUCCEEDED(res) && (nsnull != decoder))
{
PRInt32 srcLen = PL_strlen(aSourceString);
res = decoder->GetMaxLength(aSourceString, srcLen, &unicharLength);
// temporary buffer to hold unicode string
unichars = new PRUnichar[unicharLength + 1];
if (unichars == nsnull)
{
res = NS_ERROR_OUT_OF_MEMORY;
}
else
{
res = decoder->Convert(aSourceString, &srcLen, unichars, &unicharLength);
unichars[unicharLength] = 0;
}
NS_IF_RELEASE(decoder);
nsString unicodeStr(unichars);
convertedString = unicodeStr.ToNewUnicode();
delete [] unichars;
}
}
*aUnicodeStr = convertedString;
return (convertedString) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

View File

@ -53,6 +53,8 @@ char*
CreateUtf7ConvertedString(const char * aSourceString,
PRBool aConvertToUtf7Imap);
nsresult CreateUnicodeStringFromUtf7(const char *aSourceString, PRUnichar **result);
char *
CreateUtf7ConvertedStringFromUnicode(const PRUnichar *aSourceString);