Files
palemoon27/parser/htmlparser/nsHTMLEntities.cpp
roytam1 e21f25c894 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1251999 - [css-grid] Update <fixed-size> parsing to the latest spec. r=dholbert (07f68007b7)
- Bug 1151243 part 5 - [css-grid] Reftests for abs. pos. static-position. (f9a3b24508)
- Bug 1242053 part 1 - [css-grid] Fix parsing / serialization of grid-template subgrid values. r=dholbert (39576c2f6d)
- Bug 1242053 part 2 - [css-grid] Enable subgrid support for tests. r=dholbert (6da4aeb35a)
- Bug 1240956 part 2 - [css-grid] Update tests due to the changed column/row value order for 'grid', 'grid-template' and 'grid-gap' properties. (16d2258d3a)
- Bug 1253529 part 1 - [css-grid] Replace uses of the 'grid-template' shorthand with 'grid'. (f847bfa554)
- Bug 1253529 part 2 - [css-grid] Remove the 'grid-template' shorthand. r=dholbert (d553c2f623)
- Bug 594933 - Part 1: Let calc() supports number. r=dbaron (e4bc39b5f0)
- Bug 594933 - Part 2: Add support for calc() to line-height. r=dbaron (901227bacb)
- Bug 1253189 part 5 - Import reftests of css-values. r=dbaron (4599431827)
- Bug 1253189 part 4 - Add skip.list for skipping imported tests. r=dbaron (014f7ca7de)
- Bug 1253189 part 1 - Make import-tests.py compatible with Windows. r=dbaron (a22c3e4f7f)
- Bug 1253189 part 2 - Update import-tests.py script to work on the current repo. r=dbaron (7535b38b71)
- Bug 1253189 part 3 - Update existing received w3c reftests. r=dbaron (0fa2d6e2de)
- Bug 1253189 followup - Update skip.list to match the directory name on CLOSED TREE (019b55c3c9)
- Bug 968761 - Treat nested calc() as plain parenthesis. r=dbaron (537506f4e5)
- Bug 1248371 - [css-grid] Require that each track has a definite min- or max-sizing function when the track list contains a repeat(auto-fill/fit) track. r=dholbert (330dd37427)
- Bug 1244638 - Part 1:implement AnimationEffectTiming iterationStart. r=birtles, r=smaug (d0217068ac)
- Bug 1244638 - Part 2: Throw TypeError if iterationStart is NaN, negative value or Infinity. r=birtles, r=smaug (f631e261a0)
- Bug 1238845 - Implement UUID helper - dom/bluetooth & dom/webidl & layout/build change. r=jocelyn, r=bz (3ddfa8cccf)
- Bug 1252790 - Remove RuleHashTableOps. r=dbaron. (b52d9e2613)
- Bug 1252375 - Fix up jemalloc stats reporting. r=erahm. (dbecb54598)
- Bug 1249503 - Make WindowsAddressSpaceReporter bloat memory reports less. r=erahm. (3bfb6932cb)
- Bug 1253085 - Remove the |PLDHashTable*| argument from PLDHash{HashKey,MatchEntry}. r=froydnj. (1331fd9ea0)
- Bug 1251127 - Gracefully handle multiple calls to nsMemoryReporterManager::Init(). r=erahm. (c51f57907e)
- Bug 1234540 - verify the validity of hashEntry, if it's null return with NS_ERROR_FAILURE. r=michal (f44bd269db)
- Bug 1112499 - Set up shutdown pipe before new thread starts. r=keeler (73b9a56196)
- Bug 1245059 - Disable NotifyIpInterfaceChange use for now. r=mcmanus (ab11fd8507)
- Bug 1251873 - Store the trimmed referrer URL on HTTP channel if a trimming referrer policy is in effect; r=mcmanus (3f43d5b351)
- more bits of bug 366559 - patch 7, content-encoding brotli for https (f127a97450)
- Bug 1250115 - initialized pollInterval with 0 in order to prevent garbage value if Poll(..) doesn't get called. r=dragana (af55e06789)
- Bug 1251493 - Remove remaining references to MOZILLA_XPCOMRT_API from netwerk. r=mcmanus (43d711d2d6)
- Bug 1242452 - only if PR_GetIdentitiesLayer return valid pointer continue and pass it's result to PR_GetIdentitiesLayer. r=mcmanus (61a2785337)
- Bug 1251595 - Check if mNetAddr is set before sending ipv4/6 telemetry. r=mcmanus (9d081bc0b9)
- Bug 1252755: increase maximum UDP packet size to 9216 bytes for jumbo frames. r=jesup (3d629473ea)
- Bug 1194259: warnings-as-errors bustage fix rs=bustagn a CLOSED TREE (5b8288ff6d)
- Bug 1227781 - Fix crash with bogus STUN parameters. r=bwc (7d132a37ff)
- Bug 1231196: Fix init of PeerConnectionImpl::mThread for unit-tests and similar. r+drno (60f11ed191)
- Bug 1230184 - plumb setParameters down to JsepTrack. r=bwc, r=mrbkap (fdeaafb737)
- Bug 1231507 - Part 1: selectSsrc chrome-only API for SSRC-based filtering of receive tracks. r=drno, r=smaug (c24ce1a76e)
- Bug 1221837 - Accept hard coded codec numbers without rtpmaps. r=bwc (89b81c861c)
- Bug 1231507 - Part 2: added mochitest SimulCast offer test case r=jib (05d838960f)
- Bug 1230184 - setParameters webidl. r=smaug (6319cdfca7)
- Bug 1230184 - add input parameter validation to setParameters. r=bwc (c0740c142a)
- Bug 1230184 - add media.peerconnection.simulcast pref. r=bwc (99b1a4978d)
- Bug 1247619 - add console warning about OAuth for STUN not yet supported. r=jesup,smaug (801eaa66e1)
- Bug 1241153: Stop blocking addTrack on GMP init, and update codecs on existing tracks when GMP init finishes. r=jesup (3473dfe0ce)
- Bug 1251737 - Remove remaining references to MOZILLA_XPCOMRT_API from media. r=jesup (7b32d9d191)
- Bug 1218326: Prevent datachannel operations on closed PeerConnections. r=jesup a=lizzard (5d20d7dd7f)
- Bug 1211091 - use upper boundary for streams per data channel. r=bwc (7f9462c434)
- Bug 1188391 - separate immediate ICE failures from failures after checking. r=bwc, r=vladan (9095c58656)
- Bug 1227708 - Differentiate ICE_SUCCESS_RATE telemetry for loop vs webrtc r=jesup (399406c872)
- Bug 1232082 - fix removal of remote tracks to update receivers. r=jesup (81998ed355)
- Bug 1244913 - Add test_peerConnection_scaleResolution.html r=bwc,jesup (8ac2d8a363)
- Bug 1249860 - Add simulcast test for resolution scaling. r=bwc (c7753bf02b)
- Bug 1247622 - Make RTCRtpSender.setParameters return a promise. r=jesup,smaug (4c2504adc8)
2024-02-29 23:06:26 +08:00

