2005-11-02 07:42:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00: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 08:19:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An XML Utility class
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef MITRE_XMLUTILS_H
|
|
|
|
#define MITRE_XMLUTILS_H
|
|
|
|
|
2005-11-02 07:42:16 +00:00
|
|
|
#include "txCore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-11-02 07:39:22 +00:00
|
|
|
#include "nsDependentSubstring.h"
|
2005-11-02 07:42:24 +00:00
|
|
|
#include "nsIAtom.h"
|
2005-11-02 07:41:43 +00:00
|
|
|
#include "txXPathNode.h"
|
2005-11-02 07:41:54 +00:00
|
|
|
|
2005-11-02 07:42:42 +00:00
|
|
|
#define kExpatSeparatorChar 0xFFFF
|
|
|
|
|
2012-03-15 04:56:58 +00:00
|
|
|
extern "C" int MOZ_XMLIsLetter(const char* ptr);
|
|
|
|
extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
|
|
|
|
|
2005-11-02 07:42:16 +00:00
|
|
|
class nsIAtom;
|
2005-11-02 07:40:09 +00:00
|
|
|
class txNamespaceMap;
|
|
|
|
|
2005-11-02 07:37:24 +00:00
|
|
|
class txExpandedName {
|
1999-08-28 08:19:56 +00:00
|
|
|
public:
|
2005-11-02 07:39:22 +00:00
|
|
|
txExpandedName() : mNamespaceID(kNameSpaceID_None)
|
2005-11-02 07:37:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
txExpandedName(int32_t aNsID,
|
2005-11-02 07:39:29 +00:00
|
|
|
nsIAtom* aLocalName) : mNamespaceID(aNsID),
|
|
|
|
mLocalName(aLocalName)
|
2005-11-02 07:37:26 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
txExpandedName(const txExpandedName& aOther) :
|
|
|
|
mNamespaceID(aOther.mNamespaceID),
|
|
|
|
mLocalName(aOther.mLocalName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-02 07:40:09 +00:00
|
|
|
nsresult init(const nsAString& aQName, txNamespaceMap* aResolver,
|
2011-11-10 19:26:13 +00:00
|
|
|
bool aUseDefault);
|
2005-11-02 07:40:09 +00:00
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
mNamespaceID = kNameSpaceID_None;
|
2012-07-30 14:20:58 +00:00
|
|
|
mLocalName = nullptr;
|
2005-11-02 07:40:09 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isNull()
|
2005-11-02 07:40:09 +00:00
|
|
|
{
|
|
|
|
return mNamespaceID == kNameSpaceID_None && !mLocalName;
|
|
|
|
}
|
2005-11-02 07:37:26 +00:00
|
|
|
|
|
|
|
txExpandedName& operator = (const txExpandedName& rhs)
|
|
|
|
{
|
|
|
|
mNamespaceID = rhs.mNamespaceID;
|
|
|
|
mLocalName = rhs.mLocalName;
|
|
|
|
return *this;
|
|
|
|
}
|
2005-11-02 07:37:24 +00:00
|
|
|
|
2011-11-10 19:26:13 +00:00
|
|
|
bool operator == (const txExpandedName& rhs) const
|
2005-11-02 07:37:24 +00:00
|
|
|
{
|
2005-11-02 07:37:26 +00:00
|
|
|
return ((mLocalName == rhs.mLocalName) &&
|
|
|
|
(mNamespaceID == rhs.mNamespaceID));
|
2005-11-02 07:37:24 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 19:26:13 +00:00
|
|
|
bool operator != (const txExpandedName& rhs) const
|
2005-11-02 07:37:24 +00:00
|
|
|
{
|
2005-11-02 07:37:26 +00:00
|
|
|
return ((mLocalName != rhs.mLocalName) ||
|
|
|
|
(mNamespaceID != rhs.mNamespaceID));
|
2005-11-02 07:37:24 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mNamespaceID;
|
2005-11-02 07:39:22 +00:00
|
|
|
nsCOMPtr<nsIAtom> mLocalName;
|
2005-11-02 07:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class XMLUtils {
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:37:24 +00:00
|
|
|
public:
|
2014-01-04 15:02:17 +00:00
|
|
|
static nsresult splitExpatName(const char16_t *aExpatName,
|
2005-11-02 07:42:27 +00:00
|
|
|
nsIAtom **aPrefix, nsIAtom **aLocalName,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* aNameSpaceID);
|
2005-11-02 07:42:27 +00:00
|
|
|
static nsresult splitQName(const nsAString& aName, nsIAtom** aPrefix,
|
|
|
|
nsIAtom** aLocalName);
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:38:03 +00:00
|
|
|
/*
|
|
|
|
* Returns true if the given character is whitespace.
|
|
|
|
*/
|
2014-01-04 15:02:17 +00:00
|
|
|
static bool isWhitespace(const char16_t& aChar)
|
2005-11-02 07:38:03 +00:00
|
|
|
{
|
|
|
|
return (aChar <= ' ' &&
|
|
|
|
(aChar == ' ' || aChar == '\r' ||
|
|
|
|
aChar == '\n'|| aChar == '\t'));
|
|
|
|
}
|
|
|
|
|
1999-11-15 07:13:17 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given string has only whitespace characters
|
2005-11-02 07:39:22 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isWhitespace(const nsAFlatString& aText);
|
2005-11-02 07:39:22 +00:00
|
|
|
|
1999-08-28 08:19:56 +00:00
|
|
|
/**
|
|
|
|
* Normalizes the value of a XML processingInstruction
|
|
|
|
**/
|
2005-11-02 07:39:22 +00:00
|
|
|
static void normalizePIValue(nsAString& attValue);
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the given string is a valid XML QName
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool isValidQName(const nsAFlatString& aQName,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t** aColon);
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
1999-08-28 08:19:56 +00:00
|
|
|
* Returns true if the given character represents an Alpha letter
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2014-01-04 15:02:17 +00:00
|
|
|
static bool isLetter(char16_t aChar)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
2012-03-15 04:56:58 +00:00
|
|
|
return !!MOZ_XMLIsLetter(reinterpret_cast<const char*>(&aChar));
|
|
|
|
}
|
1999-08-28 08:19:56 +00:00
|
|
|
|
2005-11-02 07:41:54 +00:00
|
|
|
/**
|
1999-08-28 08:19:56 +00:00
|
|
|
* Returns true if the given character is an allowable NCName character
|
2005-11-02 07:37:53 +00:00
|
|
|
*/
|
2014-01-04 15:02:17 +00:00
|
|
|
static bool isNCNameChar(char16_t aChar)
|
2005-11-02 07:41:54 +00:00
|
|
|
{
|
2012-03-15 04:56:58 +00:00
|
|
|
return !!MOZ_XMLIsNCNameChar(reinterpret_cast<const char*>(&aChar));
|
2005-11-02 07:41:54 +00:00
|
|
|
}
|
2005-11-02 07:38:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Walks up the document tree and returns true if the closest xml:space
|
|
|
|
* attribute is "preserve"
|
|
|
|
*/
|
2011-11-10 19:26:13 +00:00
|
|
|
static bool getXMLSpacePreserve(const txXPathNode& aNode);
|
2005-11-02 07:37:53 +00:00
|
|
|
};
|
1999-08-28 08:19:56 +00:00
|
|
|
|
|
|
|
#endif
|