michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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: /** michael@0: * An XML Utility class michael@0: **/ michael@0: michael@0: #ifndef MITRE_XMLUTILS_H michael@0: #define MITRE_XMLUTILS_H michael@0: michael@0: #include "txCore.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsDependentSubstring.h" michael@0: #include "nsIAtom.h" michael@0: #include "txXPathNode.h" michael@0: michael@0: #define kExpatSeparatorChar 0xFFFF michael@0: michael@0: extern "C" int MOZ_XMLIsLetter(const char* ptr); michael@0: extern "C" int MOZ_XMLIsNCNameChar(const char* ptr); michael@0: michael@0: class nsIAtom; michael@0: class txNamespaceMap; michael@0: michael@0: class txExpandedName { michael@0: public: michael@0: txExpandedName() : mNamespaceID(kNameSpaceID_None) michael@0: { michael@0: } michael@0: michael@0: txExpandedName(int32_t aNsID, michael@0: nsIAtom* aLocalName) : mNamespaceID(aNsID), michael@0: mLocalName(aLocalName) michael@0: { michael@0: } michael@0: michael@0: txExpandedName(const txExpandedName& aOther) : michael@0: mNamespaceID(aOther.mNamespaceID), michael@0: mLocalName(aOther.mLocalName) michael@0: { michael@0: } michael@0: michael@0: nsresult init(const nsAString& aQName, txNamespaceMap* aResolver, michael@0: bool aUseDefault); michael@0: michael@0: void reset() michael@0: { michael@0: mNamespaceID = kNameSpaceID_None; michael@0: mLocalName = nullptr; michael@0: } michael@0: michael@0: bool isNull() michael@0: { michael@0: return mNamespaceID == kNameSpaceID_None && !mLocalName; michael@0: } michael@0: michael@0: txExpandedName& operator = (const txExpandedName& rhs) michael@0: { michael@0: mNamespaceID = rhs.mNamespaceID; michael@0: mLocalName = rhs.mLocalName; michael@0: return *this; michael@0: } michael@0: michael@0: bool operator == (const txExpandedName& rhs) const michael@0: { michael@0: return ((mLocalName == rhs.mLocalName) && michael@0: (mNamespaceID == rhs.mNamespaceID)); michael@0: } michael@0: michael@0: bool operator != (const txExpandedName& rhs) const michael@0: { michael@0: return ((mLocalName != rhs.mLocalName) || michael@0: (mNamespaceID != rhs.mNamespaceID)); michael@0: } michael@0: michael@0: int32_t mNamespaceID; michael@0: nsCOMPtr mLocalName; michael@0: }; michael@0: michael@0: class XMLUtils { michael@0: michael@0: public: michael@0: static nsresult splitExpatName(const char16_t *aExpatName, michael@0: nsIAtom **aPrefix, nsIAtom **aLocalName, michael@0: int32_t* aNameSpaceID); michael@0: static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix, michael@0: nsIAtom** aLocalName); michael@0: michael@0: /* michael@0: * Returns true if the given character is whitespace. michael@0: */ michael@0: static bool isWhitespace(const char16_t& aChar) michael@0: { michael@0: return (aChar <= ' ' && michael@0: (aChar == ' ' || aChar == '\r' || michael@0: aChar == '\n'|| aChar == '\t')); michael@0: } michael@0: michael@0: /** michael@0: * Returns true if the given string has only whitespace characters michael@0: */ michael@0: static bool isWhitespace(const nsAFlatString& aText); michael@0: michael@0: /** michael@0: * Normalizes the value of a XML processingInstruction michael@0: **/ michael@0: static void normalizePIValue(nsAString& attValue); michael@0: michael@0: /** michael@0: * Returns true if the given string is a valid XML QName michael@0: */ michael@0: static bool isValidQName(const nsAFlatString& aQName, michael@0: const char16_t** aColon); michael@0: michael@0: /** michael@0: * Returns true if the given character represents an Alpha letter michael@0: */ michael@0: static bool isLetter(char16_t aChar) michael@0: { michael@0: return !!MOZ_XMLIsLetter(reinterpret_cast(&aChar)); michael@0: } michael@0: michael@0: /** michael@0: * Returns true if the given character is an allowable NCName character michael@0: */ michael@0: static bool isNCNameChar(char16_t aChar) michael@0: { michael@0: return !!MOZ_XMLIsNCNameChar(reinterpret_cast(&aChar)); michael@0: } michael@0: michael@0: /* michael@0: * Walks up the document tree and returns true if the closest xml:space michael@0: * attribute is "preserve" michael@0: */ michael@0: static bool getXMLSpacePreserve(const txXPathNode& aNode); michael@0: }; michael@0: michael@0: #endif