Bug 1262324 (part 2) - Introduce nsUConvProp. r=emk.

This patch fixes the hack of using a trio of |const char*| pointers to
represent a property that has two strings and a length.

--HG--
extra : rebase_source : 9f603b768146a78baf9fa2b4096cccfae9f87322
This commit is contained in:
Nicholas Nethercote 2016-04-06 13:31:38 +10:00
Родитель 827c11faae
Коммит c8c2a2bc4d
9 изменённых файлов: 23 добавлений и 15 удалений

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

@ -15,11 +15,11 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
static const char* const labelsEncodings[][3] = { static const nsUConvProp labelsEncodings[] = {
#include "labelsencodings.properties.h" #include "labelsencodings.properties.h"
}; };
static const char* const encodingsGroups[][3] = { static const nsUConvProp encodingsGroups[] = {
#include "encodingsgroups.properties.h" #include "encodingsgroups.properties.h"
}; };

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

@ -15,15 +15,15 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
static const char* const localesFallbacks[][3] = { static const nsUConvProp localesFallbacks[] = {
#include "localesfallbacks.properties.h" #include "localesfallbacks.properties.h"
}; };
static const char* const domainsFallbacks[][3] = { static const nsUConvProp domainsFallbacks[] = {
#include "domainsfallbacks.properties.h" #include "domainsfallbacks.properties.h"
}; };
static const char* const nonParticipatingDomains[][3] = { static const nsUConvProp nonParticipatingDomains[] = {
#include "nonparticipatingdomains.properties.h" #include "nonparticipatingdomains.properties.h"
}; };

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

@ -15,7 +15,7 @@
using namespace mozilla; using namespace mozilla;
static const char* const kLangGroups[][3] = { static const nsUConvProp kLangGroups[] = {
#include "langGroups.properties.h" #include "langGroups.properties.h"
}; };

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

@ -8,6 +8,7 @@
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsInterfaceHashtable.h" #include "nsInterfaceHashtable.h"
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsUConvPropertySearch.h"
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#define NS_LANGUAGEATOMSERVICE_CID \ #define NS_LANGUAGEATOMSERVICE_CID \

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

@ -13,8 +13,8 @@ struct PropertyComparator
{ {
const nsCString& mKey; const nsCString& mKey;
explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {} explicit PropertyComparator(const nsCString& aKey) : mKey(aKey) {}
int operator()(const char* const (&aProperty)[3]) const { int operator()(const nsUConvProp& aProperty) const {
return mKey.Compare(aProperty[0]); return mKey.Compare(aProperty.mKey);
} }
}; };
@ -22,7 +22,7 @@ struct PropertyComparator
// static // static
nsresult nsresult
nsUConvPropertySearch::SearchPropertyValue(const char* const aProperties[][3], nsUConvPropertySearch::SearchPropertyValue(const nsUConvProp aProperties[],
int32_t aNumberOfProperties, int32_t aNumberOfProperties,
const nsACString& aKey, const nsACString& aKey,
nsACString& aValue) nsACString& aValue)
@ -33,8 +33,8 @@ nsUConvPropertySearch::SearchPropertyValue(const char* const aProperties[][3],
size_t index; size_t index;
if (BinarySearchIf(aProperties, 0, aNumberOfProperties, if (BinarySearchIf(aProperties, 0, aNumberOfProperties,
PropertyComparator(flat), &index)) { PropertyComparator(flat), &index)) {
nsDependentCString val(aProperties[index][1], nsDependentCString val(aProperties[index].mValue,
NS_PTR_TO_UINT32(aProperties[index][2])); aProperties[index].mValueLength);
aValue.Assign(val); aValue.Assign(val);
return NS_OK; return NS_OK;
} }

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

@ -7,6 +7,13 @@
#include "nsStringFwd.h" #include "nsStringFwd.h"
struct nsUConvProp
{
const char* const mKey;
const char* const mValue;
const uint32_t mValueLength;
};
class nsUConvPropertySearch class nsUConvPropertySearch
{ {
public: public:
@ -21,7 +28,7 @@ class nsUConvPropertySearch
* the return value (empty string if not found) * the return value (empty string if not found)
* @return NS_OK if found or NS_ERROR_FAILURE if not found * @return NS_OK if found or NS_ERROR_FAILURE if not found
*/ */
static nsresult SearchPropertyValue(const char* const aProperties[][3], static nsresult SearchPropertyValue(const nsUConvProp aProperties[],
int32_t aNumberOfProperties, int32_t aNumberOfProperties,
const nsACString& aKey, const nsACString& aKey,
nsACString& aValue); nsACString& aValue);

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

@ -21,7 +21,7 @@ def main(header, propFile):
header.write("// This is a generated file. Please do not edit.\n") header.write("// This is a generated file. Please do not edit.\n")
header.write("// Please edit the corresponding .properties file instead.\n") header.write("// Please edit the corresponding .properties file instead.\n")
entries = ['{ "%s", "%s", (const char*)NS_INT32_TO_PTR(%d) }' entries = ['{ "%s", "%s", %d }'
% (key, mappings[key], len(mappings[key])) for key in keys] % (key, mappings[key], len(mappings[key])) for key in keys]
header.write(',\n'.join(entries) + '\n') header.write(',\n'.join(entries) + '\n')

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

@ -29,7 +29,7 @@
using mozilla::dom::EncodingUtils; using mozilla::dom::EncodingUtils;
using namespace mozilla; using namespace mozilla;
static const char* const kUnixCharsets[][3] = { static const nsUConvProp kUnixCharsets[] = {
#include "unixcharset.properties.h" #include "unixcharset.properties.h"
}; };

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

@ -17,7 +17,7 @@
using namespace mozilla; using namespace mozilla;
static const char* const kWinCharsets[][3] = { static const nsUConvProp kWinCharsets[] = {
#include "wincharset.properties.h" #include "wincharset.properties.h"
}; };