Skip to content

Commit

Permalink
fix bug 14914. r=cata (several weeks ago). change the GetEncoder/GetD…
Browse files Browse the repository at this point in the history
…ecoder from a loop which create/destroy/IsEqual of nsString to use PROGID directly
  • Loading branch information
ftang%netscape.com committed Nov 2, 1999
1 parent ccd5e48 commit ef4beb6
Showing 1 changed file with 28 additions and 44 deletions.
72 changes: 28 additions & 44 deletions intl/uconv/src/nsCharsetConverterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ class nsCharsetConverterManager : public nsICharsetConverterManager
nsICharsetConverterInfo * GetICharsetConverterInfo(ConverterInfo * ci,
PRInt32 aIndex, PRInt32 * aSize);

/**
* General method for finding and instantiating a Converter.
*/
nsresult GetCharsetConverter(const nsString * aSrc, void ** aResult,
const nsCID * aCID, const ConverterInfo * aArray, PRInt32 aSize);

public:

Expand Down Expand Up @@ -378,31 +373,6 @@ nsCharsetConverterManager::GetICharsetConverterInfo(ConverterInfo * aArray,
return NULL;
}

nsresult nsCharsetConverterManager::GetCharsetConverter(
const nsString * aSrc,
void ** aResult,
const nsCID * aCID,
const ConverterInfo * aArray,
PRInt32 aSize)
{
nsresult res = NS_ERROR_UCONV_NOCONV;
nsString * str;
GetCharsetName(aSrc, &str);

*aResult = NULL;
for (PRInt32 i=0; i<aSize; i++) if (str->EqualsIgnoreCase(*(aArray[i].mCharset))) {
res = nsComponentManager::CreateInstance(*(aArray[i].mCID),NULL,*aCID,aResult);
break;
}

delete str;

// well, we didn't found any converter. Damn, life sucks!
if ((*aResult == NULL) && (NS_SUCCEEDED(res)))
res = NS_ERROR_UCONV_NOCONV;

return res;
}

//----------------------------------------------------------------------
// Interface nsICharsetConverterManager [implementation]
Expand All @@ -411,28 +381,42 @@ NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeEncoder(
const nsString * aDest,
nsIUnicodeEncoder ** aResult)
{
*aResult= nsnull;
nsIComponentManager* comMgr;
nsresult res;
if (!mMappingDone) {
res = CreateMapping();
if NS_FAILED(res) return res;
}

return GetCharsetConverter(aDest, (void **) aResult, &kIUnicodeEncoderIID,
mEncArray, mEncSize);
res = NS_GetGlobalComponentManager(&comMgr);
if(NS_FAILED(res))
return res;
PRInt32 baselen = nsCRT::strlen(NS_UNICODEENCODER_PROGID_BASE);
char progid[256];
PL_strncpy(progid, NS_UNICODEENCODER_PROGID_BASE, 256);
aDest->ToCString(progid + baselen, 256 - baselen);
res = comMgr->CreateInstanceByProgID(progid,NULL,
kIUnicodeEncoderIID ,(void**)aResult);
if(NS_FAILED(res))
res = NS_ERROR_UCONV_NOCONV;
return res;
}

NS_IMETHODIMP nsCharsetConverterManager::GetUnicodeDecoder(
const nsString * aSrc,
nsIUnicodeDecoder ** aResult)
{
*aResult= nsnull;
nsIComponentManager* comMgr;
nsresult res;
if (!mMappingDone) {
res = CreateMapping();
if NS_FAILED(res) return res;
}

return GetCharsetConverter(aSrc, (void **) aResult, &kIUnicodeDecoderIID,
mDecArray, mDecSize);
res = NS_GetGlobalComponentManager(&comMgr);
if(NS_FAILED(res))
return res;
PRInt32 baselen = nsCRT::strlen(NS_UNICODEDECODER_PROGID_BASE);
char progid[256];
PL_strncpy(progid, NS_UNICODEDECODER_PROGID_BASE, 256);
aSrc->ToCString(progid + baselen, 256 - baselen);
res = comMgr->CreateInstanceByProgID(progid,NULL,
kIUnicodeDecoderIID,(void**)aResult);
if(NS_FAILED(res))
res = NS_ERROR_UCONV_NOCONV;
return res;
}

NS_IMETHODIMP nsCharsetConverterManager::GetEncodableCharsets(
Expand Down

0 comments on commit ef4beb6

Please sign in to comment.