Bug 122001. Implement txExpandedNameMap. Add QName parsing and some operators to txExpandedName.

r=peterv sr=jst a=asa
This commit is contained in:
sicking%bigfoot.com 2005-11-02 07:37:26 +00:00
parent c8066d4eaa
commit 8d0ed41f75
4 changed files with 82 additions and 24 deletions

View File

@ -31,6 +31,9 @@ MODULE = transformiix
REQUIRES = string \
xpcom \
unicharutil \
dom \
content \
widget \
$(NULL)
endif
@ -44,7 +47,8 @@ CPPSRCS = ArrayList.cpp \
Stack.cpp \
StringList.cpp \
Tokenizer.cpp \
txAtoms.cpp
txAtoms.cpp \
txExpandedNameMap.cpp
ifdef TX_EXE
CPPSRCS += CommandLineUtils.cpp \
@ -55,6 +59,7 @@ endif
include $(topsrcdir)/config/rules.mk
INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt
INCLUDES += -I$(srcdir)/../xpath -I$(srcdir)/../xslt -I$(srcdir)/../xml \
-I$(srcdir)/../xml/dom
libs:: $(OBJS)

View File

@ -40,6 +40,7 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
../base/StringList.$(OBJ_SUFFIX) \
../base/Tokenizer.$(OBJ_SUFFIX) \
../base/txAtoms.$(OBJ_SUFFIX) \
../base/txExpandedNameMap.$(OBJ_SUFFIX) \
../base/TxString.$(OBJ_SUFFIX) \
../net/URIUtils.$(OBJ_SUFFIX) \
../xml/dom/standalone/Attr.$(OBJ_SUFFIX) \

View File

@ -31,17 +31,37 @@
#include "XMLUtils.h"
txExpandedName::txExpandedName(PRInt32 aNsID,
txAtom* aLocalName) : mNamespaceID(aNsID),
mLocalName(aLocalName)
nsresult txExpandedName::init(const String& aQName,
Node* aResolver,
MBool aUseDefault)
{
if (mLocalName)
TX_ADDREF_ATOM(mLocalName);
}
NS_ASSERTION(aResolver, "missing resolve node");
if (!XMLUtils::isValidQName(aQName))
return NS_ERROR_FAILURE;
txExpandedName::~txExpandedName()
{
TX_IF_RELEASE_ATOM(mLocalName);
int idx = aQName.indexOf(':');
if (idx >= 0) {
String localName, prefixStr;
aQName.subString(0, idx, prefixStr);
txAtom* prefix = TX_GET_ATOM(prefixStr);
PRInt32 namespaceID = aResolver->lookupNamespaceID(prefix);
if (namespaceID == kNameSpaceID_Unknown)
return NS_ERROR_FAILURE;
mNamespaceID = namespaceID;
aQName.subString(idx+1, localName);
TX_IF_RELEASE_ATOM(mLocalName);
mLocalName = TX_GET_ATOM(localName);
}
else {
TX_IF_RELEASE_ATOM(mLocalName);
mLocalName = TX_GET_ATOM(aQName);
if (aUseDefault)
mNamespaceID = aResolver->lookupNamespaceID(0);
else
mNamespaceID = kNameSpaceID_None;
}
return NS_OK;
}
//------------------------------/
@ -111,7 +131,7 @@ MBool XMLUtils::isQNameChar(PRInt32 ch) {
/**
* Returns true if the given String is a valid XML QName
**/
MBool XMLUtils::isValidQName(String& name) {
MBool XMLUtils::isValidQName(const String& name) {
if (name.isEmpty())
return MB_FALSE;

View File

@ -32,26 +32,58 @@
#include "baseutils.h"
#include "txAtom.h"
#include "dom.h"
#include "txError.h"
class String;
class txExpandedName {
public:
txExpandedName(PRInt32 aNsID, txAtom* aLocalName);
~txExpandedName();
MBool
operator == (const txExpandedName& rhs)
txExpandedName() : mNamespaceID(kNameSpaceID_None),
mLocalName(0)
{
return ((mNamespaceID == rhs.mNamespaceID) &&
(mLocalName == rhs.mLocalName));
}
MBool
operator != (const txExpandedName& rhs)
txExpandedName(PRInt32 aNsID,
txAtom* aLocalName) : mNamespaceID(aNsID),
mLocalName(aLocalName)
{
return ((mNamespaceID != rhs.mNamespaceID) ||
(mLocalName != rhs.mLocalName));
TX_IF_ADDREF_ATOM(mLocalName);
}
txExpandedName(const txExpandedName& aOther) :
mNamespaceID(aOther.mNamespaceID),
mLocalName(aOther.mLocalName)
{
TX_IF_ADDREF_ATOM(mLocalName);
}
~txExpandedName()
{
TX_IF_RELEASE_ATOM(mLocalName);
}
nsresult init(const String& aQName, Node* aResolver, MBool aUseDefault);
txExpandedName& operator = (const txExpandedName& rhs)
{
mNamespaceID = rhs.mNamespaceID;
TX_IF_RELEASE_ATOM(mLocalName);
mLocalName = rhs.mLocalName;
TX_IF_ADDREF_ATOM(mLocalName);
return *this;
}
MBool operator == (const txExpandedName& rhs) const
{
return ((mLocalName == rhs.mLocalName) &&
(mNamespaceID == rhs.mNamespaceID));
}
MBool operator != (const txExpandedName& rhs) const
{
return ((mLocalName != rhs.mLocalName) ||
(mNamespaceID != rhs.mNamespaceID));
}
PRInt32 mNamespaceID;
@ -69,7 +101,7 @@ public:
/**
* Returns true if the given String is a valid XML QName
**/
static MBool isValidQName(String& name);
static MBool isValidQName(const String& name);
/**
* Returns true if the given string has only whitespace characters