/* 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/. */
// static
nsHtml5String nsHtml5String::FromBuffer(char16_t* aBuffer, int32_t aLength,
nsHtml5TreeBuilder* aTreeBuilder) { if (!aLength) { return nsHtml5String(eEmpty);
} // Work with StringBuffer directly to make sure that storage is actually // StringBuffer and to make sure the allocation strategy matches // nsAttrValue::GetStringBuffer, so that it doesn't need to reallocate and // copy.
RefPtr<StringBuffer> buffer = StringBuffer::Create(aBuffer, aLength); if (MOZ_UNLIKELY(!buffer)) { if (!aTreeBuilder) {
MOZ_CRASH("Out of memory.");
}
aTreeBuilder->MarkAsBroken(NS_ERROR_OUT_OF_MEMORY);
buffer = StringBuffer::Alloc(2 * sizeof(char16_t)); if (!buffer) {
MOZ_CRASH( "Out of memory so badly that couldn't even allocate placeholder.");
}
char16_t* data = reinterpret_cast<char16_t*>(buffer->Data());
data[0] = 0xFFFD;
data[1] = 0;
} return nsHtml5String(reinterpret_cast<uintptr_t>(buffer.forget().take()) |
eStringBuffer);
}
// static
nsHtml5String nsHtml5String::FromLiteral(constchar* aLiteral) {
size_t length = std::strlen(aLiteral); if (!length) { return nsHtml5String(eEmpty);
} // Work with StringBuffer directly to make sure that storage is actually // StringBuffer and to make sure the allocation strategy matches // nsAttrValue::GetStringBuffer, so that it doesn't need to reallocate and // copy.
RefPtr<StringBuffer> buffer(
StringBuffer::Alloc((length + 1) * sizeof(char16_t))); if (!buffer) {
MOZ_CRASH("Out of memory.");
}
char16_t* data = reinterpret_cast<char16_t*>(buffer->Data());
ConvertAsciitoUtf16(mozilla::Span(aLiteral, length),
mozilla::Span(data, length));
data[length] = 0; return nsHtml5String(reinterpret_cast<uintptr_t>(buffer.forget().take()) |
eStringBuffer);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.