michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsIAtom.h" michael@0: #include "nsString.h" michael@0: #include "jArray.h" michael@0: #include "nsHtml5Portability.h" michael@0: michael@0: nsIAtom* michael@0: nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, int32_t offset, int32_t length, nsHtml5AtomTable* interner) michael@0: { michael@0: NS_ASSERTION(!offset, "The offset should always be zero here."); michael@0: NS_ASSERTION(interner, "Didn't get an atom service."); michael@0: return interner->GetAtom(nsDependentSubstring(buf, buf + length)); michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5Portability::newStringFromBuffer(char16_t* buf, int32_t offset, int32_t length) michael@0: { michael@0: return new nsString(buf + offset, length); michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5Portability::newEmptyString() michael@0: { michael@0: return new nsString(); michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5Portability::newStringFromLiteral(const char* literal) michael@0: { michael@0: nsString* str = new nsString(); michael@0: str->AssignASCII(literal); michael@0: return str; michael@0: } michael@0: michael@0: nsString* michael@0: nsHtml5Portability::newStringFromString(nsString* string) { michael@0: nsString* newStr = new nsString(); michael@0: newStr->Assign(*string); michael@0: return newStr; michael@0: } michael@0: michael@0: jArray michael@0: nsHtml5Portability::newCharArrayFromLocal(nsIAtom* local) michael@0: { michael@0: nsAutoString temp; michael@0: local->ToString(temp); michael@0: int32_t len = temp.Length(); michael@0: jArray arr = jArray::newJArray(len); michael@0: memcpy(arr, temp.BeginReading(), len * sizeof(char16_t)); michael@0: return arr; michael@0: } michael@0: michael@0: jArray michael@0: nsHtml5Portability::newCharArrayFromString(nsString* string) michael@0: { michael@0: int32_t len = string->Length(); michael@0: jArray arr = jArray::newJArray(len); michael@0: memcpy(arr, string->BeginReading(), len * sizeof(char16_t)); michael@0: return arr; michael@0: } michael@0: michael@0: nsIAtom* michael@0: nsHtml5Portability::newLocalFromLocal(nsIAtom* local, nsHtml5AtomTable* interner) michael@0: { michael@0: NS_PRECONDITION(local, "Atom was null."); michael@0: NS_PRECONDITION(interner, "Atom table was null"); michael@0: if (!local->IsStaticAtom()) { michael@0: nsAutoString str; michael@0: local->ToString(str); michael@0: local = interner->GetAtom(str); michael@0: } michael@0: return local; michael@0: } michael@0: michael@0: void michael@0: nsHtml5Portability::releaseString(nsString* str) michael@0: { michael@0: delete str; michael@0: } michael@0: michael@0: bool michael@0: nsHtml5Portability::localEqualsBuffer(nsIAtom* local, char16_t* buf, int32_t offset, int32_t length) michael@0: { michael@0: return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length)); michael@0: } michael@0: michael@0: bool michael@0: nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string) michael@0: { michael@0: if (!string) { michael@0: return false; michael@0: } michael@0: const char* litPtr = lowerCaseLiteral; michael@0: const char16_t* strPtr = string->BeginReading(); michael@0: const char16_t* end = string->EndReading(); michael@0: char16_t litChar; michael@0: while ((litChar = *litPtr)) { michael@0: NS_ASSERTION(!(litChar >= 'A' && litChar <= 'Z'), "Literal isn't in lower case."); michael@0: if (strPtr == end) { michael@0: return false; michael@0: } michael@0: char16_t strChar = *strPtr; michael@0: if (strChar >= 'A' && strChar <= 'Z') { michael@0: strChar += 0x20; michael@0: } michael@0: if (litChar != strChar) { michael@0: return false; michael@0: } michael@0: ++litPtr; michael@0: ++strPtr; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string) michael@0: { michael@0: if (!string) { michael@0: return false; michael@0: } michael@0: return string->LowerCaseEqualsASCII(lowerCaseLiteral); michael@0: } michael@0: michael@0: bool michael@0: nsHtml5Portability::literalEqualsString(const char* literal, nsString* string) michael@0: { michael@0: if (!string) { michael@0: return false; michael@0: } michael@0: return string->EqualsASCII(literal); michael@0: } michael@0: michael@0: bool michael@0: nsHtml5Portability::stringEqualsString(nsString* one, nsString* other) michael@0: { michael@0: return one->Equals(*other); michael@0: } michael@0: michael@0: void michael@0: nsHtml5Portability::initializeStatics() michael@0: { michael@0: } michael@0: michael@0: void michael@0: nsHtml5Portability::releaseStatics() michael@0: { michael@0: }