2012-05-29 15:52:43 +00:00
|
|
|
/* 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/. */
|
2009-06-28 22:44:22 +00:00
|
|
|
|
|
|
|
#include "nsHtml5Portability.h"
|
2018-03-16 15:26:06 +00:00
|
|
|
#include "jArray.h"
|
|
|
|
#include "nsAtom.h"
|
2015-08-25 15:05:46 +00:00
|
|
|
#include "nsHtml5TreeBuilder.h"
|
2018-03-16 15:26:06 +00:00
|
|
|
#include "nsString.h"
|
2009-06-28 22:44:22 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom*
|
2018-03-16 15:26:06 +00:00
|
|
|
nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf,
|
|
|
|
int32_t length,
|
|
|
|
nsHtml5AtomTable* interner)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2009-09-21 11:43:43 +00:00
|
|
|
NS_ASSERTION(interner, "Didn't get an atom service.");
|
|
|
|
return interner->GetAtom(nsDependentSubstring(buf, buf + length));
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 06:22:57 +00:00
|
|
|
static bool
|
|
|
|
ContainsWhiteSpace(mozilla::Span<char16_t> aSpan)
|
|
|
|
{
|
|
|
|
for (char16_t c : aSpan) {
|
|
|
|
if (nsContentUtils::IsHTMLWhitespace(c)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5String
|
|
|
|
nsHtml5Portability::newStringFromBuffer(char16_t* buf,
|
|
|
|
int32_t offset,
|
|
|
|
int32_t length,
|
2017-08-11 06:22:57 +00:00
|
|
|
nsHtml5TreeBuilder* treeBuilder,
|
|
|
|
bool maybeAtomize)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-08-11 06:22:57 +00:00
|
|
|
if (!length) {
|
|
|
|
return nsHtml5String::EmptyString();
|
|
|
|
}
|
2018-03-16 15:26:06 +00:00
|
|
|
if (maybeAtomize &&
|
|
|
|
!ContainsWhiteSpace(mozilla::MakeSpan(buf + offset, length))) {
|
|
|
|
return nsHtml5String::FromAtom(
|
|
|
|
NS_AtomizeMainThread(nsDependentSubstring(buf + offset, length)));
|
2017-08-11 06:22:57 +00:00
|
|
|
}
|
2017-03-20 12:45:15 +00:00
|
|
|
return nsHtml5String::FromBuffer(buf + offset, length, treeBuilder);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5String
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5Portability::newEmptyString()
|
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return nsHtml5String::EmptyString();
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5String
|
2009-06-28 22:44:22 +00:00
|
|
|
nsHtml5Portability::newStringFromLiteral(const char* literal)
|
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return nsHtml5String::FromLiteral(literal);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5String
|
|
|
|
nsHtml5Portability::newStringFromString(nsHtml5String string)
|
|
|
|
{
|
|
|
|
return string.Clone();
|
2009-09-21 07:00:10 +00:00
|
|
|
}
|
|
|
|
|
2018-03-16 15:26:06 +00:00
|
|
|
jArray<char16_t, int32_t>
|
2017-10-02 22:05:19 +00:00
|
|
|
nsHtml5Portability::newCharArrayFromLocal(nsAtom* local)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
|
|
|
nsAutoString temp;
|
|
|
|
local->ToString(temp);
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = temp.Length();
|
2018-03-16 15:26:06 +00:00
|
|
|
jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len);
|
2014-01-04 15:02:17 +00:00
|
|
|
memcpy(arr, temp.BeginReading(), len * sizeof(char16_t));
|
2009-07-15 11:30:33 +00:00
|
|
|
return arr;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 12:45:15 +00:00
|
|
|
jArray<char16_t, int32_t>
|
|
|
|
nsHtml5Portability::newCharArrayFromString(nsHtml5String string)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
MOZ_RELEASE_ASSERT(string);
|
|
|
|
uint32_t len = string.Length();
|
|
|
|
MOZ_RELEASE_ASSERT(len < INT32_MAX);
|
2018-03-16 15:26:06 +00:00
|
|
|
jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len);
|
2017-03-20 12:45:15 +00:00
|
|
|
string.CopyToBuffer(arr);
|
2009-07-15 11:30:33 +00:00
|
|
|
return arr;
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom*
|
|
|
|
nsHtml5Portability::newLocalFromLocal(nsAtom* local, nsHtml5AtomTable* interner)
|
2009-09-21 13:18:20 +00:00
|
|
|
{
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(local, "Atom was null.");
|
|
|
|
MOZ_ASSERT(interner, "Atom table was null");
|
2018-03-07 04:17:34 +00:00
|
|
|
if (!local->IsStatic()) {
|
2009-09-21 13:18:20 +00:00
|
|
|
nsAutoString str;
|
|
|
|
local->ToString(str);
|
|
|
|
local = interner->GetAtom(str);
|
|
|
|
}
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2018-03-16 15:26:06 +00:00
|
|
|
nsHtml5Portability::localEqualsBuffer(nsAtom* local,
|
|
|
|
char16_t* buf,
|
|
|
|
int32_t length)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-10-23 11:42:21 +00:00
|
|
|
return local->Equals(buf, length);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
|
|
|
|
const char* lowerCaseLiteral,
|
|
|
|
nsHtml5String string)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return string.LowerCaseStartsWithASCII(lowerCaseLiteral);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(
|
|
|
|
const char* lowerCaseLiteral,
|
|
|
|
nsHtml5String string)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return string.LowerCaseEqualsASCII(lowerCaseLiteral);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5Portability::literalEqualsString(const char* literal,
|
|
|
|
nsHtml5String string)
|
2009-06-28 22:44:22 +00:00
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return string.EqualsASCII(literal);
|
2009-06-28 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2017-03-20 12:45:15 +00:00
|
|
|
nsHtml5Portability::stringEqualsString(nsHtml5String one, nsHtml5String other)
|
2010-10-15 09:23:42 +00:00
|
|
|
{
|
2017-03-20 12:45:15 +00:00
|
|
|
return one.Equals(other);
|
2010-10-15 09:23:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 22:44:22 +00:00
|
|
|
void
|
|
|
|
nsHtml5Portability::initializeStatics()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHtml5Portability::releaseStatics()
|
|
|
|
{
|
|
|
|
}
|