tenfourfox/parser/html/nsHtml5Portability.cpp

135 lines
3.4 KiB
C++
Raw Normal View History

2017-04-19 07:56:45 +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/. */
#include "nsIAtom.h"
#include "nsString.h"
#include "jArray.h"
#include "nsHtml5Portability.h"
#include "nsHtml5TreeBuilder.h"
#include "mozilla/CheckedInt.h"
int32_t
nsHtml5Portability::checkedAdd(int32_t a, int32_t b) {
mozilla::CheckedInt<int32_t> sum(a);
sum += b;
MOZ_RELEASE_ASSERT(sum.isValid(),
"HTML input too large for signed 32-bit integer.");
return sum.value();
}
2017-04-19 07:56:45 +00:00
nsIAtom*
nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, int32_t offset, int32_t length, nsHtml5AtomTable* interner)
{
NS_ASSERTION(!offset, "The offset should always be zero here.");
NS_ASSERTION(interner, "Didn't get an atom service.");
return interner->GetAtom(nsDependentSubstring(buf, buf + length));
}
2019-08-17 05:08:00 +00:00
nsHtml5String
nsHtml5Portability::newStringFromBuffer(char16_t* buf,
int32_t offset,
int32_t length,
nsHtml5TreeBuilder* treeBuilder)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
return nsHtml5String::FromBuffer(buf + offset, length, treeBuilder);
2017-04-19 07:56:45 +00:00
}
2019-08-17 05:08:00 +00:00
nsHtml5String
2017-04-19 07:56:45 +00:00
nsHtml5Portability::newEmptyString()
{
2019-08-17 05:08:00 +00:00
return nsHtml5String::EmptyString();
2017-04-19 07:56:45 +00:00
}
2019-08-17 05:08:00 +00:00
nsHtml5String
2017-04-19 07:56:45 +00:00
nsHtml5Portability::newStringFromLiteral(const char* literal)
{
2019-08-17 05:08:00 +00:00
return nsHtml5String::FromLiteral(literal);
2017-04-19 07:56:45 +00:00
}
2019-08-17 05:08:00 +00:00
nsHtml5String
nsHtml5Portability::newStringFromString(nsHtml5String string)
{
return string.Clone();
2017-04-19 07:56:45 +00:00
}
jArray<char16_t,int32_t>
nsHtml5Portability::newCharArrayFromLocal(nsIAtom* local)
{
nsAutoString temp;
local->ToString(temp);
int32_t len = temp.Length();
jArray<char16_t,int32_t> arr = jArray<char16_t,int32_t>::newJArray(len);
memcpy(arr, temp.BeginReading(), len * sizeof(char16_t));
return arr;
}
2019-08-17 05:08:00 +00:00
jArray<char16_t, int32_t>
nsHtml5Portability::newCharArrayFromString(nsHtml5String string)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
MOZ_RELEASE_ASSERT(string);
uint32_t len = string.Length();
MOZ_RELEASE_ASSERT(len < INT32_MAX);
2017-04-19 07:56:45 +00:00
jArray<char16_t,int32_t> arr = jArray<char16_t,int32_t>::newJArray(len);
2019-08-17 05:08:00 +00:00
string.CopyToBuffer(arr);
2017-04-19 07:56:45 +00:00
return arr;
}
nsIAtom*
nsHtml5Portability::newLocalFromLocal(nsIAtom* local, nsHtml5AtomTable* interner)
{
NS_PRECONDITION(local, "Atom was null.");
NS_PRECONDITION(interner, "Atom table was null");
if (!local->IsStaticAtom()) {
nsAutoString str;
local->ToString(str);
local = interner->GetAtom(str);
}
return local;
}
bool
nsHtml5Portability::localEqualsBuffer(nsIAtom* local, char16_t* buf, int32_t offset, int32_t length)
{
return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length));
}
bool
2019-08-17 05:08:00 +00:00
nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
const char* lowerCaseLiteral,
nsHtml5String string)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
return string.LowerCaseStartsWithASCII(lowerCaseLiteral);
2017-04-19 07:56:45 +00:00
}
bool
2019-08-17 05:08:00 +00:00
nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(
const char* lowerCaseLiteral,
nsHtml5String string)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
return string.LowerCaseEqualsASCII(lowerCaseLiteral);
2017-04-19 07:56:45 +00:00
}
bool
2019-08-17 05:08:00 +00:00
nsHtml5Portability::literalEqualsString(const char* literal,
nsHtml5String string)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
return string.EqualsASCII(literal);
2017-04-19 07:56:45 +00:00
}
bool
2019-08-17 05:08:00 +00:00
nsHtml5Portability::stringEqualsString(nsHtml5String one, nsHtml5String other)
2017-04-19 07:56:45 +00:00
{
2019-08-17 05:08:00 +00:00
return one.Equals(other);
2017-04-19 07:56:45 +00:00
}
void
nsHtml5Portability::initializeStatics()
{
}
void
nsHtml5Portability::releaseStatics()
{
}