mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 801402 - Make EncodingUtil methods case sensitive. r=hsivonen
This commit is contained in:
parent
399d375b70
commit
af1bfecedb
@ -129,7 +129,6 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
|
|||||||
#include "nsISVGChildFrame.h"
|
#include "nsISVGChildFrame.h"
|
||||||
#include "nsRenderingContext.h"
|
#include "nsRenderingContext.h"
|
||||||
#include "gfxSVGGlyphs.h"
|
#include "gfxSVGGlyphs.h"
|
||||||
#include "mozilla/dom/EncodingUtils.h"
|
|
||||||
|
|
||||||
#ifdef IBMBIDI
|
#ifdef IBMBIDI
|
||||||
#include "nsIBidiKeyboard.h"
|
#include "nsIBidiKeyboard.h"
|
||||||
@ -1529,8 +1528,7 @@ nsContentUtils::Shutdown()
|
|||||||
sModifierSeparator = nullptr;
|
sModifierSeparator = nullptr;
|
||||||
|
|
||||||
NS_IF_RELEASE(sSameOriginChecker);
|
NS_IF_RELEASE(sSameOriginChecker);
|
||||||
|
|
||||||
EncodingUtils::Shutdown();
|
|
||||||
nsTextEditorState::ShutDown();
|
nsTextEditorState::ShutDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,279 +3,22 @@
|
|||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "mozilla/dom/EncodingUtils.h"
|
#include "mozilla/dom/EncodingUtils.h"
|
||||||
#include "nsAutoPtr.h"
|
#include "nsUConvPropertySearch.h"
|
||||||
#include "nsContentUtils.h"
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
EncodingUtils* gEncodings = nullptr;
|
static const char* labelsEncodings[][3] = {
|
||||||
|
#include "labelsencodings.properties.h"
|
||||||
struct LabelEncoding
|
|
||||||
{
|
|
||||||
const char* mLabel;
|
|
||||||
const char* mEncoding;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const LabelEncoding labelsEncodings[] = {
|
|
||||||
{"unicode-1-1-utf-8", "utf-8"},
|
|
||||||
{"utf-8", "utf-8"},
|
|
||||||
{"utf8", "utf-8"},
|
|
||||||
{"866", "ibm866"},
|
|
||||||
{"cp866", "ibm866"},
|
|
||||||
{"csibm866", "ibm866"},
|
|
||||||
{"ibm866", "ibm866"},
|
|
||||||
{"csisolatin2", "iso-8859-2"},
|
|
||||||
{"iso-8859-2", "iso-8859-2"},
|
|
||||||
{"iso-ir-101", "iso-8859-2"},
|
|
||||||
{"iso8859-2", "iso-8859-2"},
|
|
||||||
{"iso88592", "iso-8859-2"},
|
|
||||||
{"iso_8859-2", "iso-8859-2"},
|
|
||||||
{"iso_8859-2:1987", "iso-8859-2"},
|
|
||||||
{"l2", "iso-8859-2"},
|
|
||||||
{"latin2", "iso-8859-2"},
|
|
||||||
{"csisolatin3", "iso-8859-3"},
|
|
||||||
{"iso-8859-3", "iso-8859-3"},
|
|
||||||
{"iso-ir-109", "iso-8859-3"},
|
|
||||||
{"iso8859-3", "iso-8859-3"},
|
|
||||||
{"iso88593", "iso-8859-3"},
|
|
||||||
{"iso_8859-3", "iso-8859-3"},
|
|
||||||
{"iso_8859-3:1988", "iso-8859-3"},
|
|
||||||
{"l3", "iso-8859-3"},
|
|
||||||
{"latin3", "iso-8859-3"},
|
|
||||||
{"csisolatin4", "iso-8859-4"},
|
|
||||||
{"iso-8859-4", "iso-8859-4"},
|
|
||||||
{"iso-ir-110", "iso-8859-4"},
|
|
||||||
{"iso8859-4", "iso-8859-4"},
|
|
||||||
{"iso88594", "iso-8859-4"},
|
|
||||||
{"iso_8859-4", "iso-8859-4"},
|
|
||||||
{"iso_8859-4:1988", "iso-8859-4"},
|
|
||||||
{"l4", "iso-8859-4"},
|
|
||||||
{"latin4", "iso-8859-4"},
|
|
||||||
{"csisolatincyrillic", "iso-8859-5"},
|
|
||||||
{"cyrillic", "iso-8859-5"},
|
|
||||||
{"iso-8859-5", "iso-8859-5"},
|
|
||||||
{"iso-ir-144", "iso-8859-5"},
|
|
||||||
{"iso8859-5", "iso-8859-5"},
|
|
||||||
{"iso88595", "iso-8859-5"},
|
|
||||||
{"iso_8859-5", "iso-8859-5"},
|
|
||||||
{"iso_8859-5:1988", "iso-8859-5"},
|
|
||||||
{"arabic", "iso-8859-6"},
|
|
||||||
{"asmo-708", "iso-8859-6"},
|
|
||||||
{"csiso88596e", "iso-8859-6"},
|
|
||||||
{"csiso88596i", "iso-8859-6"},
|
|
||||||
{"csisolatinarabic", "iso-8859-6"},
|
|
||||||
{"ecma-114", "iso-8859-6"},
|
|
||||||
{"iso-8859-6", "iso-8859-6"},
|
|
||||||
{"iso-8859-6-e", "iso-8859-6"},
|
|
||||||
{"iso-8859-6-i", "iso-8859-6"},
|
|
||||||
{"iso-ir-127", "iso-8859-6"},
|
|
||||||
{"iso8859-6", "iso-8859-6"},
|
|
||||||
{"iso88596", "iso-8859-6"},
|
|
||||||
{"iso_8859-6", "iso-8859-6"},
|
|
||||||
{"iso_8859-6:1987", "iso-8859-6"},
|
|
||||||
{"csisolatingreek", "iso-8859-7"},
|
|
||||||
{"ecma-118", "iso-8859-7"},
|
|
||||||
{"elot_928", "iso-8859-7"},
|
|
||||||
{"greek", "iso-8859-7"},
|
|
||||||
{"greek8", "iso-8859-7"},
|
|
||||||
{"iso-8859-7", "iso-8859-7"},
|
|
||||||
{"iso-ir-126", "iso-8859-7"},
|
|
||||||
{"iso8859-7", "iso-8859-7"},
|
|
||||||
{"iso88597", "iso-8859-7"},
|
|
||||||
{"iso_8859-7", "iso-8859-7"},
|
|
||||||
{"iso_8859-7:1987", "iso-8859-7"},
|
|
||||||
{"sun_eu_greek", "iso-8859-7"},
|
|
||||||
{"csiso88598e", "iso-8859-8"},
|
|
||||||
{"csisolatinhebrew", "iso-8859-8"},
|
|
||||||
{"hebrew", "iso-8859-8"},
|
|
||||||
{"iso-8859-8", "iso-8859-8"},
|
|
||||||
{"iso-8859-8-e", "iso-8859-8"},
|
|
||||||
{"iso-ir-138", "iso-8859-8"},
|
|
||||||
{"iso8859-8", "iso-8859-8"},
|
|
||||||
{"iso88598", "iso-8859-8"},
|
|
||||||
{"iso_8859-8", "iso-8859-8"},
|
|
||||||
{"iso_8859-8:1988", "iso-8859-8"},
|
|
||||||
{"visual", "iso-8859-8"},
|
|
||||||
{"csiso88598i", "iso-8859-8-i"},
|
|
||||||
{"iso-8859-8-i", "iso-8859-8-i"},
|
|
||||||
{"logical", "iso-8859-8-i"},
|
|
||||||
{"csisolatin6", "iso-8859-10"},
|
|
||||||
{"iso-8859-10", "iso-8859-10"},
|
|
||||||
{"iso-ir-157", "iso-8859-10"},
|
|
||||||
{"iso8859-10", "iso-8859-10"},
|
|
||||||
{"iso885910", "iso-8859-10"},
|
|
||||||
{"l6", "iso-8859-10"},
|
|
||||||
{"latin6", "iso-8859-10"},
|
|
||||||
{"iso-8859-13", "iso-8859-13"},
|
|
||||||
{"iso8859-13", "iso-8859-13"},
|
|
||||||
{"iso885913", "iso-8859-13"},
|
|
||||||
{"iso-8859-14", "iso-8859-14"},
|
|
||||||
{"iso8859-14", "iso-8859-14"},
|
|
||||||
{"iso885914", "iso-8859-14"},
|
|
||||||
{"csisolatin9", "iso-8859-15"},
|
|
||||||
{"iso-8859-15", "iso-8859-15"},
|
|
||||||
{"iso8859-15", "iso-8859-15"},
|
|
||||||
{"iso885915", "iso-8859-15"},
|
|
||||||
{"iso_8859-15", "iso-8859-15"},
|
|
||||||
{"l9", "iso-8859-15"},
|
|
||||||
{"iso-8859-16", "iso-8859-16"},
|
|
||||||
{"cskoi8r", "koi8-r"},
|
|
||||||
{"koi", "koi8-r"},
|
|
||||||
{"koi8", "koi8-r"},
|
|
||||||
{"koi8-r", "koi8-r"},
|
|
||||||
{"koi8_r", "koi8-r"},
|
|
||||||
{"koi8-u", "koi8-u"},
|
|
||||||
{"csmacintosh", "macintosh"},
|
|
||||||
{"mac", "macintosh"},
|
|
||||||
{"macintosh", "macintosh"},
|
|
||||||
{"x-mac-roman", "macintosh"},
|
|
||||||
{"dos-874", "windows-874"},
|
|
||||||
{"iso-8859-11", "windows-874"},
|
|
||||||
{"iso8859-11", "windows-874"},
|
|
||||||
{"iso885911", "windows-874"},
|
|
||||||
{"tis-620", "windows-874"},
|
|
||||||
{"windows-874", "windows-874"},
|
|
||||||
{"cp1250", "windows-1250"},
|
|
||||||
{"windows-1250", "windows-1250"},
|
|
||||||
{"x-cp1250", "windows-1250"},
|
|
||||||
{"cp1251", "windows-1251"},
|
|
||||||
{"windows-1251", "windows-1251"},
|
|
||||||
{"x-cp1251", "windows-1251"},
|
|
||||||
{"ansi_x3.4-1968", "windows-1252"},
|
|
||||||
{"ascii", "windows-1252"},
|
|
||||||
{"cp1252", "windows-1252"},
|
|
||||||
{"cp819", "windows-1252"},
|
|
||||||
{"csisolatin1", "windows-1252"},
|
|
||||||
{"ibm819", "windows-1252"},
|
|
||||||
{"iso-8859-1", "windows-1252"},
|
|
||||||
{"iso-ir-100", "windows-1252"},
|
|
||||||
{"iso8859-1", "windows-1252"},
|
|
||||||
{"iso88591", "windows-1252"},
|
|
||||||
{"iso_8859-1", "windows-1252"},
|
|
||||||
{"iso_8859-1:1987", "windows-1252"},
|
|
||||||
{"l1", "windows-1252"},
|
|
||||||
{"latin1", "windows-1252"},
|
|
||||||
{"us-ascii", "windows-1252"},
|
|
||||||
{"windows-1252", "windows-1252"},
|
|
||||||
{"x-cp1252", "windows-1252"},
|
|
||||||
{"cp1253", "windows-1253"},
|
|
||||||
{"windows-1253", "windows-1253"},
|
|
||||||
{"x-cp1253", "windows-1253"},
|
|
||||||
{"cp1254", "windows-1254"},
|
|
||||||
{"csisolatin5", "windows-1254"},
|
|
||||||
{"iso-8859-9", "windows-1254"},
|
|
||||||
{"iso-ir-148", "windows-1254"},
|
|
||||||
{"iso8859-9", "windows-1254"},
|
|
||||||
{"iso88599", "windows-1254"},
|
|
||||||
{"iso_8859-9", "windows-1254"},
|
|
||||||
{"iso_8859-9:1989", "windows-1254"},
|
|
||||||
{"l5", "windows-1254"},
|
|
||||||
{"latin5", "windows-1254"},
|
|
||||||
{"windows-1254", "windows-1254"},
|
|
||||||
{"x-cp1254", "windows-1254"},
|
|
||||||
{"cp1255", "windows-1255"},
|
|
||||||
{"windows-1255", "windows-1255"},
|
|
||||||
{"x-cp1255", "windows-1255"},
|
|
||||||
{"cp1256", "windows-1256"},
|
|
||||||
{"windows-1256", "windows-1256"},
|
|
||||||
{"x-cp1256", "windows-1256"},
|
|
||||||
{"cp1257", "windows-1257"},
|
|
||||||
{"windows-1257", "windows-1257"},
|
|
||||||
{"x-cp1257", "windows-1257"},
|
|
||||||
{"cp1258", "windows-1258"},
|
|
||||||
{"windows-1258", "windows-1258"},
|
|
||||||
{"x-cp1258", "windows-1258"},
|
|
||||||
{"x-mac-cyrillic", "x-mac-cyrillic"},
|
|
||||||
{"x-mac-ukrainian", "x-mac-cyrillic"},
|
|
||||||
{"chinese", "gbk"},
|
|
||||||
{"csgb2312", "gbk"},
|
|
||||||
{"csiso58gb231280", "gbk"},
|
|
||||||
{"gb2312", "gbk"},
|
|
||||||
{"gb_2312", "gbk"},
|
|
||||||
{"gb_2312-80", "gbk"},
|
|
||||||
{"gbk", "gbk"},
|
|
||||||
{"iso-ir-58", "gbk"},
|
|
||||||
{"x-gbk", "gbk"},
|
|
||||||
{"gb18030", "gb18030"},
|
|
||||||
{"hz-gb-2312", "hz-gb-2312"},
|
|
||||||
{"big5", "big5"},
|
|
||||||
{"big5-hkscs", "big5"},
|
|
||||||
{"cn-big5", "big5"},
|
|
||||||
{"csbig5", "big5"},
|
|
||||||
{"x-x-big5", "big5"},
|
|
||||||
{"cseucpkdfmtjapanese", "euc-jp"},
|
|
||||||
{"euc-jp", "euc-jp"},
|
|
||||||
{"x-euc-jp", "euc-jp"},
|
|
||||||
{"csiso2022jp", "iso-2022-jp"},
|
|
||||||
{"iso-2022-jp", "iso-2022-jp"},
|
|
||||||
{"csshiftjis", "shift_jis"},
|
|
||||||
{"ms_kanji", "shift_jis"},
|
|
||||||
{"shift-jis", "shift_jis"},
|
|
||||||
{"shift_jis", "shift_jis"},
|
|
||||||
{"sjis", "shift_jis"},
|
|
||||||
{"windows-31j", "shift_jis"},
|
|
||||||
{"x-sjis", "shift_jis"},
|
|
||||||
{"cseuckr", "euc-kr"},
|
|
||||||
{"csksc56011987", "euc-kr"},
|
|
||||||
{"euc-kr", "euc-kr"},
|
|
||||||
{"iso-ir-149", "euc-kr"},
|
|
||||||
{"korean", "euc-kr"},
|
|
||||||
{"ks_c_5601-1987", "euc-kr"},
|
|
||||||
{"ks_c_5601-1989", "euc-kr"},
|
|
||||||
{"ksc5601", "euc-kr"},
|
|
||||||
{"ksc_5601", "euc-kr"},
|
|
||||||
{"windows-949", "euc-kr"},
|
|
||||||
{"csiso2022kr", "iso-2022-kr"},
|
|
||||||
{"iso-2022-kr", "iso-2022-kr"},
|
|
||||||
{"utf-16", "utf-16le"},
|
|
||||||
{"utf-16le", "utf-16le"},
|
|
||||||
{"utf-16be", "utf-16be"},
|
|
||||||
{"x-user-defined", "x-user-defined"},
|
|
||||||
};
|
|
||||||
|
|
||||||
EncodingUtils::EncodingUtils()
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(!gEncodings);
|
|
||||||
|
|
||||||
const uint32_t numLabels = ArrayLength(labelsEncodings);
|
|
||||||
mLabelsEncodings.Init(numLabels);
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < numLabels; i++) {
|
|
||||||
mLabelsEncodings.Put(NS_ConvertASCIItoUTF16(labelsEncodings[i].mLabel),
|
|
||||||
labelsEncodings[i].mEncoding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodingUtils::~EncodingUtils()
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(gEncodings && gEncodings == this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EncodingUtils::Shutdown()
|
|
||||||
{
|
|
||||||
NS_IF_RELEASE(gEncodings);
|
|
||||||
}
|
|
||||||
|
|
||||||
already_AddRefed<EncodingUtils>
|
|
||||||
EncodingUtils::GetOrCreate()
|
|
||||||
{
|
|
||||||
if (!gEncodings) {
|
|
||||||
gEncodings = new EncodingUtils();
|
|
||||||
NS_ADDREF(gEncodings);
|
|
||||||
}
|
|
||||||
NS_ADDREF(gEncodings);
|
|
||||||
return gEncodings;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t
|
uint32_t
|
||||||
EncodingUtils::IdentifyDataOffset(const char* aData,
|
EncodingUtils::IdentifyDataOffset(const char* aData,
|
||||||
const uint32_t aLength,
|
const uint32_t aLength,
|
||||||
const char*& aRetval)
|
nsACString& aRetval)
|
||||||
{
|
{
|
||||||
// Truncating to pre-clear return value in case of failure.
|
// Truncating to pre-clear return value in case of failure.
|
||||||
aRetval = "";
|
aRetval.Truncate();
|
||||||
|
|
||||||
// Minimum bytes in input stream data that represents
|
// Minimum bytes in input stream data that represents
|
||||||
// the Byte Order Mark is 2. Max is 3.
|
// the Byte Order Mark is 2. Max is 3.
|
||||||
@ -284,12 +27,12 @@ EncodingUtils::IdentifyDataOffset(const char* aData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (aData[0] == '\xFF' && aData[1] == '\xFE') {
|
if (aData[0] == '\xFF' && aData[1] == '\xFE') {
|
||||||
aRetval = "utf-16le";
|
aRetval.AssignLiteral("UTF-16LE");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aData[0] == '\xFE' && aData[1] == '\xFF') {
|
if (aData[0] == '\xFE' && aData[1] == '\xFF') {
|
||||||
aRetval = "utf-16be";
|
aRetval.AssignLiteral("UTF-16BE");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,36 +44,28 @@ EncodingUtils::IdentifyDataOffset(const char* aData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (aData[0] == '\xEF' && aData[1] == '\xBB' && aData[2] == '\xBF') {
|
if (aData[0] == '\xEF' && aData[1] == '\xBB' && aData[2] == '\xBF') {
|
||||||
aRetval = "utf-8";
|
aRetval.AssignLiteral("UTF-8");
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
EncodingUtils::FindEncodingForLabel(const nsAString& aLabel,
|
EncodingUtils::FindEncodingForLabel(const nsACString& aLabel,
|
||||||
const char*& aOutEncoding)
|
nsACString& aOutEncoding)
|
||||||
{
|
{
|
||||||
nsRefPtr<EncodingUtils> self = EncodingUtils::GetOrCreate();
|
// Save aLabel first because it may refer the same string as aOutEncoding.
|
||||||
MOZ_ASSERT(self);
|
nsCString label(aLabel);
|
||||||
|
|
||||||
// Save aLabel first because it may be the same as aOutEncoding.
|
|
||||||
nsString label(aLabel);
|
|
||||||
// Truncating to clear aOutEncoding in case of failure.
|
|
||||||
aOutEncoding = EmptyCString().get();
|
|
||||||
|
|
||||||
EncodingUtils::TrimSpaceCharacters(label);
|
EncodingUtils::TrimSpaceCharacters(label);
|
||||||
if (label.IsEmpty()) {
|
if (label.IsEmpty()) {
|
||||||
|
aOutEncoding.Truncate();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsContentUtils::ASCIIToLower(label);
|
ToLowerCase(label);
|
||||||
const char* encoding = self->mLabelsEncodings.Get(label);
|
return NS_SUCCEEDED(nsUConvPropertySearch::SearchPropertyValue(
|
||||||
if (!encoding) {
|
labelsEncodings, ArrayLength(labelsEncodings), label, aOutEncoding));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
aOutEncoding = encoding;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
@ -14,11 +14,12 @@ namespace dom {
|
|||||||
class EncodingUtils
|
class EncodingUtils
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_INLINE_DECL_REFCOUNTING(EncodingUtils)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements decode algorithm's step 1 & 2 from Encoding spec.
|
* Implements decode algorithm's step 1 & 2 from Encoding spec.
|
||||||
* http://encoding.spec.whatwg.org/#decode
|
* http://encoding.spec.whatwg.org/#decode
|
||||||
|
* The returned name may not be lowercased due to compatibility with
|
||||||
|
* our internal implementations.
|
||||||
*
|
*
|
||||||
* @param aData, incoming byte stream of data.
|
* @param aData, incoming byte stream of data.
|
||||||
* @param aLength, incoming byte stream length.
|
* @param aLength, incoming byte stream length.
|
||||||
@ -29,21 +30,29 @@ public:
|
|||||||
*/
|
*/
|
||||||
static uint32_t IdentifyDataOffset(const char* aData,
|
static uint32_t IdentifyDataOffset(const char* aData,
|
||||||
const uint32_t aLength,
|
const uint32_t aLength,
|
||||||
const char*& aRetval);
|
nsACString& aRetval);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements get an encoding algorithm from Encoding spec.
|
* Implements get an encoding algorithm from Encoding spec.
|
||||||
* http://encoding.spec.whatwg.org/#concept-encoding-get
|
* http://encoding.spec.whatwg.org/#concept-encoding-get
|
||||||
* Given a label, this function returns the corresponding encoding or a
|
* Given a label, this function returns the corresponding encoding or a
|
||||||
* false.
|
* false.
|
||||||
|
* The returned name may not be lowercased due to compatibility with
|
||||||
|
* our internal implementations.
|
||||||
*
|
*
|
||||||
* @param aLabel, incoming label describing charset to be decoded.
|
* @param aLabel, incoming label describing charset to be decoded.
|
||||||
* @param aRetEncoding, returning corresponding encoding for label.
|
* @param aRetEncoding, returning corresponding encoding for label.
|
||||||
* @return false if no encoding was found for label.
|
* @return false if no encoding was found for label.
|
||||||
* true if valid encoding found.
|
* true if valid encoding found.
|
||||||
*/
|
*/
|
||||||
|
static bool FindEncodingForLabel(const nsACString& aLabel,
|
||||||
|
nsACString& aOutEncoding);
|
||||||
|
|
||||||
static bool FindEncodingForLabel(const nsAString& aLabel,
|
static bool FindEncodingForLabel(const nsAString& aLabel,
|
||||||
const char*& aOutEncoding);
|
nsACString& aOutEncoding)
|
||||||
|
{
|
||||||
|
return FindEncodingForLabel(NS_ConvertUTF16toUTF8(aLabel), aOutEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove any leading and trailing space characters, following the
|
* Remove any leading and trailing space characters, following the
|
||||||
@ -55,19 +64,14 @@ public:
|
|||||||
*
|
*
|
||||||
* @param aString, string to be trimmed.
|
* @param aString, string to be trimmed.
|
||||||
*/
|
*/
|
||||||
static void TrimSpaceCharacters(nsString& aString)
|
template<class T>
|
||||||
|
static void TrimSpaceCharacters(T& aString)
|
||||||
{
|
{
|
||||||
aString.Trim(" \t\n\f\r");
|
aString.Trim(" \t\n\f\r");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called to free up Encoding instance. */
|
private:
|
||||||
static void Shutdown();
|
EncodingUtils() MOZ_DELETE;
|
||||||
|
|
||||||
protected:
|
|
||||||
nsDataHashtable<nsStringHashKey, const char *> mLabelsEncodings;
|
|
||||||
EncodingUtils();
|
|
||||||
virtual ~EncodingUtils();
|
|
||||||
static already_AddRefed<EncodingUtils> GetOrCreate();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // dom
|
} // dom
|
||||||
|
@ -33,6 +33,20 @@ CPPSRCS = \
|
|||||||
TextEncoder.cpp \
|
TextEncoder.cpp \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
LOCAL_INCLUDES = \
|
||||||
|
-I$(topsrcdir)/intl/locale/src \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
include $(topsrcdir)/dom/dom-config.mk
|
include $(topsrcdir)/dom/dom-config.mk
|
||||||
include $(topsrcdir)/config/config.mk
|
include $(topsrcdir)/config/config.mk
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
EncodingUtils.$(OBJ_SUFFIX): labelsencodings.properties.h
|
||||||
|
|
||||||
|
PROPS2ARRAYS = $(topsrcdir)/intl/locale/src/props2arrays.py
|
||||||
|
labelsencodings.properties.h: $(PROPS2ARRAYS) labelsencodings.properties
|
||||||
|
$(PYTHON) $^ $@
|
||||||
|
|
||||||
|
GARBAGE += \
|
||||||
|
charsetalias.properties.h \
|
||||||
|
$(NULL)
|
||||||
|
@ -28,8 +28,8 @@ TextDecoder::Init(const nsAString& aEncoding,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsUTF16Family = !strcmp(mEncoding, "utf-16le") ||
|
mIsUTF16Family = mEncoding.EqualsLiteral("UTF-16LE") ||
|
||||||
!strcmp(mEncoding, "utf-16be");
|
mEncoding.EqualsLiteral("UTF-16BE");
|
||||||
|
|
||||||
// If the constructor is called with an options argument,
|
// If the constructor is called with an options argument,
|
||||||
// and the fatal property of the dictionary is set,
|
// and the fatal property of the dictionary is set,
|
||||||
@ -44,7 +44,7 @@ TextDecoder::Init(const nsAString& aEncoding,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccm->GetUnicodeDecoder(mEncoding, getter_AddRefs(mDecoder));
|
ccm->GetUnicodeDecoderRaw(mEncoding.get(), getter_AddRefs(mDecoder));
|
||||||
if (!mDecoder) {
|
if (!mDecoder) {
|
||||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||||
return;
|
return;
|
||||||
@ -168,12 +168,12 @@ TextDecoder::HandleBOM(const char*& aData, uint32_t& aLength,
|
|||||||
aLength -= 2 - mOffset;
|
aLength -= 2 - mOffset;
|
||||||
mOffset = 2;
|
mOffset = 2;
|
||||||
|
|
||||||
const char* encoding = "";
|
nsAutoCString encoding;
|
||||||
if (!EncodingUtils::IdentifyDataOffset(mInitialBytes, 2, encoding) ||
|
if (!EncodingUtils::IdentifyDataOffset(mInitialBytes, 2, encoding) ||
|
||||||
strcmp(encoding, mEncoding)) {
|
!encoding.Equals(mEncoding)) {
|
||||||
// If the stream doesn't start with BOM or the BOM doesn't match the
|
// If the stream doesn't start with BOM or the BOM doesn't match the
|
||||||
// encoding, feed a BOM to workaround decoder's bug (bug 634541).
|
// encoding, feed a BOM to workaround decoder's bug (bug 634541).
|
||||||
FeedBytes(!strcmp(mEncoding, "utf-16le") ? "\xFF\xFE" : "\xFE\xFF");
|
FeedBytes(mEncoding.EqualsLiteral("UTF-16LE") ? "\xFF\xFE" : "\xFE\xFF");
|
||||||
}
|
}
|
||||||
FeedBytes(mInitialBytes, &aOutString);
|
FeedBytes(mInitialBytes, &aOutString);
|
||||||
}
|
}
|
||||||
@ -201,12 +201,13 @@ TextDecoder::GetEncoding(nsAString& aEncoding)
|
|||||||
// "utf-16".
|
// "utf-16".
|
||||||
// This workaround should not be exposed to the public API and so "utf-16"
|
// This workaround should not be exposed to the public API and so "utf-16"
|
||||||
// is returned by GetEncoding() if the internal encoding name is "utf-16le".
|
// is returned by GetEncoding() if the internal encoding name is "utf-16le".
|
||||||
if (!strcmp(mEncoding, "utf-16le")) {
|
if (mEncoding.EqualsLiteral("UTF-16LE")) {
|
||||||
aEncoding.AssignLiteral("utf-16");
|
aEncoding.AssignLiteral("utf-16");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
aEncoding.AssignASCII(mEncoding);
|
CopyASCIItoUTF16(mEncoding, aEncoding);
|
||||||
|
nsContentUtils::ASCIIToLower(aEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextDecoder)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextDecoder)
|
||||||
|
@ -92,7 +92,7 @@ public:
|
|||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* mEncoding;
|
nsCString mEncoding;
|
||||||
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
nsCOMPtr<nsIUnicodeDecoder> mDecoder;
|
||||||
nsCOMPtr<nsISupports> mGlobal;
|
nsCOMPtr<nsISupports> mGlobal;
|
||||||
bool mFatal;
|
bool mFatal;
|
||||||
|
@ -26,9 +26,9 @@ TextEncoder::Init(const nsAString& aEncoding,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PL_strcasecmp(mEncoding, "utf-8") &&
|
if (!mEncoding.EqualsLiteral("UTF-8") &&
|
||||||
PL_strcasecmp(mEncoding, "utf-16le") &&
|
!mEncoding.EqualsLiteral("UTF-16LE") &&
|
||||||
PL_strcasecmp(mEncoding, "utf-16be")) {
|
!mEncoding.EqualsLiteral("UTF-16BE")) {
|
||||||
aRv.ThrowTypeError(MSG_DOM_ENCODING_NOT_UTF);
|
aRv.ThrowTypeError(MSG_DOM_ENCODING_NOT_UTF);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ TextEncoder::Init(const nsAString& aEncoding,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccm->GetUnicodeEncoder(mEncoding, getter_AddRefs(mEncoder));
|
ccm->GetUnicodeEncoderRaw(mEncoding.get(), getter_AddRefs(mEncoder));
|
||||||
if (!mEncoder) {
|
if (!mEncoder) {
|
||||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||||
return;
|
return;
|
||||||
@ -106,11 +106,13 @@ TextEncoder::GetEncoding(nsAString& aEncoding)
|
|||||||
// "utf-16".
|
// "utf-16".
|
||||||
// This workaround should not be exposed to the public API and so "utf-16"
|
// This workaround should not be exposed to the public API and so "utf-16"
|
||||||
// is returned by GetEncoding() if the internal encoding name is "utf-16le".
|
// is returned by GetEncoding() if the internal encoding name is "utf-16le".
|
||||||
if (!strcmp(mEncoding, "utf-16le")) {
|
if (mEncoding.EqualsLiteral("UTF-16LE")) {
|
||||||
aEncoding.AssignLiteral("utf-16");
|
aEncoding.AssignLiteral("utf-16");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
aEncoding.AssignASCII(mEncoding);
|
|
||||||
|
CopyASCIItoUTF16(mEncoding, aEncoding);
|
||||||
|
nsContentUtils::ASCIIToLower(aEncoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextEncoder)
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TextEncoder)
|
||||||
|
@ -85,7 +85,7 @@ public:
|
|||||||
const TextEncodeOptions& aOptions,
|
const TextEncodeOptions& aOptions,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
private:
|
private:
|
||||||
const char* mEncoding;
|
nsCString mEncoding;
|
||||||
nsCOMPtr<nsIUnicodeEncoder> mEncoder;
|
nsCOMPtr<nsIUnicodeEncoder> mEncoder;
|
||||||
nsCOMPtr<nsISupports> mGlobal;
|
nsCOMPtr<nsISupports> mGlobal;
|
||||||
|
|
||||||
|
223
dom/encoding/labelsencodings.properties
Normal file
223
dom/encoding/labelsencodings.properties
Normal file
@ -0,0 +1,223 @@
|
|||||||
|
# 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/.
|
||||||
|
#
|
||||||
|
# The list is taken from http://encoding.spec.whatwg.org/#encodings
|
||||||
|
# The encoding name may not be lowercased due to compatibility with
|
||||||
|
# our internal implementations.
|
||||||
|
#
|
||||||
|
|
||||||
|
unicode-1-1-utf-8=UTF-8
|
||||||
|
utf-8=UTF-8
|
||||||
|
utf8=UTF-8
|
||||||
|
866=IBM866
|
||||||
|
cp866=IBM866
|
||||||
|
csibm866=IBM866
|
||||||
|
ibm866=IBM866
|
||||||
|
csisolatin2=ISO-8859-2
|
||||||
|
iso-8859-2=ISO-8859-2
|
||||||
|
iso-ir-101=ISO-8859-2
|
||||||
|
iso8859-2=ISO-8859-2
|
||||||
|
iso88592=ISO-8859-2
|
||||||
|
iso_8859-2=ISO-8859-2
|
||||||
|
iso_8859-2:1987=ISO-8859-2
|
||||||
|
l2=ISO-8859-2
|
||||||
|
latin2=ISO-8859-2
|
||||||
|
csisolatin3=ISO-8859-3
|
||||||
|
iso-8859-3=ISO-8859-3
|
||||||
|
iso-ir-109=ISO-8859-3
|
||||||
|
iso8859-3=ISO-8859-3
|
||||||
|
iso88593=ISO-8859-3
|
||||||
|
iso_8859-3=ISO-8859-3
|
||||||
|
iso_8859-3:1988=ISO-8859-3
|
||||||
|
l3=ISO-8859-3
|
||||||
|
latin3=ISO-8859-3
|
||||||
|
csisolatin4=ISO-8859-4
|
||||||
|
iso-8859-4=ISO-8859-4
|
||||||
|
iso-ir-110=ISO-8859-4
|
||||||
|
iso8859-4=ISO-8859-4
|
||||||
|
iso88594=ISO-8859-4
|
||||||
|
iso_8859-4=ISO-8859-4
|
||||||
|
iso_8859-4:1988=ISO-8859-4
|
||||||
|
l4=ISO-8859-4
|
||||||
|
latin4=ISO-8859-4
|
||||||
|
csisolatincyrillic=ISO-8859-5
|
||||||
|
cyrillic=ISO-8859-5
|
||||||
|
iso-8859-5=ISO-8859-5
|
||||||
|
iso-ir-144=ISO-8859-5
|
||||||
|
iso8859-5=ISO-8859-5
|
||||||
|
iso88595=ISO-8859-5
|
||||||
|
iso_8859-5=ISO-8859-5
|
||||||
|
iso_8859-5:1988=ISO-8859-5
|
||||||
|
arabic=ISO-8859-6
|
||||||
|
asmo-708=ISO-8859-6
|
||||||
|
csiso88596e=ISO-8859-6
|
||||||
|
csiso88596i=ISO-8859-6
|
||||||
|
csisolatinarabic=ISO-8859-6
|
||||||
|
ecma-114=ISO-8859-6
|
||||||
|
iso-8859-6=ISO-8859-6
|
||||||
|
iso-8859-6-e=ISO-8859-6
|
||||||
|
iso-8859-6-i=ISO-8859-6
|
||||||
|
iso-ir-127=ISO-8859-6
|
||||||
|
iso8859-6=ISO-8859-6
|
||||||
|
iso88596=ISO-8859-6
|
||||||
|
iso_8859-6=ISO-8859-6
|
||||||
|
iso_8859-6:1987=ISO-8859-6
|
||||||
|
csisolatingreek=ISO-8859-7
|
||||||
|
ecma-118=ISO-8859-7
|
||||||
|
elot_928=ISO-8859-7
|
||||||
|
greek=ISO-8859-7
|
||||||
|
greek8=ISO-8859-7
|
||||||
|
iso-8859-7=ISO-8859-7
|
||||||
|
iso-ir-126=ISO-8859-7
|
||||||
|
iso8859-7=ISO-8859-7
|
||||||
|
iso88597=ISO-8859-7
|
||||||
|
iso_8859-7=ISO-8859-7
|
||||||
|
iso_8859-7:1987=ISO-8859-7
|
||||||
|
sun_eu_greek=ISO-8859-7
|
||||||
|
csiso88598e=ISO-8859-8
|
||||||
|
csisolatinhebrew=ISO-8859-8
|
||||||
|
hebrew=ISO-8859-8
|
||||||
|
iso-8859-8=ISO-8859-8
|
||||||
|
iso-8859-8-e=ISO-8859-8
|
||||||
|
iso-ir-138=ISO-8859-8
|
||||||
|
iso8859-8=ISO-8859-8
|
||||||
|
iso88598=ISO-8859-8
|
||||||
|
iso_8859-8=ISO-8859-8
|
||||||
|
iso_8859-8:1988=ISO-8859-8
|
||||||
|
visual=ISO-8859-8
|
||||||
|
csiso88598i=ISO-8859-8-I
|
||||||
|
iso-8859-8-i=ISO-8859-8-I
|
||||||
|
logical=ISO-8859-8-I
|
||||||
|
csisolatin6=ISO-8859-10
|
||||||
|
iso-8859-10=ISO-8859-10
|
||||||
|
iso-ir-157=ISO-8859-10
|
||||||
|
iso8859-10=ISO-8859-10
|
||||||
|
iso885910=ISO-8859-10
|
||||||
|
l6=ISO-8859-10
|
||||||
|
latin6=ISO-8859-10
|
||||||
|
iso-8859-13=ISO-8859-13
|
||||||
|
iso8859-13=ISO-8859-13
|
||||||
|
iso885913=ISO-8859-13
|
||||||
|
iso-8859-14=ISO-8859-14
|
||||||
|
iso8859-14=ISO-8859-14
|
||||||
|
iso885914=ISO-8859-14
|
||||||
|
csisolatin9=ISO-8859-15
|
||||||
|
iso-8859-15=ISO-8859-15
|
||||||
|
iso8859-15=ISO-8859-15
|
||||||
|
iso885915=ISO-8859-15
|
||||||
|
iso_8859-15=ISO-8859-15
|
||||||
|
l9=ISO-8859-15
|
||||||
|
iso-8859-16=ISO-8859-16
|
||||||
|
cskoi8r=KOI8-R
|
||||||
|
koi=KOI8-R
|
||||||
|
koi8=KOI8-R
|
||||||
|
koi8-r=KOI8-R
|
||||||
|
koi8_r=KOI8-R
|
||||||
|
koi8-u=KOI8-U
|
||||||
|
csmacintosh=macintosh
|
||||||
|
mac=macintosh
|
||||||
|
macintosh=macintosh
|
||||||
|
x-mac-roman=macintosh
|
||||||
|
dos-874=windows-874
|
||||||
|
iso-8859-11=windows-874
|
||||||
|
iso8859-11=windows-874
|
||||||
|
iso885911=windows-874
|
||||||
|
tis-620=windows-874
|
||||||
|
windows-874=windows-874
|
||||||
|
cp1250=windows-1250
|
||||||
|
windows-1250=windows-1250
|
||||||
|
x-cp1250=windows-1250
|
||||||
|
cp1251=windows-1251
|
||||||
|
windows-1251=windows-1251
|
||||||
|
x-cp1251=windows-1251
|
||||||
|
ansi_x3.4-1968=windows-1252
|
||||||
|
ascii=windows-1252
|
||||||
|
cp1252=windows-1252
|
||||||
|
cp819=windows-1252
|
||||||
|
csisolatin1=windows-1252
|
||||||
|
ibm819=windows-1252
|
||||||
|
iso-8859-1=windows-1252
|
||||||
|
iso-ir-100=windows-1252
|
||||||
|
iso8859-1=windows-1252
|
||||||
|
iso88591=windows-1252
|
||||||
|
iso_8859-1=windows-1252
|
||||||
|
iso_8859-1:1987=windows-1252
|
||||||
|
l1=windows-1252
|
||||||
|
latin1=windows-1252
|
||||||
|
us-ascii=windows-1252
|
||||||
|
windows-1252=windows-1252
|
||||||
|
x-cp1252=windows-1252
|
||||||
|
cp1253=windows-1253
|
||||||
|
windows-1253=windows-1253
|
||||||
|
x-cp1253=windows-1253
|
||||||
|
cp1254=windows-1254
|
||||||
|
csisolatin5=windows-1254
|
||||||
|
iso-8859-9=windows-1254
|
||||||
|
iso-ir-148=windows-1254
|
||||||
|
iso8859-9=windows-1254
|
||||||
|
iso88599=windows-1254
|
||||||
|
iso_8859-9=windows-1254
|
||||||
|
iso_8859-9:1989=windows-1254
|
||||||
|
l5=windows-1254
|
||||||
|
latin5=windows-1254
|
||||||
|
windows-1254=windows-1254
|
||||||
|
x-cp1254=windows-1254
|
||||||
|
cp1255=windows-1255
|
||||||
|
windows-1255=windows-1255
|
||||||
|
x-cp1255=windows-1255
|
||||||
|
cp1256=windows-1256
|
||||||
|
windows-1256=windows-1256
|
||||||
|
x-cp1256=windows-1256
|
||||||
|
cp1257=windows-1257
|
||||||
|
windows-1257=windows-1257
|
||||||
|
x-cp1257=windows-1257
|
||||||
|
cp1258=windows-1258
|
||||||
|
windows-1258=windows-1258
|
||||||
|
x-cp1258=windows-1258
|
||||||
|
x-mac-cyrillic=x-mac-cyrillic
|
||||||
|
x-mac-ukrainian=x-mac-cyrillic
|
||||||
|
chinese=gbk
|
||||||
|
csgb2312=gbk
|
||||||
|
csiso58gb231280=gbk
|
||||||
|
gb2312=gbk
|
||||||
|
gb_2312=gbk
|
||||||
|
gb_2312-80=gbk
|
||||||
|
gbk=gbk
|
||||||
|
iso-ir-58=gbk
|
||||||
|
x-gbk=gbk
|
||||||
|
gb18030=gb18030
|
||||||
|
hz-gb-2312=HZ-GB-2312
|
||||||
|
big5=Big5
|
||||||
|
big5-hkscs=Big5
|
||||||
|
cn-big5=Big5
|
||||||
|
csbig5=Big5
|
||||||
|
x-x-big5=Big5
|
||||||
|
cseucpkdfmtjapanese=EUC-JP
|
||||||
|
euc-jp=EUC-JP
|
||||||
|
x-euc-jp=EUC-JP
|
||||||
|
csiso2022jp=ISO-2022-JP
|
||||||
|
iso-2022-jp=ISO-2022-JP
|
||||||
|
csshiftjis=Shift_JIS
|
||||||
|
ms_kanji=Shift_JIS
|
||||||
|
shift-jis=Shift_JIS
|
||||||
|
shift_jis=Shift_JIS
|
||||||
|
sjis=Shift_JIS
|
||||||
|
windows-31j=Shift_JIS
|
||||||
|
x-sjis=Shift_JIS
|
||||||
|
cseuckr=EUC-KR
|
||||||
|
csksc56011987=EUC-KR
|
||||||
|
euc-kr=EUC-KR
|
||||||
|
iso-ir-149=EUC-KR
|
||||||
|
korean=EUC-KR
|
||||||
|
ks_c_5601-1987=EUC-KR
|
||||||
|
ks_c_5601-1989=EUC-KR
|
||||||
|
ksc5601=EUC-KR
|
||||||
|
ksc_5601=EUC-KR
|
||||||
|
windows-949=EUC-KR
|
||||||
|
csiso2022kr=ISO-2022-KR
|
||||||
|
iso-2022-kr=ISO-2022-KR
|
||||||
|
utf-16=UTF-16LE
|
||||||
|
utf-16le=UTF-16LE
|
||||||
|
utf-16be=UTF-16BE
|
||||||
|
x-user-defined=x-user-defined
|
Loading…
Reference in New Issue
Block a user