Bug 1418743 - Stop using Encoding::ForName in FallbackEncoding.cpp. r=hsivonen

MozReview-Commit-ID: EsUdqCvSlBf

--HG--
rename : intl/locale/props2arrays.py => dom/encoding/encodings2arrays.py
extra : rebase_source : 8210f998145e93b847ef990d51280db7c6550a52
extra : intermediate-source : 8b2e3fd722018b9c8650702def681f132f9b6890
extra : source : ee95bb97a482c9d9bb25107a1bd66699dbabdb9d
This commit is contained in:
Masatoshi Kimura 2017-11-15 22:56:08 +09:00
Родитель 50dad1e139
Коммит 80c8444cea
3 изменённых файлов: 62 добавлений и 18 удалений

Просмотреть файл

@ -18,11 +18,32 @@ using mozilla::intl::LocaleService;
namespace mozilla {
namespace dom {
static constexpr nsUConvProp localesFallbacks[] = {
struct EncodingProp
{
const char* const mKey;
NotNull<const Encoding*> mValue;
};
template <int32_t N>
static NotNull<const Encoding*>
SearchEncodingProp(const EncodingProp (&aProperties)[N],
const nsACString& aKey)
{
const nsCString& flat = PromiseFlatCString(aKey);
size_t index;
if (!BinarySearchIf(aProperties, 0, ArrayLength(aProperties),
[&flat](const EncodingProp& aProperty)
{ return flat.Compare(aProperty.mKey); }, &index)) {
return WINDOWS_1252_ENCODING;
}
return aProperties[index].mValue;
}
static const EncodingProp localesFallbacks[] = {
#include "localesfallbacks.properties.h"
};
static constexpr nsUConvProp domainsFallbacks[] = {
static const EncodingProp domainsFallbacks[] = {
#include "domainsfallbacks.properties.h"
};
@ -91,15 +112,10 @@ FallbackEncoding::Get()
locale.Truncate(index);
}
nsAutoCString fallback;
if (NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
localesFallbacks, ArrayLength(localesFallbacks), locale, fallback))) {
mFallback = WINDOWS_1252_ENCODING;
} else {
mFallback = Encoding::ForName(fallback);
}
auto fallback = SearchEncodingProp(localesFallbacks, locale);
mFallback = fallback;
return WrapNotNull(mFallback);
return fallback;
}
NotNull<const Encoding*>
@ -176,12 +192,7 @@ FallbackEncoding::IsParticipatingTopLevelDomain(const nsACString& aTLD)
NotNull<const Encoding*>
FallbackEncoding::FromTopLevelDomain(const nsACString& aTLD)
{
nsAutoCString fallback;
if (NS_FAILED(nsUConvPropertySearch::SearchPropertyValue(
domainsFallbacks, ArrayLength(domainsFallbacks), aTLD, fallback))) {
return WINDOWS_1252_ENCODING;
}
return Encoding::ForName(fallback);
return SearchEncodingProp(domainsFallbacks, aTLD);
}
} // namespace dom

Просмотреть файл

@ -0,0 +1,27 @@
# 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/.
import sys
def main(header, propFile):
mappings = {}
with open(propFile, 'r') as f:
for line in f:
line = line.strip()
if not line.startswith('#'):
parts = line.split("=", 1)
if len(parts) == 2 and len(parts[0]) > 0:
mappings[parts[0].strip()] = parts[1].strip()
keys = mappings.keys()
keys.sort()
header.write("// This is a generated file. Please do not edit.\n")
header.write("// Please edit the corresponding .properties file instead.\n")
entries = ['{ "%s", %s }'
% (key, mappings[key].replace('-', '_').upper() + '_ENCODING') for key in keys]
header.write(',\n'.join(entries) + '\n')

Просмотреть файл

@ -24,12 +24,11 @@ LOCAL_INCLUDES += [
'/intl/locale',
]
props2arrays = '/intl/locale/props2arrays.py'
props2arrays = 'encodings2arrays.py'
prefixes = (
'domainsfallbacks',
'labelsencodings',
'localesfallbacks',
'nonparticipatingdomains',
)
for prefix in prefixes:
@ -40,6 +39,13 @@ for prefix in prefixes:
props.script = props2arrays
props.inputs = [input_file]
input_file = 'nonparticipatingdomains.properties'
header = input_file + '.h'
GENERATED_FILES += [header]
props = GENERATED_FILES[header]
props.script = '../../intl/locale/props2arrays.py'
props.inputs = [input_file]
MOCHITEST_MANIFESTS += [
'test/mochitest.ini',
]