From 2e98926edaf55076552e7d4e65eade03d7cdfbea Mon Sep 17 00:00:00 2001 From: "tomk%mitre.org" Date: Thu, 30 Mar 2000 20:47:34 +0000 Subject: [PATCH] Changed toChar to toCharArray in String and MozillaString. Also provided is a version of the function which creates its own char* buffer. These classes are part of TransforMIIX and are not part of the automatic build process for the rest of Mozilla. git-svn-id: svn://10.0.0.236/trunk@64616 18797224-902f-48f8-a5cc-f745e15eee43 --- .../transformiix/source/base/MozillaString.cpp | 15 +++++++++++++-- .../transformiix/source/base/MozillaString.h | 5 ++++- .../transformiix/source/base/String.cpp | 16 +++++++++++++++- .../extensions/transformiix/source/base/String.h | 9 ++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/mozilla/extensions/transformiix/source/base/MozillaString.cpp b/mozilla/extensions/transformiix/source/base/MozillaString.cpp index bd8ccb5b1dd..d5bf3d4b1dc 100644 --- a/mozilla/extensions/transformiix/source/base/MozillaString.cpp +++ b/mozilla/extensions/transformiix/source/base/MozillaString.cpp @@ -616,6 +616,17 @@ String& MozillaString::subString(Int32 start, Int32 end, String& dest) const return dest; } +/** + * Instantiate a new character buffer (remembering the null terminator) and pass + * it to toChar(char*). +**/ +char* MozillaString::toCharArray() const +{ + char* tmpBuffer = new char[ptrNSString->Length()+1]; + + return toCharArray(tmpBuffer); +} + /** * Convert the internally represented string to a character buffer. Store * the resultant character array in the buffer provided by the caller. A @@ -624,14 +635,14 @@ String& MozillaString::subString(Int32 start, Int32 end, String& dest) const * Use ( nsString::GetUnicode() ) to retreive the nsString's buffer, then * copy it to dest. **/ -char* MozillaString::toChar(char* dest) const +char* MozillaString::toCharArray(char* dest) const { Int32 copyLoop; Int32 strLength = ptrNSString->Length(); const char* strBuffer = ptrNSString->GetBuffer(); for (copyLoop=0;copyLoop #include @@ -1036,13 +1039,24 @@ String& String::subString(Int32 start, Int32 end, String& dest) const return dest; } +/** + * Instantiate a new character buffer (remembering the null terminator) and pass + * it to toChar(char*). +**/ +char* String::toCharArray() const +{ + char* tmpBuffer = new char[strLength+1]; + + return toCharArray(tmpBuffer); +} + /** * Convert the internally represented string to a character buffer. Store * the resultant character array in the buffer provided by the caller. A * null terminator will be placed at the end of the array, make sure * space has been provided. **/ -char* String::toChar(char* dest) const +char* String::toCharArray(char* dest) const { Int32 copyLoop; diff --git a/mozilla/extensions/transformiix/source/base/String.h b/mozilla/extensions/transformiix/source/base/String.h index 1dbe8976cc0..dcbf84107ca 100644 --- a/mozilla/extensions/transformiix/source/base/String.h +++ b/mozilla/extensions/transformiix/source/base/String.h @@ -104,6 +104,12 @@ // length of the null terminated UNICODE_CHAR array. // TK 12/22/1999 Enhanced Trim() to to remove additional "white space" // characters (added \n, \t, and \r). +// +// TK 02/14/2000 Added a constructon which accepts a UNICODE_CHAR* array, and +// its associated length. +// +// TK 03/30/2000 Changed toChar to toCharArray and provided an overloaded +// version which will instantiate its own character buffer. #ifndef MITRE_STRING #define MITRE_STRING @@ -231,7 +237,8 @@ class String : public MITREObject virtual String& subString(Int32 start, Int32 end, String& dest) const; //Convert the internal rep. to a char buffer - virtual char* toChar(char* dest) const; + virtual char* toCharArray() const; + virtual char* toCharArray(char* dest) const; virtual UNICODE_CHAR* toUnicode(UNICODE_CHAR* dest) const; virtual const UNICODE_CHAR* toUnicode() const;