nsHtml5Portability.cpp (3072B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "nsHtml5Portability.h" 6 #include "jArray.h" 7 #include "nsAtom.h" 8 #include "nsHtml5TreeBuilder.h" 9 #include "nsString.h" 10 11 nsAtom* nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, 12 int32_t length, 13 nsHtml5AtomTable* interner) { 14 NS_ASSERTION(interner, "Didn't get an atom service."); 15 return interner->GetAtom(nsDependentSubstring(buf, buf + length)); 16 } 17 18 nsHtml5String nsHtml5Portability::newStringFromBuffer( 19 char16_t* buf, int32_t offset, int32_t length, 20 nsHtml5TreeBuilder* treeBuilder, bool maybeAtomize) { 21 if (!length) { 22 return nsHtml5String::EmptyString(); 23 } 24 if (maybeAtomize) { 25 return nsHtml5String::FromAtom( 26 NS_AtomizeMainThread(nsDependentSubstring(buf + offset, length))); 27 } 28 return nsHtml5String::FromBuffer(buf + offset, length, treeBuilder); 29 } 30 31 nsHtml5String nsHtml5Portability::newEmptyString() { 32 return nsHtml5String::EmptyString(); 33 } 34 35 nsHtml5String nsHtml5Portability::newStringFromLiteral(const char* literal) { 36 return nsHtml5String::FromLiteral(literal); 37 } 38 39 nsHtml5String nsHtml5Portability::newStringFromString(nsHtml5String string) { 40 return string.Clone(); 41 } 42 43 jArray<char16_t, int32_t> nsHtml5Portability::newCharArrayFromLocal( 44 nsAtom* local) { 45 nsAutoString temp; 46 local->ToString(temp); 47 int32_t len = temp.Length(); 48 jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len); 49 memcpy(arr, temp.BeginReading(), len * sizeof(char16_t)); 50 return arr; 51 } 52 53 jArray<char16_t, int32_t> nsHtml5Portability::newCharArrayFromString( 54 nsHtml5String string) { 55 MOZ_RELEASE_ASSERT(string); 56 uint32_t len = string.Length(); 57 MOZ_RELEASE_ASSERT(len < INT32_MAX); 58 jArray<char16_t, int32_t> arr = jArray<char16_t, int32_t>::newJArray(len); 59 string.CopyToBuffer(arr); 60 return arr; 61 } 62 63 bool nsHtml5Portability::localEqualsBuffer(nsAtom* local, char16_t* buf, 64 int32_t length) { 65 return local->Equals(buf, length); 66 } 67 68 bool nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString( 69 const char* lowerCaseLiteral, nsHtml5String string) { 70 return string.LowerCaseStartsWithASCII(lowerCaseLiteral); 71 } 72 73 bool nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString( 74 const char* lowerCaseLiteral, nsHtml5String string) { 75 return string.LowerCaseEqualsASCII(lowerCaseLiteral); 76 } 77 78 bool nsHtml5Portability::literalEqualsString(const char* literal, 79 nsHtml5String string) { 80 return string.EqualsASCII(literal); 81 } 82 83 bool nsHtml5Portability::stringEqualsString(nsHtml5String one, 84 nsHtml5String other) { 85 return one.Equals(other); 86 } 87 88 void nsHtml5Portability::initializeStatics() {} 89 90 void nsHtml5Portability::releaseStatics() {}