dom/xslt/xml/txXMLUtils.h

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

mercurial