Files
firefox/content/base/src/nsXMLNameSpaceMap.cpp
T
Ehsan Akhgari 243c878d26 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

109 lines
2.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
/*
* A class for keeping track of prefix-to-namespace-id mappings
*/
#include "nsXMLNameSpaceMap.h"
#include "nsINameSpaceManager.h"
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
template <>
class nsDefaultComparator <nsNameSpaceEntry, nsIAtom*> {
public:
bool Equals(const nsNameSpaceEntry& aEntry, nsIAtom* const& aPrefix) const {
return aEntry.prefix == aPrefix;
}
};
template <>
class nsDefaultComparator <nsNameSpaceEntry, int32_t> {
public:
bool Equals(const nsNameSpaceEntry& aEntry, const int32_t& aNameSpace) const {
return aEntry.nameSpaceID == aNameSpace;
}
};
/* static */ nsXMLNameSpaceMap*
nsXMLNameSpaceMap::Create(bool aForXML)
{
nsXMLNameSpaceMap *map = new nsXMLNameSpaceMap();
NS_ENSURE_TRUE(map, nullptr);
if (aForXML) {
nsresult rv1 = map->AddPrefix(nsGkAtoms::xmlns,
kNameSpaceID_XMLNS);
nsresult rv2 = map->AddPrefix(nsGkAtoms::xml, kNameSpaceID_XML);
if (NS_FAILED(rv1) || NS_FAILED(rv2)) {
delete map;
map = nullptr;
}
}
return map;
}
nsXMLNameSpaceMap::nsXMLNameSpaceMap()
: mNameSpaces(4)
{
}
nsresult
nsXMLNameSpaceMap::AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID)
{
if (!mNameSpaces.Contains(aPrefix) && !mNameSpaces.AppendElement(aPrefix)) {
return NS_ERROR_OUT_OF_MEMORY;
}
mNameSpaces[mNameSpaces.IndexOf(aPrefix)].nameSpaceID = aNameSpaceID;
return NS_OK;
}
nsresult
nsXMLNameSpaceMap::AddPrefix(nsIAtom *aPrefix, nsString &aURI)
{
int32_t id;
nsresult rv = nsContentUtils::NameSpaceManager()->RegisterNameSpace(aURI,
id);
NS_ENSURE_SUCCESS(rv, rv);
return AddPrefix(aPrefix, id);
}
int32_t
nsXMLNameSpaceMap::FindNameSpaceID(nsIAtom *aPrefix) const
{
uint32_t index = mNameSpaces.IndexOf(aPrefix);
if (index != mNameSpaces.NoIndex) {
return mNameSpaces[index].nameSpaceID;
}
// The default mapping for no prefix is no namespace. If a non-null prefix
// was specified and we didn't find it, we return an error.
return aPrefix ? kNameSpaceID_Unknown : kNameSpaceID_None;
}
nsIAtom*
nsXMLNameSpaceMap::FindPrefix(int32_t aNameSpaceID) const
{
uint32_t index = mNameSpaces.IndexOf(aNameSpaceID);
if (index != mNameSpaces.NoIndex) {
return mNameSpaces[index].prefix;
}
return nullptr;
}
void
nsXMLNameSpaceMap::Clear()
{
mNameSpaces.Clear();
}