gecko/parser/html/nsHtml5Portability.cpp
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

152 lines
3.6 KiB
C++

/* 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 "prtypes.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "jArray.h"
#include "nsHtml5Portability.h"
nsIAtom*
nsHtml5Portability::newLocalNameFromBuffer(PRUnichar* 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(PRUnichar* buf, int32_t offset, int32_t length)
{
return new nsString(buf + offset, length);
}
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<PRUnichar,int32_t>
nsHtml5Portability::newCharArrayFromLocal(nsIAtom* local)
{
nsAutoString temp;
local->ToString(temp);
int32_t len = temp.Length();
jArray<PRUnichar,int32_t> arr = jArray<PRUnichar,int32_t>::newJArray(len);
memcpy(arr, temp.BeginReading(), len * sizeof(PRUnichar));
return arr;
}
jArray<PRUnichar,int32_t>
nsHtml5Portability::newCharArrayFromString(nsString* string)
{
int32_t len = string->Length();
jArray<PRUnichar,int32_t> arr = jArray<PRUnichar,int32_t>::newJArray(len);
memcpy(arr, string->BeginReading(), len * sizeof(PRUnichar));
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, PRUnichar* 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 PRUnichar* strPtr = string->BeginReading();
const PRUnichar* end = string->EndReading();
PRUnichar litChar;
while ((litChar = *litPtr)) {
NS_ASSERTION(!(litChar >= 'A' && litChar <= 'Z'), "Literal isn't in lower case.");
if (strPtr == end) {
return false;
}
PRUnichar 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()
{
}