Surfaced enumeration service added in PersistentProperties.

This commit is contained in:
sgehani%netscape.com 1999-06-11 02:22:34 +00:00
Родитель 16015f845b
Коммит a0be8f890b
3 изменённых файлов: 60 добавлений и 0 удалений

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsILocale.h"
#include "nsIURL.h"
#include "nsString.h"
#include "nsIEnumerator.h"
// {D85A17C0-AA7C-11d2-9B8C-00805F8A16D9}
#define NS_ISTRINGBUNDLESERVICE_IID \
@ -45,6 +46,7 @@ class nsIStringBundle : public nsISupports
public:
NS_IMETHOD GetStringFromID(PRInt32 aID, nsString& aResult) = 0;
NS_IMETHOD GetStringFromName(const nsString& aName, nsString& aResult) = 0;
NS_IMETHOD GetEnumeration(nsIBidirectionalEnumerator** elements) = 0;
};
class nsIStringBundleService : public nsISupports

Просмотреть файл

@ -55,6 +55,7 @@ public:
NS_IMETHOD GetStringFromID(PRInt32 aID, nsString& aResult);
NS_IMETHOD GetStringFromName(const nsString& aName, nsString& aResult);
NS_IMETHOD GetEnumeration(nsIBidirectionalEnumerator** elements);
nsIPersistentProperties* mProps;
};
@ -127,6 +128,17 @@ nsStringBundle::GetStringFromName(const nsString& aName, nsString& aResult)
return ret;
}
NS_IMETHODIMP
nsStringBundle::GetEnumeration(nsIBidirectionalEnumerator** elements)
{
if (!elements)
return NS_ERROR_INVALID_POINTER;
nsresult ret = mProps->EnumerateProperties(elements);
return ret;
}
class nsStringBundleService : public nsIStringBundleService
{
public:

Просмотреть файл

@ -121,5 +121,51 @@ main(int argc, char *argv[])
value = v.ToNewCString();
cout << "123=\"" << value << "\"" << endl;
nsIBidirectionalEnumerator* propEnum = nsnull;
ret = bundle->GetEnumeration(&propEnum);
if (NS_FAILED(ret)) {
printf("cannot get enumeration\n");
return 1;
}
ret = propEnum->First();
if (NS_FAILED(ret))
{
printf("enumerator is empty\n");
return 1;
}
cout << endl << "Key" << "\t" << "Value" << endl;
cout << "---" << "\t" << "-----" << endl;
while (NS_SUCCEEDED(ret))
{
nsIPropertyElement* propElem = nsnull;
ret = propEnum->CurrentItem((nsISupports**)&propElem);
if (NS_FAILED(ret)) {
printf("failed to get current item\n");
return 1;
}
nsString* key = nsnull;
nsString* val = nsnull;
ret = propElem->GetKey(&key);
if (NS_FAILED(ret)) {
printf("failed to get current element's key\n");
return 1;
}
ret = propElem->GetValue(&val);
if (NS_FAILED(ret)) {
printf("failed to get current element's value\n");
return 1;
}
char* keyCStr = key->ToNewCString();
char* valCStr = val->ToNewCString();
if (keyCStr && valCStr)
cout << keyCStr << "\t" << valCStr << endl;
delete[] keyCStr;
delete[] valCStr;
delete key;
delete val;
ret = propEnum->Next();
}
return 0;
}