Bug 1003731 - Removal of transliteration. r=hsivonen

IGNORE IDL
This commit is contained in:
Andy Pusch 2015-04-22 00:21:00 -04:00
parent 26812005c3
commit d0bfe27324
12 changed files with 119 additions and 3230 deletions

View File

@ -1,52 +0,0 @@
/* Tests conversion of unrepresented characters that should be transliterated
* to spaces (bug 365345), and some others from transliterate.properties while
* I'm here
*/
const inSpace = "Hello Space";
const inEnSpace = "Hello\u2002EnSpace";
const inEmSpace = "Hello\u2003EmSpace";
const inEuro = "Hello\u20ACEuro";
const inTamil1000 = "Hello\u0BF2Tamil1000";
const inMonospace9 = "Hello\ud835\udfffMonospace9";
const expectedSpace = "Hello Space";
const expectedEnSpace = "Hello EnSpace";
const expectedEmSpace = "Hello EmSpace";
const expectedEuro = "HelloEUREuro";
const expectedTamil1000 = "Hello[1000]Tamil1000";
const expectedMonospace9 = "Hello9Monospace9";
const EntityAfterCharsetConv = 512;
const transliterate = 8;
const charset = "ISO-8859-2";
function run_test() {
var SaveAsCharset =
Components.Constructor("@mozilla.org/intl/saveascharset;1",
"nsISaveAsCharset",
"Init");
var converter = new SaveAsCharset(charset,
EntityAfterCharsetConv,
transliterate);
var outSpace = converter.Convert(inSpace);
do_check_eq(outSpace, expectedSpace);
var outEnSpace = converter.Convert(inEnSpace);
do_check_eq(outEnSpace, expectedEnSpace);
var outEmSpace = converter.Convert(inEmSpace);
do_check_eq(outEmSpace, expectedEmSpace);
var outEuro = converter.Convert(inEuro);
do_check_eq(outEuro, expectedEuro);
var outTamil1000 = converter.Convert(inTamil1000);
do_check_eq(outTamil1000, expectedTamil1000);
var outMonospace9 = converter.Convert(inMonospace9);
do_check_eq(outMonospace9, expectedMonospace9);
}

View File

