From 509fb31739ce96ebceca8588bfe577fcc5dbb474 Mon Sep 17 00:00:00 2001 From: "tague%netscape.com" Date: Fri, 20 Aug 1999 23:57:51 +0000 Subject: [PATCH] Added nsEntityConverter components. git-svn-id: svn://10.0.0.236/trunk@43911 18797224-902f-48f8-a5cc-f745e15eee43 --- .../unicharutil/src/nsEntityConverter.cpp | 172 ++++++++++++++++++ .../intl/unicharutil/src/nsEntityConverter.h | 81 +++++++++ 2 files changed, 253 insertions(+) create mode 100644 mozilla/intl/unicharutil/src/nsEntityConverter.cpp create mode 100644 mozilla/intl/unicharutil/src/nsEntityConverter.h diff --git a/mozilla/intl/unicharutil/src/nsEntityConverter.cpp b/mozilla/intl/unicharutil/src/nsEntityConverter.cpp new file mode 100644 index 00000000000..807cc7260ab --- /dev/null +++ b/mozilla/intl/unicharutil/src/nsEntityConverter.cpp @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsEntityConverter.h" +#include "nsIProperties.h" +#include "nsIServiceManager.h" +#include "nsIComponentManager.h" +#include "nsIURL.h" +#include "nsNeckoUtil.h" + +// +// guids +// +NS_DEFINE_IID(kIEntityConverterIID,NS_IENTITYCONVERTER_IID); +NS_DEFINE_IID(kIFactoryIID,NS_IFACTORY_IID); +NS_DEFINE_IID(kIPersistentPropertiesIID,NS_IPERSISTENTPROPERTIES_IID); + +// +// implementation methods +// +nsEntityConverter::nsEntityConverter() +: mEntityList(nsnull), + mEntityListLength(0) +{ + NS_INIT_REFCNT(); + nsIPersistentProperties* pEntities = nsnull; + nsIURI* url = nsnull; + nsIInputStream* in = nsnull; + nsresult res; + nsString aUrl("resource:/res/latin1_entites.properties"); + + res = NS_NewURI(&url,aUrl,nsnull); + if (NS_FAILED(res)) return; + + res = NS_OpenURI(&in,url); + NS_RELEASE(url); + if (NS_FAILED(res)) return; + + res = nsComponentManager::CreateInstance(NS_PERSISTENTPROPERTIES_PROGID,nsnull, + kIPersistentPropertiesIID, + (void**)&pEntities); + if(NS_SUCCEEDED(res) && in) { + res = pEntities->Load(in); + LoadEntityProperties(pEntities); + pEntities->Release(); + } + + +} + +nsEntityConverter::~nsEntityConverter() +{ + +} + +void +nsEntityConverter::LoadEntityProperties(nsIPersistentProperties* pEntities) +{ + nsString key, value, temp; + PRInt32 i; + PRInt32 result; + + key="entity.list.name"; + nsresult rv = pEntities->GetProperty(key,mEntityListName); + NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n"); + if (NS_FAILED(rv)) return; + + key="entity.list.length"; + rv = pEntities->GetProperty(key,value); + NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n"); + if (NS_FAILED(rv)) return; + mEntityListLength = value.ToInteger(&result); + + // + // allocate the table + // + mEntityList = new nsEntityEntry[mEntityListLength]; + if (!mEntityList) return; + + for(i=1;i<=mEntityListLength;i++) + { + key="entity."; + key.Append(i,10); + rv = pEntities->GetProperty(key,value); + if (NS_FAILED(rv)) return; + + PRInt32 offset = value.Find(":"); + value.Left(temp,offset); + mEntityList[i-1].mChar = (PRUnichar)temp.ToInteger(&result); + + value.Mid(temp,offset+1,-1); + mEntityList[i-1].mEntityValue = temp.ToNewUnicode(); + + } + + +} +// +// nsISupports methods +// +NS_IMPL_ISUPPORTS(nsEntityConverter,kIEntityConverterIID) + + +// +// nsIEntityConverter +// +NS_IMETHODIMP +nsEntityConverter::ConvertToEntity(PRUnichar character, PRUnichar **_retval) +{ + PRInt32 i; + + for(i=0;iQueryInterface(aIID,aResult); + + *aResult=nsnull; + return NS_ERROR_OUT_OF_MEMORY; +} + +NS_IMETHODIMP +nsEntityConverterFactory::LockFactory(PRBool aLock) +{ + return NS_OK; +} \ No newline at end of file diff --git a/mozilla/intl/unicharutil/src/nsEntityConverter.h b/mozilla/intl/unicharutil/src/nsEntityConverter.h new file mode 100644 index 00000000000..a29f8ea1546 --- /dev/null +++ b/mozilla/intl/unicharutil/src/nsEntityConverter.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsIEntityConverter.h" +#include "nsIFactory.h" +#include "nsIProperties.h" + +class nsEntityEntry +{ +public: + PRUnichar mChar; + PRUnichar* mEntityValue; +}; + +class nsEntityConverter: public nsIEntityConverter +{ +public: + + // + // implementation methods + // + nsEntityConverter(); + virtual ~nsEntityConverter(); + + // + // nsISupports + // + NS_DECL_ISUPPORTS + + // + // nsIEntityConverter + // + NS_IMETHOD ConvertToEntity(PRUnichar character, PRUnichar **_retval); + +protected: + + void LoadEntityProperties(nsIPersistentProperties* entityProperties); + nsString mEntityListName; + nsEntityEntry *mEntityList; + PRInt32 mEntityListLength; + +}; + + +class nsEntityConverterFactory: public nsIFactory +{ +public: + + // + // implementation methods + // + nsEntityConverterFactory(); + virtual ~nsEntityConverterFactory(); + + // + // nsISupports methods + // + NS_DECL_ISUPPORTS + + // + // nsIFactory methods + // + NS_IMETHOD CreateInstance(nsISupports* aOuter,REFNSIID aIID,void** aResult); + NS_IMETHOD LockFactory(PRBool aLock); +}; +