204 lines
5.7 KiB
C++

/* -*- 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/. */
#include "mozilla/ArrayUtils.h"
#include "nsHTMLEntities.h"
#include "nsString.h"
#include "nsCRT.h"
#include "PLDHashTable.h"
using namespace mozilla;
struct EntityNode {
const char* mStr; // never owns buffer
int32_t mUnicode;
};
struct EntityNodeEntry : public PLDHashEntryHdr
{
const EntityNode* node;
};
static bool matchNodeString(const PLDHashEntryHdr* aHdr, const void* key)
{
const EntityNodeEntry* entry = static_cast<const EntityNodeEntry*>(aHdr);
const char* str = static_cast<const char*>(key);
return (nsCRT::strcmp(entry->node->mStr, str) == 0);
}
static bool matchNodeUnicode(const PLDHashEntryHdr* aHdr, const void* key)
{
const EntityNodeEntry* entry = static_cast<const EntityNodeEntry*>(aHdr);
const int32_t ucode = NS_PTR_TO_INT32(key);
return (entry->node->mUnicode == ucode);
}
static PLDHashNumber hashUnicodeValue(const void* key)
{
// key is actually the unicode value
return PLDHashNumber(NS_PTR_TO_INT32(key));
}
static const PLDHashTableOps EntityToUnicodeOps = {
PLDHashTable::HashStringKey,
matchNodeString,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};
static const PLDHashTableOps UnicodeToEntityOps = {
hashUnicodeValue,
matchNodeUnicode,
PLDHashTable::MoveEntryStub,
PLDHashTable::ClearEntryStub,
nullptr,
};
static PLDHashTable* gEntityToUnicode;
static PLDHashTable* gUnicodeToEntity;
static nsrefcnt gTableRefCnt = 0;
#define HTML_ENTITY(_name, _value) { #_name, _value },
static const EntityNode gEntityArray[] = {
#include "nsHTMLEntityList.h"
};
#undef HTML_ENTITY
#define NS_HTML_ENTITY_COUNT ((int32_t)ArrayLength(gEntityArray))
nsresult
nsHTMLEntities::AddRefTable(void)
{
if (!gTableRefCnt) {
gEntityToUnicode = new PLDHashTable(&EntityToUnicodeOps,
sizeof(EntityNodeEntry),
NS_HTML_ENTITY_COUNT);
gUnicodeToEntity = new PLDHashTable(&UnicodeToEntityOps,
sizeof(EntityNodeEntry),
NS_HTML_ENTITY_COUNT);
for (const EntityNode *node = gEntityArray,
*node_end = ArrayEnd(gEntityArray);
node < node_end; ++node) {
// add to Entity->Unicode table
auto entry = static_cast<EntityNodeEntry*>
(gEntityToUnicode->Add(node->mStr, fallible));
NS_ASSERTION(entry, "Error adding an entry");
// Prefer earlier entries when we have duplication.
if (!entry->node)
entry->node = node;
// add to Unicode->Entity table
entry = static_cast<EntityNodeEntry*>
(gUnicodeToEntity->Add(NS_INT32_TO_PTR(node->mUnicode),
fallible));
NS_ASSERTION(entry, "Error adding an entry");
// Prefer earlier entries when we have duplication.
if (!entry->node)
entry->node = node;
}
#ifdef DEBUG
gUnicodeToEntity->MarkImmutable();
gEntityToUnicode->MarkImmutable();
#endif
}
++gTableRefCnt;
return NS_OK;
}
void
nsHTMLEntities::ReleaseTable(void)
{
if (--gTableRefCnt != 0)
return;
delete gEntityToUnicode;
delete gUnicodeToEntity;
gEntityToUnicode = nullptr;
gUnicodeToEntity = nullptr;
}
int32_t
nsHTMLEntities::EntityToUnicode(const nsCString& aEntity)
{
NS_ASSERTION(gEntityToUnicode, "no lookup table, needs addref");
if (!gEntityToUnicode)
return -1;
//this little piece of code exists because entities may or may not have the terminating ';'.
//if we see it, strip if off for this test...
if(';'==aEntity.Last()) {
nsAutoCString temp(aEntity);
temp.Truncate(aEntity.Length()-1);
return EntityToUnicode(temp);
}
auto entry =
static_cast<EntityNodeEntry*>(gEntityToUnicode->Search(aEntity.get()));
return entry ? entry->node->mUnicode : -1;
}
int32_t
nsHTMLEntities::EntityToUnicode(const nsAString& aEntity) {
nsAutoCString theEntity; theEntity.AssignWithConversion(aEntity);
if(';'==theEntity.Last()) {
theEntity.Truncate(theEntity.Length()-1);
}
return EntityToUnicode(theEntity);
}
const char*
nsHTMLEntities::UnicodeToEntity(int32_t aUnicode)
{
NS_ASSERTION(gUnicodeToEntity, "no lookup table, needs addref");
auto entry =
static_cast<EntityNodeEntry*>
(gUnicodeToEntity->Search(NS_INT32_TO_PTR(aUnicode)));
return entry ? entry->node->mStr : nullptr;
}
#ifdef DEBUG
#include <stdio.h>
class nsTestEntityTable {
public:
nsTestEntityTable() {
int32_t value;
nsHTMLEntities::AddRefTable();
// Make sure we can find everything we are supposed to
for (int i = 0; i < NS_HTML_ENTITY_COUNT; ++i) {
nsAutoString entity; entity.AssignWithConversion(gEntityArray[i].mStr);
value = nsHTMLEntities::EntityToUnicode(entity);
NS_ASSERTION(value != -1, "can't find entity");
NS_ASSERTION(value == gEntityArray[i].mUnicode, "bad unicode value");
entity.AssignWithConversion(nsHTMLEntities::UnicodeToEntity(value));
NS_ASSERTION(entity.EqualsASCII(gEntityArray[i].mStr), "bad entity name");
}
// Make sure we don't find things that aren't there
value = nsHTMLEntities::EntityToUnicode(nsAutoCString("@"));
NS_ASSERTION(value == -1, "found @");
value = nsHTMLEntities::EntityToUnicode(nsAutoCString("zzzzz"));
NS_ASSERTION(value == -1, "found zzzzz");
nsHTMLEntities::ReleaseTable();
}
};
//nsTestEntityTable validateEntityTable;
#endif