@ -14,7 +14,6 @@ support-files =
[test_bug317216.js]
[test_bug321379.js]
[test_bug340714.js]
[test_bug365345.js]
[test_bug381412.Big5-HKSCS.js]
[test_bug381412.Big5.js]
[test_bug381412.euc-kr.js]

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -13,137 +13,75 @@
//
// implementation methods
//
nsEntityConverter::nsEntityConverter() :
mVersionList(nullptr),
mVersionListLength(0)
{
}
nsEntityConverter::nsEntityConverter() { }
nsEntityConverter::~nsEntityConverter()
{
if (mVersionList)
delete [] mVersionList;
}
NS_IMETHODIMP
nsEntityConverter::LoadVersionPropertyFile()
{
NS_NAMED_LITERAL_CSTRING(url, "resource://gre/res/entityTables/htmlEntityVersions.properties");
nsCOMPtr<nsIStringBundleService> bundleService =
mozilla::services::GetStringBundleService();
if (!bundleService)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIStringBundle> entities;
nsresult rv = bundleService->CreateBundle(url.get(), getter_AddRefs(entities));
if (NS_FAILED(rv)) return rv;
nsresult result;
nsAutoString key;
nsXPIDLString value;
rv = entities->GetStringFromName(MOZ_UTF16("length"),
getter_Copies(value));
NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n");
if (NS_FAILED(rv)) return rv;
mVersionListLength = nsAutoString(value).ToInteger(&result);
NS_ASSERTION(32 >= mVersionListLength,"nsEntityConverter: malformed entity table\n");
if (32 < mVersionListLength) return NS_ERROR_FAILURE;
mVersionList = new nsEntityVersionList[mVersionListLength];
if (!mVersionList) return NS_ERROR_OUT_OF_MEMORY;
for (uint32_t i = 0; i < mVersionListLength && NS_SUCCEEDED(rv); i++) {
key.SetLength(0);
key.AppendInt(i+1, 10);
rv = entities->GetStringFromName(key.get(), getter_Copies(value));
uint32_t len = value.Length();
if (kVERSION_STRING_LEN < len) return NS_ERROR_UNEXPECTED;
memcpy(mVersionList[i].mEntityListName, value.get(), len*sizeof(char16_t));
mVersionList[i].mEntityListName[len] = 0;
mVersionList[i].mVersion = (1 << i);
}
return NS_OK;
}
already_AddRefed<nsIStringBundle>
nsEntityConverter::LoadEntityBundle(uint32_t version)
{
nsAutoCString url(NS_LITERAL_CSTRING("resource://gre/res/entityTables/"));
nsresult rv;
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, nullptr);
const char16_t *versionName = GetVersionName(version);
NS_ENSURE_TRUE(versionName, nullptr);
// all property file names are ASCII, like "html40Latin1" so this is safe
LossyAppendUTF16toASCII(versionName, url);
url.AppendLiteral(".properties");
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(url.get(), getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, nullptr);
return bundle.forget();
}
const char16_t*
nsEntityConverter:: GetVersionName(uint32_t versionNumber)
{
for (uint32_t i = 0; i < mVersionListLength; i++) {
if (versionNumber == mVersionList[i].mVersion)
return mVersionList[i].mEntityListName;
}
return nullptr;
}
nsEntityConverter::~nsEntityConverter() { }
nsIStringBundle*
nsEntityConverter:: GetVersionBundleInstance(uint32_t versionNumber)
{
if (!mVersionList) {
// load the property file which contains available version names
// and generate a list of version/name pair
if (NS_FAILED(LoadVersionPropertyFile()))
return nullptr;
}
uint32_t i;
for (i = 0; i < mVersionListLength; i++) {
if (versionNumber == mVersionList[i].mVersion) {
if (!mVersionList[i].mEntities)
{ // not loaded
// load the property file
mVersionList[i].mEntities = LoadEntityBundle(versionNumber);
NS_ASSERTION(mVersionList[i].mEntities, "LoadEntityBundle failed");
}
return mVersionList[i].mEntities.get();
switch(versionNumber){
case nsIEntityConverter::html40Latin1:
if (!mHTML40Latin1Bundle) {
mHTML40Latin1Bundle = LoadEntityBundle(kHTML40LATIN1);
MOZ_ASSERT(mHTML40Latin1Bundle, "LoadEntityBundle failed");
}
return mHTML40Latin1Bundle;
case nsIEntityConverter::html40Symbols:
if (!mHTML40SymbolsBundle) {
mHTML40SymbolsBundle = LoadEntityBundle(kHTML40SYMBOLS);
MOZ_ASSERT(mHTML40SymbolsBundle, "LoadEntityBundle failed");
}
return mHTML40SymbolsBundle;
case nsIEntityConverter::html40Special:
if (!mHTML40SpecialBundle) {
mHTML40SpecialBundle = LoadEntityBundle(kHTML40SPECIAL);
MOZ_ASSERT(mHTML40SpecialBundle, "LoadEntityBundle failed");
}
return mHTML40SpecialBundle;
case nsIEntityConverter::mathml20:
if (!mMathML20Bundle) {
mMathML20Bundle = LoadEntityBundle(kMATHML20);
MOZ_ASSERT(mMathML20Bundle, "LoadEntityBundle failed");
}
return mMathML20Bundle;
default:
return nullptr;
}
return nullptr;
}
already_AddRefed<nsIStringBundle>
nsEntityConverter:: LoadEntityBundle(const char *fileName)
{
NS_ENSURE_TRUE(fileName, nullptr);
nsAutoCString url("resource://gre/res/entityTables/");
nsresult rv;
nsCOMPtr<nsIStringBundleService> bundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, nullptr);
url.Append(fileName);
nsCOMPtr<nsIStringBundle> bundle;
rv = bundleService->CreateBundle(url.get(), getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, nullptr);
return bundle.forget();
}
//
// nsISupports methods
//
NS_IMPL_ISUPPORTS(nsEntityConverter,nsIEntityConverter)
//
// nsIEntityConverter
//
NS_IMETHODIMP
nsEntityConverter::ConvertToEntity(char16_t character, uint32_t entityVersion, char **_retval)
{
{
return ConvertUTF32ToEntity((uint32_t)character, entityVersion, _retval);
}
@ -151,18 +89,22 @@ NS_IMETHODIMP
nsEntityConverter::ConvertUTF32ToEntity(uint32_t character, uint32_t entityVersion, char **_retval)
{
NS_ASSERTION(_retval, "null ptr- _retval");
if(nullptr == _retval)
if (nullptr == _retval) {
return NS_ERROR_NULL_POINTER;
}
*_retval = nullptr;
for (uint32_t mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
if (0 == (entityVersion & mask))
if (0 == (entityVersion & mask)) {
continue;
nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
NS_ASSERTION(entities, "Cannot get the property file");
}
if (!entities)
nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
NS_ASSERTION(entities, "Cannot get the entity");
if (!entities) {
continue;
}
nsAutoString key(NS_LITERAL_STRING("entity."));
key.AppendInt(character,10);
@ -171,13 +113,10 @@ nsEntityConverter::ConvertUTF32ToEntity(uint32_t character, uint32_t entityVersi
nsresult rv = entities->GetStringFromName(key.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
*_retval = ToNewCString(value);
if(nullptr == *_retval)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
return NS_OK;
}
}
return NS_ERROR_ILLEGAL_VALUE;
return NS_ERROR_ILLEGAL_VALUE;
}
NS_IMETHODIMP
@ -194,30 +133,28 @@ nsEntityConverter::ConvertToEntities(const char16_t *inString, uint32_t entityVe
uint32_t len = NS_strlen(inString);
for (uint32_t i = 0; i < len; i++) {
nsAutoString key(NS_LITERAL_STRING("entity."));
if (NS_IS_HIGH_SURROGATE(inString[i]) &&
i + 2 < len &&
NS_IS_LOW_SURROGATE(inString[i + 1])) {
if (NS_IS_HIGH_SURROGATE(inString[i]) && i + 2 < len && NS_IS_LOW_SURROGATE(inString[i + 1])) {
key.AppendInt(SURROGATE_TO_UCS4(inString[i], inString[i+1]), 10);
++i;
}
else {
} else {
key.AppendInt(inString[i],10);
}
nsXPIDLString value;
const char16_t *entity = nullptr;
for (uint32_t mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
if (0 == (entityVersion & mask))
continue;
if (0 == (entityVersion & mask)) {
continue;
}
nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
NS_ASSERTION(entities, "Cannot get the property file");
if (!entities)
continue;
if (!entities) {
continue;
}
nsresult rv = entities->GetStringFromName(key.get(),
getter_Copies(value));
nsresult rv = entities->GetStringFromName(key.get(), getter_Copies(value));
if (NS_SUCCEEDED(rv)) {
entity = value.get();
break;
@ -225,15 +162,12 @@ nsEntityConverter::ConvertToEntities(const char16_t *inString, uint32_t entityVe
}
if (entity) {
outString.Append(entity);
}
else {
} else {
outString.Append(&inString[i], 1);
}
}
*_retval = ToNewUnicode(outString);
if (!*_retval)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}

View File

@ -10,59 +10,40 @@
#include "nsIStringBundle.h"
#include "nsCOMPtr.h"
#define kVERSION_STRING_LEN 128
class nsEntityVersionList
{
public:
nsEntityVersionList() {}
uint32_t mVersion;
char16_t mEntityListName[kVERSION_STRING_LEN+1];
nsCOMPtr<nsIStringBundle> mEntities;
};
class nsEntityConverter: public nsIEntityConverter
{
public:
//
// implementation methods
//
nsEntityConverter();
//
// implementation methods
//
nsEntityConverter();
//
// nsISupports
//
NS_DECL_ISUPPORTS
//
// nsISupports
//
NS_DECL_ISUPPORTS
//
// nsIEntityConverter
//
NS_IMETHOD ConvertUTF32ToEntity(uint32_t character, uint32_t entityVersion, char **_retval) override;
NS_IMETHOD ConvertToEntity(char16_t character, uint32_t entityVersion, char **_retval) override;
NS_IMETHOD ConvertToEntities(const char16_t *inString, uint32_t entityVersion, char16_t **_retval) override;
NS_IMETHOD ConvertUTF32ToEntity(uint32_t character, uint32_t entityVersion, char **_retval) override;
NS_IMETHOD ConvertToEntity(char16_t character, uint32_t entityVersion, char **_retval) override;
NS_IMETHOD ConvertToEntities(const char16_t *inString, uint32_t entityVersion, char16_t **_retval) override;
protected:
// map version number to a string bundle
nsIStringBundle* GetVersionBundleInstance(uint32_t versionNumber);
// load a version property file and generate a version list (number/name pair)
NS_IMETHOD LoadVersionPropertyFile();
// load a string bundle file
already_AddRefed<nsIStringBundle> LoadEntityBundle(const char *fileName);
// map version number to version string
const char16_t* GetVersionName(uint32_t versionNumber);
const char* kHTML40LATIN1 = "html40Latin1.properties";
const char* kHTML40SYMBOLS = "html40Symbols.properties";
const char* kHTML40SPECIAL = "html40Special.properties";
const char* kMATHML20 = "mathml20.properties";
nsCOMPtr<nsIStringBundle> mHTML40Latin1Bundle;
nsCOMPtr<nsIStringBundle> mHTML40SymbolsBundle;
nsCOMPtr<nsIStringBundle> mHTML40SpecialBundle;
nsCOMPtr<nsIStringBundle> mMathML20Bundle;
// map version number to a string bundle
nsIStringBundle* GetVersionBundleInstance(uint32_t versionNumber);
// load a string bundle file
already_AddRefed<nsIStringBundle> LoadEntityBundle(uint32_t version);
nsEntityVersionList *mVersionList; // array of version number/name pairs
uint32_t mVersionListLength; // number of supported versions
virtual ~nsEntityConverter();
virtual ~nsEntityConverter();
};
#endif

View File

@ -18,7 +18,7 @@ interface nsIEntityConverter : nsISupports
const unsigned long html40Latin1 = 1;
const unsigned long html40Symbols = 2;
const unsigned long html40Special = 4; // excludes &quot, &amp, &lt, &gt
const unsigned long transliterate = 8;
const unsigned long transliterate = 8; // Obsolete
const unsigned long mathml20 = 16;
const unsigned long html32 = html40Latin1;
const unsigned long html40 = html40Latin1+html40Symbols+html40Special;

View File

@ -1,18 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# LOCALIZATION NOTE: FILE
# This file associates internal names of entity lists to integers.
# Do not translate anything in this file
# list supported versions number/name pair
# length should not be greater than 32
length=5
1=html40Latin1
2=html40Symbols
3=html40Special
4=transliterate
5=mathml20

View File

@ -5,12 +5,10 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
RESOURCE_FILES.entityTables = [
'htmlEntityVersions.properties',
'html40Latin1.properties',
'html40Symbols.properties',
'html40Special.properties',
'mathml20.properties',
'transliterate.properties',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':

File diff suppressed because it is too large Load Diff

2
intl/unicharutil/tests/moz.build Normal file → Executable file
View File

@ -4,8 +4,6 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
GeckoSimplePrograms([
'NormalizationTest',
'UnicharSelfTest',

View File

@ -1,56 +0,0 @@
/* Tests transliteration of new characters in Unicode 5.1, 5.2, and 6.0
*/
const inTeluguFractions = "\u0C78\u0C79\u0C7A\u0C7B\u0C7C\u0C7D\u0C7E";
const inMalayalamNumbers = "\u0D70\u0D71\u0D72\u0D73\u0D74\u0D75";
/* MYANMAR SHAN DIGIT ONE,
SUNDANESE DIGIT TWO,
LEPCHA DIGIT THREE,
OL CHIKI DIGIT FOUR,
VAI DIGIT FIVE,
SAURASHTRA DIGIT SIX
KAYAH LI DIGIT SEVEN
CHAM DIGIT EIGHT
JAVANESE DIGIT NINE
MEETEI MAYEK DIGIT ZERO */
const inDigits = "\u1091\u1BB2\u1C43\u1C54\uA625\uA8D6\uA907\uAA58\uA9D9\uABF0";
const inRomanNumerals = "\u2185\u2186\u2187\u2188";
const inSuperSubscripts = "\u2C7C\u2C7D\u2095\u209C";
const expectedTeluguFractions = "[0][1][2][3][1][2][3]";
const expectedMalayalamNumbers = "[10][100][1000][1/4][1/2][3/4]";
const expectedDigits = "1234567890";
const expectedRomanNumerals = "[6][50][50000][100000]";
const expectedSuperSubscripts = "v(j)^(V)v(h)v(t)";
const EntityAfterCharsetConv = 512;
const transliterate = 8;
const charset = "ISO-8859-1";
function run_test() {
var SaveAsCharset =
Components.Constructor("@mozilla.org/intl/saveascharset;1",
"nsISaveAsCharset",
"Init");
var converter = new SaveAsCharset(charset,
EntityAfterCharsetConv,
transliterate);
var outTeluguFractions = converter.Convert(inTeluguFractions);
do_check_eq(outTeluguFractions, expectedTeluguFractions);
var outMalayalamNumbers = converter.Convert(inMalayalamNumbers);
do_check_eq(outMalayalamNumbers, expectedMalayalamNumbers);
var outDigits = converter.Convert(inDigits);
do_check_eq(outDigits, expectedDigits);
var outRomanNumerals = converter.Convert(inRomanNumerals);
do_check_eq(outRomanNumerals, expectedRomanNumerals);
var outSuperSubscripts = converter.Convert(inSuperSubscripts);
do_check_eq(outSuperSubscripts, expectedSuperSubscripts);
}

2
intl/unicharutil/tests/unit/xpcshell.ini Normal file → Executable file
View File

@ -2,5 +2,3 @@
head =
tail =
skip-if = toolkit == 'gonk'
[test_bug_427350_1.js]

View File

@ -69,11 +69,11 @@ nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void*
nsCOMPtr<nsISupportsString> primitive =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
if (primitive ) {
if (aDataLen % 2) {
if (aDataLen % 2) {
nsAutoArrayPtr<char> buffer(new char[aDataLen + 1]);
if (!MOZ_LIKELY(buffer))
return;
memcpy(buffer, aDataBuff, aDataLen);
buffer[aDataLen] = 0;
const char16_t* start = reinterpret_cast<const char16_t*>(buffer.get());
@ -85,7 +85,7 @@ nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void*
primitive->SetData(Substring(start, start + (aDataLen / 2)));
}
NS_ADDREF(*aPrimitive = primitive);
}
}
}
} // CreatePrimitiveForData
@ -99,7 +99,7 @@ nsPrimitiveHelpers :: CreatePrimitiveForData ( const char* aFlavor, const void*
// parameter does not reflect that.
//
void
nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive,
nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports* aPrimitive,
void** aDataBuff, uint32_t aDataLen )
{
if ( !aDataBuff )
@ -132,11 +132,11 @@ nsPrimitiveHelpers :: CreateDataFromPrimitive ( const char* aFlavor, nsISupports
//
// Given a unicode buffer (flavor text/unicode), this converts it to plain text using
// the appropriate platform charset encoding. |inUnicodeLen| is the length of the input
// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
// string, not the # of bytes in the buffer. The |outPlainTextData| is null terminated,
// but its length parameter, |outPlainTextLen|, does not reflect that.
//
nsresult
nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen,
nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, int32_t inUnicodeLen,
char** outPlainTextData, int32_t* outPlainTextLen )
{
if ( !outPlainTextData || !outPlainTextLen )
@ -160,14 +160,14 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, i
rv = converter->Init(platformCharset.get(),
nsISaveAsCharset::attr_EntityAfterCharsetConv +
nsISaveAsCharset::attr_FallbackQuestionMark,
nsIEntityConverter::transliterate);
0);
NS_ENSURE_SUCCESS(rv, rv);
rv = converter->Convert(inUnicode, outPlainTextData);
*outPlainTextLen = *outPlainTextData ? strlen(*outPlainTextData) : 0;
NS_ASSERTION ( NS_SUCCEEDED(rv), "Error converting unicode to plain text" );
return rv;
} // ConvertUnicodeToPlatformPlainText
@ -176,12 +176,12 @@ nsPrimitiveHelpers :: ConvertUnicodeToPlatformPlainText ( char16_t* inUnicode, i
// ConvertPlatformPlainTextToUnicode
//
// Given a char buffer (flavor text/plaikn), this converts it to unicode using
// the appropriate platform charset encoding. |outUnicode| is null terminated,
// the appropriate platform charset encoding. |outUnicode| is null terminated,
// but its length parameter, |outUnicodeLen|, does not reflect that. |outUnicodeLen| is
// the length of the string in characters, not bytes.
//
nsresult
nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen,
nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, int32_t inTextLen,
char16_t** outUnicode, int32_t* outUnicodeLen )
{
if ( !outUnicode || !outUnicodeLen )
@ -200,14 +200,14 @@ nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, in
rv = platformCharsetService->GetCharset(kPlatformCharsetSel_PlainTextInClipboard, platformCharset);
if (NS_FAILED(rv))
platformCharset.AssignLiteral("windows-1252");
decoder = EncodingUtils::DecoderForEncoding(platformCharset);
hasConverter = true;
}
// Estimate out length and allocate the buffer based on a worst-case estimate, then do
// the conversion.
// the conversion.
decoder->GetMaxLength(inText, inTextLen, outUnicodeLen); // |outUnicodeLen| is number of chars
if ( *outUnicodeLen ) {
*outUnicode = reinterpret_cast<char16_t*>(moz_xmalloc((*outUnicodeLen + 1) * sizeof(char16_t)));
@ -234,20 +234,20 @@ nsPrimitiveHelpers :: ConvertPlatformPlainTextToUnicode ( const char* inText, in
// NOTE: this assumes that it can use 'free' to dispose of the old buffer.
//
nsresult
nsLinebreakHelpers :: ConvertPlatformToDOMLinebreaks ( const char* inFlavor, void** ioData,
nsLinebreakHelpers :: ConvertPlatformToDOMLinebreaks ( const char* inFlavor, void** ioData,
int32_t* ioLengthInBytes )
{
NS_ASSERTION ( ioData && *ioData && ioLengthInBytes, "Bad Params");
if ( !(ioData && *ioData && ioLengthInBytes) )
return NS_ERROR_INVALID_ARG;
nsresult retVal = NS_OK;
if ( strcmp(inFlavor, "text/plain") == 0 ) {
char* buffAsChars = reinterpret_cast<char*>(*ioData);
char* oldBuffer = buffAsChars;
retVal = nsLinebreakConverter::ConvertLineBreaksInSitu ( &buffAsChars, nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakContent,
retVal = nsLinebreakConverter::ConvertLineBreaksInSitu ( &buffAsChars, nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakContent,
*ioLengthInBytes, ioLengthInBytes );
if ( NS_SUCCEEDED(retVal) ) {
if ( buffAsChars != oldBuffer ) // check if buffer was reallocated
@ -258,12 +258,12 @@ nsLinebreakHelpers :: ConvertPlatformToDOMLinebreaks ( const char* inFlavor, voi
else if ( strcmp(inFlavor, "image/jpeg") == 0 ) {
// I'd assume we don't want to do anything for binary data....
}
else {
else {
char16_t* buffAsUnichar = reinterpret_cast<char16_t*>(*ioData);
char16_t* oldBuffer = buffAsUnichar;
int32_t newLengthInChars;
retVal = nsLinebreakConverter::ConvertUnicharLineBreaksInSitu ( &buffAsUnichar, nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakContent,
retVal = nsLinebreakConverter::ConvertUnicharLineBreaksInSitu ( &buffAsUnichar, nsLinebreakConverter::eLinebreakAny,
nsLinebreakConverter::eLinebreakContent,
*ioLengthInBytes / sizeof(char16_t), &newLengthInChars );
if ( NS_SUCCEEDED(retVal) ) {
if ( buffAsUnichar != oldBuffer ) // check if buffer was reallocated
@ -272,7 +272,7 @@ nsLinebreakHelpers :: ConvertPlatformToDOMLinebreaks ( const char* inFlavor, voi
*ioLengthInBytes = newLengthInChars * sizeof(char16_t);
}
}
return retVal;
} // ConvertPlatformToDOMLinebreaks