still not part of the build; I think everything's there, though. Some further testing and I'll add it to the build

git-svn-id: svn://10.0.0.236/trunk@75625 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scc%mozilla.org
2000-08-05 02:13:59 +00:00
parent 574ca98f39
commit ac22cf0d43
3 changed files with 93 additions and 3 deletions

View File

@@ -50,15 +50,44 @@ ToNewUnicode( const nsAReadableString& aSourceString )
}
template <class FromT, class ToT>
class LossyConversionSink
{
public:
typedef FromT input_type;
typedef ToT output_type;
public:
LossyConversionSink( output_type* aDestination ) : mDestination(aDestination) { }
PRUint32
write( const input_type* aSource, PRUint32 aSourceLength )
{
const input_type* done_writing = aSource + aSourceLength;
while ( aSource < done_writing )
*mDestination++ = NS_STATIC_CAST(output_type, *aSource++);
}
private:
OutputCharT* mDestination;
};
char*
ToNewCString( const nsAReadableString& aSourceString )
{
char* result = NS_STATIC_CAST(char*, nsMemory::Alloc(aSourceString.Length()+1));
*copy_string(aSourceString.BeginReading(), aSourceString.EndReading(), LossyConversionSink<PRUnichar, char>(result)) = char(0);
return result;
}
PRUnichar*
ToNewUnicode( const nsAReadableCString& aSourceCString )
{
PRUnichar* result = NS_STATIC_CAST(char*, nsMemory::Alloc( (aSourceString.Length()+1) * sizeof(PRUnichar) ));
*copy_string(aSourceCString.BeginReading(), aSourceCString.EndReading(), LossyConversionSink<char, PRUnichar>(result)) = PRUnichar(0);
return result;
}
@@ -90,4 +119,5 @@ IsASCII( const nsAReadableString& aSourceString )
}
return PR_TRUE;
}
}