DOM string changes. All nsString& in DOM interfaces (and interfaces needed by DOM implementations) have been changed to nsAReadableString& and nsAWritableString&. String implementation additions (sanctioned by scc) to support DOM needs. Bug 49091. r=vidur,jst,scc
git-svn-id: svn://10.0.0.236/trunk@76967 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsString.h"
|
||||
|
||||
|
||||
|
||||
@@ -65,6 +66,24 @@ class LossyConvertEncoding
|
||||
};
|
||||
|
||||
|
||||
NS_COM
|
||||
void
|
||||
CopyUCS2toASCII( const nsAReadableString& aSource, nsAWritableCString& aDest )
|
||||
{
|
||||
// right now, this won't work on multi-fragment destinations
|
||||
aDest.SetLength(aSource.Length());
|
||||
copy_string(aSource.BeginReading(), aSource.EndReading(), LossyConvertEncoding<PRUnichar, char>(aDest.BeginWriting().get()));
|
||||
}
|
||||
|
||||
NS_COM
|
||||
void
|
||||
CopyASCIItoUCS2( const nsAReadableCString& aSource, nsAWritableString& aDest )
|
||||
{
|
||||
// right now, this won't work on multi-fragment destinations
|
||||
aDest.SetLength(aSource.Length());
|
||||
copy_string(aSource.BeginReading(), aSource.EndReading(), LossyConvertEncoding<char, PRUnichar>(aDest.BeginWriting().get()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A helper function that allocates a buffer of the desired character type big enough to hold a copy of the supplied string (plus a zero terminator).
|
||||
@@ -91,6 +110,30 @@ ToNewCString( const nsAReadableString& aSource )
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_COM
|
||||
char*
|
||||
ToNewUTF8String( const nsAReadableString& aSource )
|
||||
{
|
||||
NS_ConvertUCS2toUTF8 temp(aSource);
|
||||
|
||||
char* result;
|
||||
if (temp.mOwnsBuffer) {
|
||||
// We allocated. Trick the string into not freeing its buffer to
|
||||
// avoid an extra allocation.
|
||||
result = temp.mStr;
|
||||
|
||||
temp.mStr=0;
|
||||
temp.mOwnsBuffer = PR_FALSE;
|
||||
}
|
||||
else {
|
||||
// We didn't allocate a buffer, so we need to copy it out of the
|
||||
// nsCAutoString's storage.
|
||||
result = nsCRT::strdup(temp.mStr);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_COM
|
||||
char*
|
||||
ToNewCString( const nsAReadableCString& aSource )
|
||||
@@ -122,6 +165,21 @@ ToNewUnicode( const nsAReadableCString& aSource )
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_COM
|
||||
PRUnichar*
|
||||
CopyUnicodeTo( const nsAReadableString& aSource,
|
||||
PRUnichar* aDest,
|
||||
PRUint32 aLength )
|
||||
{
|
||||
typedef nsAReadableString::const_iterator iterator;
|
||||
|
||||
iterator done_reading = aSource.BeginReading();
|
||||
done_reading += aLength;
|
||||
|
||||
copy_string(aSource.BeginReading(), done_reading, aDest);
|
||||
return aDest;
|
||||
}
|
||||
|
||||
NS_COM
|
||||
PRBool
|
||||
IsASCII( const nsAReadableString& aString )
|
||||
|
||||
Reference in New Issue
Block a user