From 27f47bf2aced9e736001861630cdfc5bc882aa34 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Fri, 19 Mar 1999 09:02:43 +0000 Subject: [PATCH] Added nsUnicharKey for nsHashtables. --- base/src/nsCRT.h | 31 +++++++++++++++++++++++++++++++ xpcom/ds/nsCRT.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/base/src/nsCRT.h b/base/src/nsCRT.h index 68fa0622d277..6905bcc228e7 100644 --- a/base/src/nsCRT.h +++ b/base/src/nsCRT.h @@ -193,4 +193,35 @@ public: static PRBool IsLower(PRUnichar aChar); }; +//////////////////////////////////////////////////////////////////////////////// + +#include "nsHashtable.h" + +class nsUnicharKey : public nsHashKey { +private: + PRUnichar* mStr; + +public: + nsUnicharKey(const PRUnichar* str) { + mStr = nsCRT::strdup(str); + NS_ASSERTION(mStr, "out of memory"); + } + + virtual ~nsUnicharKey(void) { + delete[] mStr; + } + + virtual PRUint32 HashValue(void) const { + return nsCRT::HashValue(mStr); + } + + virtual PRBool Equals(const nsHashKey* aKey) const { + return nsCRT::strcmp(NS_STATIC_CAST(const nsUnicharKey*, aKey)->mStr, mStr) == 0; + } + + virtual nsHashKey* Clone() const { + return new nsUnicharKey(mStr); + } +}; + #endif /* nsCRT_h___ */ diff --git a/xpcom/ds/nsCRT.h b/xpcom/ds/nsCRT.h index 68fa0622d277..6905bcc228e7 100644 --- a/xpcom/ds/nsCRT.h +++ b/xpcom/ds/nsCRT.h @@ -193,4 +193,35 @@ public: static PRBool IsLower(PRUnichar aChar); }; +//////////////////////////////////////////////////////////////////////////////// + +#include "nsHashtable.h" + +class nsUnicharKey : public nsHashKey { +private: + PRUnichar* mStr; + +public: + nsUnicharKey(const PRUnichar* str) { + mStr = nsCRT::strdup(str); + NS_ASSERTION(mStr, "out of memory"); + } + + virtual ~nsUnicharKey(void) { + delete[] mStr; + } + + virtual PRUint32 HashValue(void) const { + return nsCRT::HashValue(mStr); + } + + virtual PRBool Equals(const nsHashKey* aKey) const { + return nsCRT::strcmp(NS_STATIC_CAST(const nsUnicharKey*, aKey)->mStr, mStr) == 0; + } + + virtual nsHashKey* Clone() const { + return new nsUnicharKey(mStr); + } +}; + #endif /* nsCRT_h___ */