summaryrefslogtreecommitdiffstats
path: root/parser/html/nsHtml5Portability.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /parser/html/nsHtml5Portability.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'parser/html/nsHtml5Portability.cpp')
-rw-r--r--parser/html/nsHtml5Portability.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/parser/html/nsHtml5Portability.cpp b/parser/html/nsHtml5Portability.cpp
new file mode 100644
index 000000000..36c7e758a
--- /dev/null
+++ b/parser/html/nsHtml5Portability.cpp
@@ -0,0 +1,157 @@
+/* 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"
+
+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));
+}
+
+nsString*
+nsHtml5Portability::newStringFromBuffer(char16_t* buf, int32_t offset, int32_t length, nsHtml5TreeBuilder* treeBuilder)
+{
+ nsString* str = new nsString();
+ bool succeeded = str->Append(buf + offset, length, mozilla::fallible);
+ if (!succeeded) {
+ str->Assign(char16_t(0xFFFD));
+ treeBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
+ }
+ return str;
+}
+
+nsString*
+nsHtml5Portability::newEmptyString()
+{
+ return new nsString();
+}
+
+nsString*
+nsHtml5Portability::newStringFromLiteral(const char* literal)
+{
+ nsString* str = new nsString();
+ str->AssignASCII(literal);
+ return str;
+}
+
+nsString*
+nsHtml5Portability::newStringFromString(nsString* string) {
+ nsString* newStr = new nsString();
+ newStr->Assign(*string);
+ return newStr;
+}
+
+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;
+}
+
+jArray<char16_t,int32_t>
+nsHtml5Portability::newCharArrayFromString(nsString* string)
+{
+ int32_t len = string->Length();
+ jArray<char16_t,int32_t> arr = jArray<char16_t,int32_t>::newJArray(len);
+ memcpy(arr, string->BeginReading(), len * sizeof(char16_t));
+ 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;
+}
+
+void
+nsHtml5Portability::releaseString(nsString* str)
+{
+ delete str;
+}
+
+bool
+nsHtml5Portability::localEqualsBuffer(nsIAtom* local, char16_t* buf, int32_t offset, int32_t length)
+{
+ return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length));
+}
+
+bool
+nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string)
+{
+ if (!string) {
+ return false;
+ }
+ const char* litPtr = lowerCaseLiteral;
+ const char16_t* strPtr = string->BeginReading();
+ const char16_t* end = string->EndReading();
+ char16_t litChar;
+ while ((litChar = *litPtr)) {
+ NS_ASSERTION(!(litChar >= 'A' && litChar <= 'Z'), "Literal isn't in lower case.");
+ if (strPtr == end) {
+ return false;
+ }
+ char16_t strChar = *strPtr;
+ if (strChar >= 'A' && strChar <= 'Z') {
+ strChar += 0x20;
+ }
+ if (litChar != strChar) {
+ return false;
+ }
+ ++litPtr;
+ ++strPtr;
+ }
+ return true;
+}
+
+bool
+nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string)
+{
+ if (!string) {
+ return false;
+ }
+ return string->LowerCaseEqualsASCII(lowerCaseLiteral);
+}
+
+bool
+nsHtml5Portability::literalEqualsString(const char* literal, nsString* string)
+{
+ if (!string) {
+ return false;
+ }
+ return string->EqualsASCII(literal);
+}
+
+bool
+nsHtml5Portability::stringEqualsString(nsString* one, nsString* other)
+{
+ return one->Equals(*other);
+}
+
+void
+nsHtml5Portability::initializeStatics()
+{
+}
+
+void
+nsHtml5Portability::releaseStatics()
+{
+}