2005-11-02 10:42:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-28 12:19:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An XML Utility class
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef MITRE_XMLUTILS_H
|
|
|
|
#define MITRE_XMLUTILS_H
|
|
|
|
|
2005-11-02 10:42:16 +03:00
|
|
|
#include "txCore.h"
|
2005-11-02 10:39:22 +03:00
|
|
|
#include "nsDependentSubstring.h"
|
2005-11-02 10:41:43 +03:00
|
|
|
#include "txXPathNode.h"
|
2005-11-02 10:41:54 +03:00
|
|
|
|
2005-11-02 10:42:42 +03:00
|
|
|
#define kExpatSeparatorChar 0xFFFF
|
|
|
|
|
2012-03-15 08:56:58 +04:00
|
|
|
extern "C" int MOZ_XMLIsLetter(const char* ptr);
|
|
|
|
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
|
|
|
|
|
2005-11-02 10:42:16 +03:00
|
|
|
class nsIAtom;
|
2005-11-02 10:37:24 +03:00
|
|
|
|
|
|
|
class XMLUtils {
|
1999-08-28 12:19:56 +04:00
|
|
|
|
2005-11-02 10:37:24 +03:00
|
|
|
public:
|
2014-01-04 19:02:17 +04:00
|
|
|
static nsresult splitExpatName(const char16_t *aExpatName,
|
2005-11-02 10:42:27 +03:00
|
|
|
nsIAtom **aPrefix, nsIAtom **aLocalName,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* aNameSpaceID);
|
2005-11-02 10:42:27 +03:00
|
|
|
static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
|
|
|
|
nsIAtom** aLocalName);
|
1999-08-28 12:19:56 +04:00
|
|
|
|
2005-11-02 10:38:03 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the given character is whitespace.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool isWhitespace(const char16_t& aChar)
|
2005-11-02 10:38:03 +03:00
|
|
|
{
|
|
|
|
return (aChar <= ' ' &&
|
|
|
|
(aChar == ' ' || aChar == '\r' ||
|
|
|
|
aChar == '\n'|| aChar == '\t'));
|
|
|
|
}
|
|
|
|
|
1999-11-15 10:13:17 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the given string has only whitespace characters
|
2005-11-02 10:39:22 +03:00
|
|
|
*/
|
2017-06-20 12:19:05 +03:00
|
|
|
static bool isWhitespace(const nsString& aText);
|
2005-11-02 10:39:22 +03:00
|
|
|
|
1999-08-28 12:19:56 +04:00
|
|
|
/**
|
|
|
|
* Normalizes the value of a XML processingInstruction
|
|
|
|
**/
|
2005-11-02 10:39:22 +03:00
|
|
|
static void normalizePIValue(nsAString& attValue);
|
1999-08-28 12:19:56 +04:00
|
|
|
|
2005-11-02 10:41:54 +03:00
|
|
|
/**
|
|
|
|
* Returns true if the given string is a valid XML QName
|
2005-11-02 10:37:53 +03:00
|
|
|
*/
|
2017-06-20 12:19:05 +03:00
|
|
|
static bool isValidQName(const nsString& aQName, const char16_t** aColon);
|
1999-08-28 12:19:56 +04:00
|
|
|
|
2005-11-02 10:41:54 +03:00
|
|
|
/**
|
1999-08-28 12:19:56 +04:00
|
|
|
* Returns true if the given character represents an Alpha letter
|
2005-11-02 10:37:53 +03:00
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool isLetter(char16_t aChar)
|
2005-11-02 10:41:54 +03:00
|
|
|
{
|
2012-03-15 08:56:58 +04:00
|
|
|
return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
|
2017-07-06 15:00:35 +03:00
|
|
|
}
|
1999-08-28 12:19:56 +04:00
|
|
|
|
2005-11-02 10:41:54 +03:00
|
|
|
/**
|
1999-08-28 12:19:56 +04:00
|
|
|
* Returns true if the given character is an allowable NCName character
|
2005-11-02 10:37:53 +03:00
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool isNCNameChar(char16_t aChar)
|
2005-11-02 10:41:54 +03:00
|
|
|
{
|
2012-03-15 08:56:58 +04:00
|
|
|
return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
|
2005-11-02 10:41:54 +03:00
|
|
|
}
|
2005-11-02 10:38:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walks up the document tree and returns true if the closest xml:space
|
|
|
|
* attribute is "preserve"
|
|
|
|
*/
|
2011-11-10 23:26:13 +04:00
|
|
|
static bool getXMLSpacePreserve(const txXPathNode& aNode);
|
2005-11-02 10:37:53 +03:00
|
|
|
};
|
1999-08-28 12:19:56 +04:00
|
|
|
|
|
|
|
#endif
|