1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/xslt/xml/txXMLUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * An XML Utility class 1.11 +**/ 1.12 + 1.13 +#ifndef MITRE_XMLUTILS_H 1.14 +#define MITRE_XMLUTILS_H 1.15 + 1.16 +#include "txCore.h" 1.17 +#include "nsCOMPtr.h" 1.18 +#include "nsDependentSubstring.h" 1.19 +#include "nsIAtom.h" 1.20 +#include "txXPathNode.h" 1.21 + 1.22 +#define kExpatSeparatorChar 0xFFFF 1.23 + 1.24 +extern "C" int MOZ_XMLIsLetter(const char* ptr); 1.25 +extern "C" int MOZ_XMLIsNCNameChar(const char* ptr); 1.26 + 1.27 +class nsIAtom; 1.28 +class txNamespaceMap; 1.29 + 1.30 +class txExpandedName { 1.31 +public: 1.32 + txExpandedName() : mNamespaceID(kNameSpaceID_None) 1.33 + { 1.34 + } 1.35 + 1.36 + txExpandedName(int32_t aNsID, 1.37 + nsIAtom* aLocalName) : mNamespaceID(aNsID), 1.38 + mLocalName(aLocalName) 1.39 + { 1.40 + } 1.41 + 1.42 + txExpandedName(const txExpandedName& aOther) : 1.43 + mNamespaceID(aOther.mNamespaceID), 1.44 + mLocalName(aOther.mLocalName) 1.45 + { 1.46 + } 1.47 + 1.48 + nsresult init(const nsAString& aQName, txNamespaceMap* aResolver, 1.49 + bool aUseDefault); 1.50 + 1.51 + void reset() 1.52 + { 1.53 + mNamespaceID = kNameSpaceID_None; 1.54 + mLocalName = nullptr; 1.55 + } 1.56 + 1.57 + bool isNull() 1.58 + { 1.59 + return mNamespaceID == kNameSpaceID_None && !mLocalName; 1.60 + } 1.61 + 1.62 + txExpandedName& operator = (const txExpandedName& rhs) 1.63 + { 1.64 + mNamespaceID = rhs.mNamespaceID; 1.65 + mLocalName = rhs.mLocalName; 1.66 + return *this; 1.67 + } 1.68 + 1.69 + bool operator == (const txExpandedName& rhs) const 1.70 + { 1.71 + return ((mLocalName == rhs.mLocalName) && 1.72 + (mNamespaceID == rhs.mNamespaceID)); 1.73 + } 1.74 + 1.75 + bool operator != (const txExpandedName& rhs) const 1.76 + { 1.77 + return ((mLocalName != rhs.mLocalName) || 1.78 + (mNamespaceID != rhs.mNamespaceID)); 1.79 + } 1.80 + 1.81 + int32_t mNamespaceID; 1.82 + nsCOMPtr<nsIAtom> mLocalName; 1.83 +}; 1.84 + 1.85 +class XMLUtils { 1.86 + 1.87 +public: 1.88 + static nsresult splitExpatName(const char16_t *aExpatName, 1.89 + nsIAtom **aPrefix, nsIAtom **aLocalName, 1.90 + int32_t* aNameSpaceID); 1.91 + static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix, 1.92 + nsIAtom** aLocalName); 1.93 + 1.94 + /* 1.95 + * Returns true if the given character is whitespace. 1.96 + */ 1.97 + static bool isWhitespace(const char16_t& aChar) 1.98 + { 1.99 + return (aChar <= ' ' && 1.100 + (aChar == ' ' || aChar == '\r' || 1.101 + aChar == '\n'|| aChar == '\t')); 1.102 + } 1.103 + 1.104 + /** 1.105 + * Returns true if the given string has only whitespace characters 1.106 + */ 1.107 + static bool isWhitespace(const nsAFlatString& aText); 1.108 + 1.109 + /** 1.110 + * Normalizes the value of a XML processingInstruction 1.111 + **/ 1.112 + static void normalizePIValue(nsAString& attValue); 1.113 + 1.114 + /** 1.115 + * Returns true if the given string is a valid XML QName 1.116 + */ 1.117 + static bool isValidQName(const nsAFlatString& aQName, 1.118 + const char16_t** aColon); 1.119 + 1.120 + /** 1.121 + * Returns true if the given character represents an Alpha letter 1.122 + */ 1.123 + static bool isLetter(char16_t aChar) 1.124 + { 1.125 + return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar)); 1.126 + } 1.127 + 1.128 + /** 1.129 + * Returns true if the given character is an allowable NCName character 1.130 + */ 1.131 + static bool isNCNameChar(char16_t aChar) 1.132 + { 1.133 + return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar)); 1.134 + } 1.135 + 1.136 + /* 1.137 + * Walks up the document tree and returns true if the closest xml:space 1.138 + * attribute is "preserve" 1.139 + */ 1.140 + static bool getXMLSpacePreserve(const txXPathNode& aNode); 1.141 +}; 1.142 + 1.143 +#endif