mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-01 05:43:46 +00:00
add 2nd implementation and fix breakage
This commit is contained in:
parent
989dbdb3c8
commit
a746dd8b56
@ -20,6 +20,7 @@
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
|
||||
|
||||
#include "nsICharsetAlias.h"
|
||||
#include "nsCharsetAliasFactory.h"
|
||||
#include "pratom.h"
|
||||
@ -27,7 +28,108 @@
|
||||
#include "nsUConvDll.h"
|
||||
|
||||
|
||||
#include "nsURLProperties.h"
|
||||
//==============================================================
|
||||
class nsCharsetAlias2 : public nsICharsetAlias
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
public:
|
||||
|
||||
nsCharsetAlias2();
|
||||
virtual ~nsCharsetAlias2();
|
||||
|
||||
NS_IMETHOD GetPreferred(const nsString& aAlias, nsString& oResult);
|
||||
NS_IMETHOD GetPreferred(const PRUnichar* aAlias, const PRUnichar** oResult) ;
|
||||
NS_IMETHOD GetPreferred(const char* aAlias, char* oResult, PRInt32 aBufLength) ;
|
||||
|
||||
NS_IMETHOD Equals(const nsString& aCharset1, const nsString& aCharset2, PRBool* oResult) ;
|
||||
NS_IMETHOD Equals(const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* oResult) ;
|
||||
NS_IMETHOD Equals(const char* aCharset1, const char* aCharset2, PRBool* oResult) ;
|
||||
|
||||
private:
|
||||
nsURLProperties* mDelegate;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMPL_ISUPPORTS(nsCharsetAlias2, kICharsetAliasIID);
|
||||
|
||||
//--------------------------------------------------------------
|
||||
nsCharsetAlias2::nsCharsetAlias2()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
nsAutoString propertyURL("resource://res/charsetalias.properties");
|
||||
mDelegate = new nsURLProperties( propertyURL );
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
nsCharsetAlias2::~nsCharsetAlias2()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
if(mDelegate)
|
||||
delete mDelegate;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsString& aAlias, nsString& oResult)
|
||||
{
|
||||
nsAutoString aKey;
|
||||
aAlias.ToLowerCase(aKey);
|
||||
oResult = "";
|
||||
return mDelegate->Get(aKey, oResult);
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const PRUnichar* aAlias, const PRUnichar** oResult)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const char* aAlias, char* oResult, PRInt32 aBufLength)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::Equals(const nsString& aCharset1, const nsString& aCharset2, PRBool* oResult)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if(aCharset1.EqualsIgnoreCase(aCharset2)) {
|
||||
*oResult = PR_TRUE;
|
||||
return res;
|
||||
}
|
||||
|
||||
if(aCharset1.Equals("") || aCharset2.Equals("")) {
|
||||
*oResult = PR_FALSE;
|
||||
return res;
|
||||
}
|
||||
|
||||
*oResult = PR_FALSE;
|
||||
nsString name1;
|
||||
nsString name2;
|
||||
res = this->GetPreferred(aCharset1, name1);
|
||||
if(NS_SUCCEEDED(res)) {
|
||||
res = this->GetPreferred(aCharset2, name2);
|
||||
if(NS_SUCCEEDED(res)) {
|
||||
*oResult = (name1.EqualsIgnoreCase(name2)) ? PR_TRUE : PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::Equals(const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* oResult)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias2::Equals(const char* aCharset1, const char* aCharset2, PRBool* oResult)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//==============================================================
|
||||
class nsCharsetAlias : public nsICharsetAlias
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -51,6 +153,7 @@ protected:
|
||||
const nsString& GetPreferred(const nsString& aAlias) const ;
|
||||
|
||||
private:
|
||||
|
||||
// XXX Hack
|
||||
nsString iso88591;
|
||||
nsString iso88592;
|
||||
@ -78,11 +181,12 @@ private:
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsCharsetAlias, kICharsetAliasIID);
|
||||
|
||||
//--------------------------------------------------------------
|
||||
nsCharsetAlias::nsCharsetAlias()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_AtomicIncrement(&g_InstanceCount);
|
||||
|
||||
|
||||
// XXX Hack
|
||||
iso88591 = "ISO-8859-1";
|
||||
iso88592 = "ISO-8859-2";
|
||||
@ -107,11 +211,13 @@ nsCharsetAlias::nsCharsetAlias()
|
||||
unknown = "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
nsCharsetAlias::~nsCharsetAlias()
|
||||
{
|
||||
PR_AtomicDecrement(&g_InstanceCount);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
const nsString& nsCharsetAlias::GetPreferred(
|
||||
const nsString& aAlias) const
|
||||
{
|
||||
@ -250,19 +356,21 @@ const nsString& nsCharsetAlias::GetPreferred(
|
||||
return windows1254;
|
||||
}
|
||||
|
||||
|
||||
return unknown;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias::GetPreferred(
|
||||
const nsString& aAlias, nsString& oResult)
|
||||
{
|
||||
oResult = GetPreferred(aAlias);
|
||||
|
||||
if(oResult.Equals(""))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias::GetPreferred(
|
||||
const PRUnichar* aAlias, const PRUnichar** oResult)
|
||||
{
|
||||
@ -276,6 +384,7 @@ NS_IMETHODIMP nsCharsetAlias::GetPreferred(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias::GetPreferred(
|
||||
const char* aAlias, char* oResult, PRInt32 aBufLength)
|
||||
{
|
||||
@ -289,6 +398,7 @@ NS_IMETHODIMP nsCharsetAlias::GetPreferred(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsCharsetAlias::Equals(
|
||||
const nsString& aCharset1, const nsString& aCharset2)
|
||||
{
|
||||
@ -304,6 +414,7 @@ PRBool nsCharsetAlias::Equals(
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
const nsString& aCharset1, const nsString& aCharset2, PRBool* oResult)
|
||||
{
|
||||
@ -312,6 +423,7 @@ NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
const PRUnichar* aCharset1, const PRUnichar* aCharset2, PRBool* oResult)
|
||||
{
|
||||
@ -319,6 +431,7 @@ NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
*oResult = ret;
|
||||
return NS_OK;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
|
||||
NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
const char* aCharset1, const char* aCharset2, PRBool* oResult)
|
||||
@ -328,6 +441,9 @@ NS_IMETHODIMP nsCharsetAlias::Equals(
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==============================================================
|
||||
class nsCharsetAliasFactory : public nsIFactory {
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
@ -345,6 +461,7 @@ public:
|
||||
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------
|
||||
NS_DEFINE_IID( kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS( nsCharsetAliasFactory , kIFactoryIID);
|
||||
|
||||
@ -357,7 +474,10 @@ NS_IMETHODIMP nsCharsetAliasFactory::CreateInstance(
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = new nsCharsetAlias();
|
||||
|
||||
|
||||
if(NULL == inst) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -368,6 +488,7 @@ NS_IMETHODIMP nsCharsetAliasFactory::CreateInstance(
|
||||
|
||||
return res;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
NS_IMETHODIMP nsCharsetAliasFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
if(aLock)
|
||||
@ -377,6 +498,7 @@ NS_IMETHODIMP nsCharsetAliasFactory::LockFactory(PRBool aLock)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
nsIFactory* NEW_CHARSETALIASFACTORY()
|
||||
{
|
||||
return new nsCharsetAliasFactory();
|
||||
|
Loading…
Reference in New Issue
Block a user