dom/xslt/xml/txXMLUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /**
michael@0 7 * An XML Utility class
michael@0 8 **/
michael@0 9
michael@0 10 #ifndef MITRE_XMLUTILS_H
michael@0 11 #define MITRE_XMLUTILS_H
michael@0 12
michael@0 13 #include "txCore.h"
michael@0 14 #include "nsCOMPtr.h"
michael@0 15 #include "nsDependentSubstring.h"
michael@0 16 #include "nsIAtom.h"
michael@0 17 #include "txXPathNode.h"
michael@0 18
michael@0 19 #define kExpatSeparatorChar 0xFFFF
michael@0 20
michael@0 21 extern "C" int MOZ_XMLIsLetter(const char* ptr);
michael@0 22 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
michael@0 23
michael@0 24 class nsIAtom;
michael@0 25 class txNamespaceMap;
michael@0 26
michael@0 27 class txExpandedName {
michael@0 28 public:
michael@0 29 txExpandedName() : mNamespaceID(kNameSpaceID_None)
michael@0 30 {
michael@0 31 }
michael@0 32
michael@0 33 txExpandedName(int32_t aNsID,
michael@0 34 nsIAtom* aLocalName) : mNamespaceID(aNsID),
michael@0 35 mLocalName(aLocalName)
michael@0 36 {
michael@0 37 }
michael@0 38
michael@0 39 txExpandedName(const txExpandedName& aOther) :
michael@0 40 mNamespaceID(aOther.mNamespaceID),
michael@0 41 mLocalName(aOther.mLocalName)
michael@0 42 {
michael@0 43 }
michael@0 44
michael@0 45 nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
michael@0 46 bool aUseDefault);
michael@0 47
michael@0 48 void reset()
michael@0 49 {
michael@0 50 mNamespaceID = kNameSpaceID_None;
michael@0 51 mLocalName = nullptr;
michael@0 52 }
michael@0 53
michael@0 54 bool isNull()
michael@0 55 {
michael@0 56 return mNamespaceID == kNameSpaceID_None && !mLocalName;
michael@0 57 }
michael@0 58
michael@0 59 txExpandedName& operator = (const txExpandedName& rhs)
michael@0 60 {
michael@0 61 mNamespaceID = rhs.mNamespaceID;
michael@0 62 mLocalName = rhs.mLocalName;
michael@0 63 return *this;
michael@0 64 }
michael@0 65
michael@0 66 bool operator == (const txExpandedName& rhs) const
michael@0 67 {
michael@0 68 return ((mLocalName == rhs.mLocalName) &&
michael@0 69 (mNamespaceID == rhs.mNamespaceID));
michael@0 70 }
michael@0 71
michael@0 72 bool operator != (const txExpandedName& rhs) const
michael@0 73 {
michael@0 74 return ((mLocalName != rhs.mLocalName) ||
michael@0 75 (mNamespaceID != rhs.mNamespaceID));
michael@0 76 }
michael@0 77
michael@0 78 int32_t mNamespaceID;
michael@0 79 nsCOMPtr<nsIAtom> mLocalName;
michael@0 80 };
michael@0 81
michael@0 82 class XMLUtils {
michael@0 83
michael@0 84 public:
michael@0 85 static nsresult splitExpatName(const char16_t *aExpatName,
michael@0 86 nsIAtom **aPrefix, nsIAtom **aLocalName,
michael@0 87 int32_t* aNameSpaceID);
michael@0 88 static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
michael@0 89 nsIAtom** aLocalName);
michael@0 90
michael@0 91 /*
michael@0 92 * Returns true if the given character is whitespace.
michael@0 93 */
michael@0 94 static bool isWhitespace(const char16_t& aChar)
michael@0 95 {
michael@0 96 return (aChar <= ' ' &&
michael@0 97 (aChar == ' ' || aChar == '\r' ||
michael@0 98 aChar == '\n'|| aChar == '\t'));
michael@0 99 }
michael@0 100
michael@0 101 /**
michael@0 102 * Returns true if the given string has only whitespace characters
michael@0 103 */
michael@0 104 static bool isWhitespace(const nsAFlatString& aText);
michael@0 105
michael@0 106 /**
michael@0 107 * Normalizes the value of a XML processingInstruction
michael@0 108 **/
michael@0 109 static void normalizePIValue(nsAString& attValue);
michael@0 110
michael@0 111 /**
michael@0 112 * Returns true if the given string is a valid XML QName
michael@0 113 */
michael@0 114 static bool isValidQName(const nsAFlatString& aQName,
michael@0 115 const char16_t** aColon);
michael@0 116
michael@0 117 /**
michael@0 118 * Returns true if the given character represents an Alpha letter
michael@0 119 */
michael@0 120 static bool isLetter(char16_t aChar)
michael@0 121 {
michael@0 122 return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
michael@0 123 }
michael@0 124
michael@0 125 /**
michael@0 126 * Returns true if the given character is an allowable NCName character
michael@0 127 */
michael@0 128 static bool isNCNameChar(char16_t aChar)
michael@0 129 {
michael@0 130 return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
michael@0 131 }
michael@0 132
michael@0 133 /*
michael@0 134 * Walks up the document tree and returns true if the closest xml:space
michael@0 135 * attribute is "preserve"
michael@0 136 */
michael@0 137 static bool getXMLSpacePreserve(const txXPathNode& aNode);
michael@0 138 };
michael@0 139
michael@0 140 #endif

mercurial