From 1af7f64344093f19eaeca5483d3d469c6fc748bb Mon Sep 17 00:00:00 2001 From: "sman%netscape.com" Date: Fri, 11 Sep 1998 23:44:36 +0000 Subject: [PATCH] fixes to x400 parsing --- calendar/modules/util/inc/nsX400Parser.h | 13 +++++++++ calendar/modules/util/src/nsX400Parser.cpp | 34 +++++++++++++++++----- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/calendar/modules/util/inc/nsX400Parser.h b/calendar/modules/util/inc/nsX400Parser.h index 90e2101e444..4b8896300c6 100644 --- a/calendar/modules/util/inc/nsX400Parser.h +++ b/calendar/modules/util/inc/nsX400Parser.h @@ -95,6 +95,12 @@ private: */ nsresult DestroyEntry(PRInt32 aIndex); + /** + * Destroy all key/value pairs + * @return NS_OK on success + */ + nsresult DestroyAllEntries(); + /** * @return the current number of key/value pairs. */ @@ -126,6 +132,13 @@ public: */ nsresult GetValue(char** aStr); + /** + * Get the newly assembled string + * @param aStr reference to the string object. + * @return NS_OK on success + */ + nsresult GetValue(JulianString& aStr); + /** * Set the supplied key to have the supplied value. Add the key * and value pair if they do not yet exist. Update the value diff --git a/calendar/modules/util/src/nsX400Parser.cpp b/calendar/modules/util/src/nsX400Parser.cpp index 20b8ad1a4ad..82de915ece3 100644 --- a/calendar/modules/util/src/nsX400Parser.cpp +++ b/calendar/modules/util/src/nsX400Parser.cpp @@ -64,10 +64,14 @@ nsX400Parser::nsX400Parser(const char* psValue) nsX400Parser::~nsX400Parser() { + DestroyAllEntries(); + if (mppKeys) + { + delete [] mppKeys; + } + if (mppVals) delete [] mppVals; - if (mppKeys) - delete [] mppKeys; } nsresult nsX400Parser::Init() @@ -92,6 +96,13 @@ nsresult nsX400Parser::GetValue(char** aStr) return NS_OK; } +nsresult nsX400Parser::GetValue(JulianString& aStr) +{ + Assemble(); + aStr = msValue; + return NS_OK; +} + nsresult nsX400Parser::EnsureSize(PRInt32 aSize) { if (aSize > miSize) @@ -239,6 +250,19 @@ nsresult nsX400Parser::DestroyEntry(PRInt32 i) return NS_OK; } +nsresult nsX400Parser::DestroyAllEntries() +{ + /* + * delete anything in the old arrays... + */ + if (0 != mppKeys && 0 != mppVals) + { + for (size_t i = 0; i < (size_t)miLength; i++) + DestroyEntry((PRInt32)i); + } + return NS_OK; +} + /** * Delete an entry. */ @@ -302,11 +326,7 @@ nsresult nsX400Parser::Parse() /* * delete anything in the old arrays... */ - if (0 != mppKeys) - { - for (i = 0; i < (size_t)miLength; i++) - DestroyEntry((PRInt32)i); - } + DestroyAllEntries(); /* * Parse off parts until done...