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
This commit is contained in:
tomk%mitre.org
2000-03-30 20:47:34 +00:00
parent e8097c0551
commit 2e98926eda
4 changed files with 40 additions and 5 deletions

View File

@@ -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<strLength;copyLoop++)
dest[copyLoop] = strBuffer[copyLoop];
dest[copyLoop] = strBuffer[copyLoop];
//Place a NULL terminator at the end of the character buffer
dest[copyLoop] = 0;

View File

@@ -33,6 +33,8 @@
// Also provided a means to obtain a const reference to the
// nsString object to support const object/references.
//
// TK 03/30/2000 Changed toChar to toCharArray and provided an overloaded
// version which will instantiate its own character buffer.
#include "String.h"
#include "MITREObject.h"
@@ -182,7 +184,8 @@ class MozillaString : public String
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;

View File

@@ -105,6 +105,9 @@
// TK 03/10/2000 Fixed a bug found by Bobbi Guarino where
// String::indexOf(const String& string...) was not RETURNing
// a value.
//
// TK 03/30/2000 Changed toChar to toCharArray and provided an overloaded
// version which will instantiate its own character buffer.
#include <stdlib.h>
#include <string.h>
@@ -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;

View File

@@ -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;