txXMLUtils.h (2141B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 "nsDependentSubstring.h" 14 #include "txCore.h" 15 #include "txXPathNode.h" 16 17 #define kExpatSeparatorChar 0xFFFF 18 19 extern "C" int MOZ_XMLIsLetter(const char* ptr); 20 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr); 21 22 class nsAtom; 23 24 class XMLUtils { 25 public: 26 static nsresult splitExpatName(const char16_t* aExpatName, nsAtom** aPrefix, 27 nsAtom** aLocalName, int32_t* aNameSpaceID); 28 static nsresult splitQName(const nsAString& aName, nsAtom** aPrefix, 29 nsAtom** aLocalName); 30 31 /* 32 * Returns true if the given character is whitespace. 33 */ 34 static bool isWhitespace(const char16_t& aChar) { 35 return (aChar <= ' ' && 36 (aChar == ' ' || aChar == '\r' || aChar == '\n' || aChar == '\t')); 37 } 38 39 /** 40 * Returns true if the given string has only whitespace characters 41 */ 42 static bool isWhitespace(const nsAString& aText); 43 44 /** 45 * Normalizes the value of a XML processingInstruction 46 **/ 47 static void normalizePIValue(nsAString& attValue); 48 49 /** 50 * Returns true if the given string is a valid XML QName 51 */ 52 static bool isValidQName(const nsAString& aQName, const char16_t** aColon); 53 54 /** 55 * Returns true if the given character represents an Alpha letter 56 */ 57 static bool isLetter(char16_t aChar) { 58 return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar)); 59 } 60 61 /** 62 * Returns true if the given character is an allowable NCName character 63 */ 64 static bool isNCNameChar(char16_t aChar) { 65 return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar)); 66 } 67 68 /* 69 * Walks up the document tree and returns true if the closest xml:space 70 * attribute is "preserve" 71 */ 72 static bool getXMLSpacePreserve(const txXPathNode& aNode); 73 }; 74 75 #endif