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