зеркало из https://github.com/mozilla/gecko-dev.git
Fix for bug 74786 (String cleanup). Remove Transformiix string wrappers. r=sicking, sr=jst. r=Pike on the Transformiix standalone parts.
This commit is contained in:
Родитель
79bd15a52c
Коммит
f8454450e6
|
@ -42,22 +42,20 @@ REQUIRES += unicharutil \
|
|||
$(NULL)
|
||||
endif
|
||||
|
||||
CPPSRCS = ArrayList.cpp \
|
||||
Double.cpp \
|
||||
CPPSRCS = Double.cpp \
|
||||
List.cpp \
|
||||
Map.cpp \
|
||||
NamedMap.cpp \
|
||||
SimpleErrorObserver.cpp \
|
||||
Stack.cpp \
|
||||
StringList.cpp \
|
||||
Tokenizer.cpp \
|
||||
txAtoms.cpp \
|
||||
txExpandedNameMap.cpp \
|
||||
txStringUtils.cpp \
|
||||
txURIUtils.cpp
|
||||
|
||||
ifdef TX_EXE
|
||||
CPPSRCS += CommandLineUtils.cpp \
|
||||
TxString.cpp
|
||||
CPPSRCS += txStringUtils.cpp
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#define TRANSFRMX_ATOMS_H
|
||||
|
||||
#include "txAtom.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
/*
|
||||
* Declare all atoms
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "nsString.h"
|
||||
#include "primitives.h"
|
||||
#include "XMLUtils.h"
|
||||
#include <math.h>
|
||||
|
@ -226,12 +227,11 @@ private:
|
|||
} mSign;
|
||||
};
|
||||
|
||||
double Double::toDouble(const String& aSrc)
|
||||
double Double::toDouble(const nsAString& aSrc)
|
||||
{
|
||||
txStringToDouble sink;
|
||||
nsAString::const_iterator fromBegin, fromEnd;
|
||||
const nsAString& str = aSrc.getConstNSString();
|
||||
copy_string(str.BeginReading(fromBegin), str.EndReading(fromEnd), sink);
|
||||
copy_string(aSrc.BeginReading(fromBegin), aSrc.EndReading(fromEnd), sink);
|
||||
return sink.getDouble();
|
||||
}
|
||||
|
||||
|
@ -240,20 +240,20 @@ double Double::toDouble(const String& aSrc)
|
|||
* The result into the destination String.
|
||||
* @return the given dest string
|
||||
*/
|
||||
String& Double::toString(double aValue, String& aDest)
|
||||
void Double::toString(double aValue, nsAString& aDest)
|
||||
{
|
||||
|
||||
// check for special cases
|
||||
|
||||
if (isNaN(aValue)) {
|
||||
aDest.Append(NS_LITERAL_STRING("NaN"));
|
||||
return aDest;
|
||||
return;
|
||||
}
|
||||
if (isInfinite(aValue)) {
|
||||
if (aValue < 0)
|
||||
aDest.Append(PRUnichar('-'));
|
||||
aDest.Append(NS_LITERAL_STRING("Infinity"));
|
||||
return aDest;
|
||||
return;
|
||||
}
|
||||
|
||||
int bufsize;
|
||||
|
@ -265,7 +265,7 @@ String& Double::toString(double aValue, String& aDest)
|
|||
char* buf = new char[bufsize];
|
||||
if (!buf) {
|
||||
NS_ASSERTION(0, "out of memory");
|
||||
return aDest;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef TX_EXE
|
||||
|
@ -319,6 +319,4 @@ String& Double::toString(double aValue, String& aDest)
|
|||
#endif
|
||||
|
||||
delete [] buf;
|
||||
|
||||
return aDest;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,7 @@
|
|||
#include "baseutils.h"
|
||||
#include "txError.h"
|
||||
#include <iostream.h>
|
||||
|
||||
class String;
|
||||
class nsAString;
|
||||
|
||||
/**
|
||||
* A simple interface for observing errors
|
||||
|
@ -47,13 +46,13 @@ public:
|
|||
/**
|
||||
* Notifies this Error observer of a new error aRes
|
||||
**/
|
||||
virtual void receiveError(const String& errorMessage, nsresult aRes) = 0;
|
||||
virtual void receiveError(const nsAString& errorMessage, nsresult aRes) = 0;
|
||||
|
||||
/**
|
||||
* Notifies this Error observer of a new error, with default
|
||||
* error code NS_ERROR_FAILURE
|
||||
**/
|
||||
void receiveError(String& errorMessage)
|
||||
void receiveError(const nsAString& errorMessage)
|
||||
{
|
||||
receiveError(errorMessage, NS_ERROR_FAILURE);
|
||||
}
|
||||
|
@ -86,7 +85,7 @@ public:
|
|||
/**
|
||||
* Notifies this Error observer of a new error aRes
|
||||
**/
|
||||
void receiveError(const String& errorMessage, nsresult aRes);
|
||||
void receiveError(const nsAString& errorMessage, nsresult aRes);
|
||||
|
||||
virtual void supressWarnings(MBool supress);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
*/
|
||||
|
||||
#include "ErrorObserver.h"
|
||||
#include "TxString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/**
|
||||
* Creates a new SimpleErrorObserver.
|
||||
|
@ -49,7 +49,7 @@ SimpleErrorObserver::SimpleErrorObserver(ostream& errStream) {
|
|||
/**
|
||||
* Notifies this Error observer of a new error using the given error level
|
||||
**/
|
||||
void SimpleErrorObserver::receiveError(const String& errorMessage,
|
||||
void SimpleErrorObserver::receiveError(const nsAString& errorMessage,
|
||||
nsresult aRes)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
|
@ -57,7 +57,7 @@ void SimpleErrorObserver::receiveError(const String& errorMessage,
|
|||
*errStream << "error: ";
|
||||
}
|
||||
|
||||
*errStream << errorMessage << endl;
|
||||
*errStream << NS_LossyConvertUCS2toASCII(errorMessage).get() << endl;
|
||||
errStream->flush();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -0,0 +1,153 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Axel Hecht <axel@pike.org>
|
||||
* Peter Van der Beken <peterv@netscape.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txStringUtils.h"
|
||||
|
||||
int
|
||||
txCaseInsensitiveStringComparator::operator()(const char_type* lhs,
|
||||
const char_type* rhs,
|
||||
PRUint32 aLength ) const
|
||||
{
|
||||
PRUnichar thisChar, otherChar;
|
||||
PRUint32 compLoop = 0;
|
||||
while (compLoop < aLength) {
|
||||
thisChar = lhs[compLoop];
|
||||
if ((thisChar >= 'A') && (thisChar <= 'Z')) {
|
||||
thisChar += 32;
|
||||
}
|
||||
otherChar = rhs[compLoop];
|
||||
if ((otherChar >= 'A') && (otherChar <= 'Z')) {
|
||||
otherChar += 32;
|
||||
}
|
||||
if (thisChar != otherChar) {
|
||||
return thisChar - otherChar;
|
||||
}
|
||||
++compLoop;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
txCaseInsensitiveStringComparator::operator()(char_type lhs,
|
||||
char_type rhs) const
|
||||
{
|
||||
if (lhs >= 'A' && lhs <= 'Z') {
|
||||
lhs += 32;
|
||||
}
|
||||
if (rhs >= 'A' && rhs <= 'Z') {
|
||||
rhs += 32;
|
||||
}
|
||||
return lhs - rhs;
|
||||
}
|
||||
|
||||
/**
|
||||
* A character sink for case conversion.
|
||||
*/
|
||||
class ConvertToLowerCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
PRUint32 write( const PRUnichar* aSource, PRUint32 aSourceLength)
|
||||
{
|
||||
PRUnichar* cp = NS_CONST_CAST(PRUnichar*, aSource);
|
||||
const PRUnichar* end = aSource + aSourceLength;
|
||||
while (cp != end) {
|
||||
PRUnichar ch = *cp;
|
||||
if ((ch >= 'A') && (ch <= 'Z'))
|
||||
*cp = ch + ('a' - 'A');
|
||||
++cp;
|
||||
}
|
||||
return aSourceLength;
|
||||
}
|
||||
};
|
||||
|
||||
void TX_ToLowerCase(nsAString& aString)
|
||||
{
|
||||
nsAString::iterator fromBegin, fromEnd;
|
||||
ConvertToLowerCase converter;
|
||||
copy_string(aString.BeginWriting(fromBegin), aString.EndWriting(fromEnd),
|
||||
converter);
|
||||
}
|
||||
|
||||
/**
|
||||
* A character sink for copying with case conversion.
|
||||
*/
|
||||
class CopyToLowerCase
|
||||
{
|
||||
public:
|
||||
typedef PRUnichar value_type;
|
||||
|
||||
CopyToLowerCase(nsAString::iterator& aDestIter) : mIter(aDestIter)
|
||||
{
|
||||
}
|
||||
|
||||
PRUint32 write(const PRUnichar* aSource, PRUint32 aSourceLength)
|
||||
{
|
||||
PRUint32 len = PR_MIN(PRUint32(mIter.size_forward()), aSourceLength);
|
||||
PRUnichar* cp = mIter.get();
|
||||
const PRUnichar* end = aSource + len;
|
||||
while (aSource != end) {
|
||||
PRUnichar ch = *aSource;
|
||||
if ((ch >= 'A') && (ch <= 'Z'))
|
||||
*cp = ch + ('a' - 'A');
|
||||
else
|
||||
*cp = ch;
|
||||
++aSource;
|
||||
++cp;
|
||||
}
|
||||
mIter.advance(len);
|
||||
return len;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsAString::iterator& mIter;
|
||||
};
|
||||
|
||||
void TX_ToLowerCase(const nsAString& aSource, nsAString& aDest)
|
||||
{
|
||||
nsAString::const_iterator fromBegin, fromEnd;
|
||||
nsAString::iterator toBegin;
|
||||
aDest.SetLength(aSource.Length());
|
||||
CopyToLowerCase converter(aDest.BeginWriting(toBegin));
|
||||
copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
|
||||
converter);
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Axel Hecht <axel@pike.org>
|
||||
* Peter Van der Beken <peterv@netscape.com>
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef txStringUtils_h__
|
||||
#define txStringUtils_h__
|
||||
|
||||
#include "nsAString.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
#ifndef TX_EXE
|
||||
|
||||
#include "nsUnicharUtils.h"
|
||||
typedef nsCaseInsensitiveStringComparator txCaseInsensitiveStringComparator;
|
||||
|
||||
#define TX_ToLowerCase ToLowerCase
|
||||
|
||||
#else
|
||||
|
||||
// These only work for ASCII ranges!
|
||||
|
||||
class txCaseInsensitiveStringComparator
|
||||
: public nsStringComparator
|
||||
{
|
||||
public:
|
||||
virtual int operator()(const char_type*, const char_type*, PRUint32 aLength) const;
|
||||
virtual int operator()(char_type, char_type) const;
|
||||
};
|
||||
|
||||
void TX_ToLowerCase(nsAString& aString);
|
||||
void TX_ToLowerCase(const nsAString& aSource, nsAString& aDest);
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Check equality between a string and an atom.
|
||||
*/
|
||||
static PRBool TX_StringEqualsAtom(const nsAString& aString, nsIAtom* aAtom)
|
||||
{
|
||||
const PRUnichar* atom;
|
||||
aAtom->GetUnicode(&atom);
|
||||
return aString.Equals(atom);
|
||||
};
|
||||
|
||||
#endif // txStringUtils_h__
|
|
@ -50,16 +50,10 @@
|
|||
#ifdef TX_EXE
|
||||
//- Constants -/
|
||||
|
||||
const String URIUtils::HTTP_PROTOCOL(NS_LITERAL_STRING("http"));
|
||||
const String URIUtils::FILE_PROTOCOL(NS_LITERAL_STRING("file"));
|
||||
const char URIUtils::HREF_PATH_SEP = '/';
|
||||
const char URIUtils::DEVICE_SEP = '|';
|
||||
const char URIUtils::PORT_SEP = ':';
|
||||
const char URIUtils::PROTOCOL_SEP = ':';
|
||||
const short URIUtils::PROTOCOL_MODE = 1;
|
||||
const short URIUtils::HOST_MODE = 2;
|
||||
const short URIUtils::PORT_MODE = 3;
|
||||
const short URIUtils::PATH_MODE = 4;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -70,8 +64,7 @@ const short URIUtils::PATH_MODE = 4;
|
|||
* @exception java.io.FileNotFoundException when the file could not be
|
||||
* found
|
||||
**/
|
||||
istream* URIUtils::getInputStream
|
||||
(const String& href, String& errMsg)
|
||||
istream* URIUtils::getInputStream(const nsAString& href, nsAString& errMsg)
|
||||
{
|
||||
|
||||
istream* inStream = 0;
|
||||
|
@ -95,31 +88,22 @@ istream* URIUtils::getInputStream
|
|||
* Returns the document base of the href argument
|
||||
* @return the document base of the given href
|
||||
**/
|
||||
void URIUtils::getDocumentBase(const String& href, String& dest) {
|
||||
//-- use temp str so the subString method doesn't destroy dest
|
||||
String docBase;
|
||||
|
||||
if (!href.IsEmpty()) {
|
||||
|
||||
int idx = -1;
|
||||
//-- check for URL
|
||||
ParsedURI* uri = parseURI(href);
|
||||
if ( !uri->isMalformed ) {
|
||||
idx = href.RFindChar(HREF_PATH_SEP);
|
||||
}
|
||||
else {
|
||||
//-- The following contains a fix from Shane Hathaway
|
||||
//-- to handle the case when both "\" and "/" appear in filename
|
||||
int idx2 = href.RFindChar(HREF_PATH_SEP);
|
||||
//idx = href.RFindChar(File.separator);
|
||||
idx = -1; //-- hack change later
|
||||
if (idx2 > idx) idx = idx2;
|
||||
}
|
||||
if (idx >= 0) href.subString(0,idx, docBase);
|
||||
delete uri;
|
||||
void URIUtils::getDocumentBase(const nsAFlatString& href, nsAString& dest)
|
||||
{
|
||||
if (href.IsEmpty()) {
|
||||
return;
|
||||
}
|
||||
dest.Append(docBase);
|
||||
} //-- getDocumentBase
|
||||
|
||||
nsAFlatString::const_char_iterator temp;
|
||||
href.BeginReading(temp);
|
||||
PRUint32 iter = href.Length();
|
||||
while (iter > 0) {
|
||||
if (temp[--iter] == HREF_PATH_SEP) {
|
||||
dest.Append(Substring(href, 0, iter));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -127,8 +111,8 @@ void URIUtils::getDocumentBase(const String& href, String& dest) {
|
|||
* if necessary.
|
||||
* The new resolved href will be appended to the given dest String
|
||||
**/
|
||||
void URIUtils::resolveHref(const String& href, const String& base,
|
||||
String& dest) {
|
||||
void URIUtils::resolveHref(const nsAString& href, const nsAString& base,
|
||||
nsAString& dest) {
|
||||
if (base.IsEmpty()) {
|
||||
dest.Append(href);
|
||||
return;
|
||||
|
@ -140,15 +124,15 @@ void URIUtils::resolveHref(const String& href, const String& base,
|
|||
|
||||
#ifndef TX_EXE
|
||||
nsCOMPtr<nsIURI> pURL;
|
||||
String resultHref;
|
||||
nsAutoString resultHref;
|
||||
nsresult result = NS_NewURI(getter_AddRefs(pURL), base);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
NS_MakeAbsoluteURI(resultHref, href, pURL);
|
||||
dest.Append(resultHref);
|
||||
}
|
||||
#else
|
||||
String documentBase;
|
||||
getDocumentBase(base, documentBase);
|
||||
nsAutoString documentBase;
|
||||
getDocumentBase(PromiseFlatString(base), documentBase);
|
||||
|
||||
//-- check for URL
|
||||
ParsedURI* uri = parseURI(href);
|
||||
|
@ -160,7 +144,7 @@ void URIUtils::resolveHref(const String& href, const String& base,
|
|||
|
||||
|
||||
//-- join document base + href
|
||||
String xHref;
|
||||
nsAutoString xHref;
|
||||
if (!documentBase.IsEmpty()) {
|
||||
xHref.Append(documentBase);
|
||||
if (documentBase.CharAt(documentBase.Length()-1) != HREF_PATH_SEP)
|
||||
|
@ -183,35 +167,16 @@ void URIUtils::resolveHref(const String& href, const String& base,
|
|||
}
|
||||
delete uri;
|
||||
delete newUri;
|
||||
//cout << "\n---\nhref='" << href << "', base='" << base << "'\ndocumentBase='" << documentBase << "', dest='" << dest << "'\n---\n";
|
||||
#endif
|
||||
} //-- resolveHref
|
||||
|
||||
void URIUtils::getFragmentIdentifier(const String& href, String& frag) {
|
||||
PRInt32 pos;
|
||||
pos = href.RFindChar('#');
|
||||
if(pos != kNotFound)
|
||||
href.subString(pos+1, frag);
|
||||
else
|
||||
frag.Truncate();
|
||||
} //-- getFragmentIdentifier
|
||||
|
||||
void URIUtils::getDocumentURI(const String& href, String& docUri) {
|
||||
PRInt32 pos;
|
||||
pos = href.RFindChar('#');
|
||||
if(pos != kNotFound)
|
||||
href.subString(0,pos,docUri);
|
||||
else
|
||||
docUri = href;
|
||||
} //-- getDocumentURI
|
||||
|
||||
#ifdef TX_EXE
|
||||
istream* URIUtils::openStream(ParsedURI* uri) {
|
||||
if ( !uri ) return 0;
|
||||
// check protocol
|
||||
|
||||
istream* inStream = 0;
|
||||
if ( FILE_PROTOCOL.Equals(uri->protocol) ) {
|
||||
if (uri->protocol.Equals(NS_LITERAL_STRING("file"))) {
|
||||
ifstream* inFile =
|
||||
new ifstream(NS_LossyConvertUCS2toASCII(uri->path).get(),
|
||||
ios::in);
|
||||
|
@ -221,22 +186,21 @@ istream* URIUtils::openStream(ParsedURI* uri) {
|
|||
return inStream;
|
||||
} //-- openStream
|
||||
|
||||
URIUtils::ParsedURI* URIUtils::parseURI(const String& uri) {
|
||||
|
||||
URIUtils::ParsedURI* URIUtils::parseURI(const nsAString& aUri) {
|
||||
const nsAFlatString& uri = PromiseFlatString(aUri);
|
||||
ParsedURI* uriTokens = new ParsedURI;
|
||||
if (!uriTokens)
|
||||
return NULL;
|
||||
return nsnull;
|
||||
uriTokens->isMalformed = MB_FALSE;
|
||||
|
||||
short mode = PROTOCOL_MODE;
|
||||
ParseMode mode = PROTOCOL_MODE;
|
||||
|
||||
// look for protocol
|
||||
int totalCount = uri.Length();
|
||||
int charCount = 0;
|
||||
PRUnichar prevCh = '\0';
|
||||
int fslash = 0;
|
||||
String buffer;
|
||||
buffer.getNSString().SetCapacity(uri.Length());
|
||||
nsAutoString buffer;
|
||||
while ( charCount < totalCount ) {
|
||||
PRUnichar ch = uri.CharAt(charCount++);
|
||||
switch(ch) {
|
||||
|
|
|
@ -36,10 +36,11 @@
|
|||
#ifndef TRANSFRMX_URIUTILS_H
|
||||
#define TRANSFRMX_URIUTILS_H
|
||||
|
||||
#include "TxString.h"
|
||||
#include "baseutils.h"
|
||||
#ifdef TX_EXE
|
||||
#include <fstream.h>
|
||||
#include <iostream.h>
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
|
@ -59,9 +60,6 @@ class URIUtils {
|
|||
public:
|
||||
|
||||
#ifdef TX_EXE
|
||||
static const String HTTP_PROTOCOL;
|
||||
static const String FILE_PROTOCOL;
|
||||
|
||||
/**
|
||||
* the path separator for an URI
|
||||
**/
|
||||
|
@ -84,13 +82,13 @@ public:
|
|||
|
||||
|
||||
static istream* getInputStream
|
||||
(const String& href, String& errMsg);
|
||||
(const nsAString& href, nsAString& errMsg);
|
||||
|
||||
/**
|
||||
* Returns the document base of the href argument
|
||||
* The document base will be appended to the given dest String
|
||||
**/
|
||||
static void getDocumentBase(const String& href, String& dest);
|
||||
static void getDocumentBase(const nsAFlatString& href, nsAString& dest);
|
||||
|
||||
#else /* TX_EXE */
|
||||
|
||||
|
@ -106,40 +104,30 @@ public:
|
|||
* if necessary.
|
||||
* The new resolved href will be appended to the given dest String
|
||||
**/
|
||||
static void resolveHref(const String& href, const String& base, String& dest);
|
||||
|
||||
/**
|
||||
* Returns the fragment identifier of the given URI, or "" if none exists
|
||||
* frag is cleared before the idetifier is appended
|
||||
**/
|
||||
static void getFragmentIdentifier(const String& href, String& frag);
|
||||
|
||||
/**
|
||||
* Returns the document location of given the URI (ie everything except
|
||||
* fragment). docUri is cleared before the URI is appended
|
||||
**/
|
||||
static void getDocumentURI(const String& href, String& docUri);
|
||||
|
||||
static void resolveHref(const nsAString& href, const nsAString& base,
|
||||
nsAString& dest);
|
||||
|
||||
private:
|
||||
|
||||
#ifdef TX_EXE
|
||||
static const short PROTOCOL_MODE;
|
||||
static const short HOST_MODE;
|
||||
static const short PORT_MODE;
|
||||
static const short PATH_MODE;
|
||||
enum ParseMode {
|
||||
PROTOCOL_MODE,
|
||||
HOST_MODE,
|
||||
PORT_MODE,
|
||||
PATH_MODE
|
||||
};
|
||||
|
||||
struct ParsedURI {
|
||||
MBool isMalformed;
|
||||
String fragmentIdentifier;
|
||||
String host;
|
||||
String protocol;
|
||||
String port;
|
||||
String path;
|
||||
nsString fragmentIdentifier;
|
||||
nsString host;
|
||||
nsString protocol;
|
||||
nsString port;
|
||||
nsString path;
|
||||
};
|
||||
|
||||
static istream* openStream(ParsedURI* uri);
|
||||
static ParsedURI* parseURI(const String& uri);
|
||||
static ParsedURI* parseURI(const nsAString& aUri);
|
||||
#endif
|
||||
|
||||
}; //-- URIUtils
|
||||
|
|
|
@ -40,19 +40,16 @@ REQUIRES = string \
|
|||
expat \
|
||||
$(NULL)
|
||||
|
||||
OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
|
||||
../base/CommandLineUtils.$(OBJ_SUFFIX) \
|
||||
../base/Double.$(OBJ_SUFFIX) \
|
||||
OBJS = ../base/Double.$(OBJ_SUFFIX) \
|
||||
../base/List.$(OBJ_SUFFIX) \
|
||||
../base/Map.$(OBJ_SUFFIX) \
|
||||
../base/NamedMap.$(OBJ_SUFFIX) \
|
||||
../base/SimpleErrorObserver.$(OBJ_SUFFIX) \
|
||||
../base/Stack.$(OBJ_SUFFIX) \
|
||||
../base/StringList.$(OBJ_SUFFIX) \
|
||||
../base/Tokenizer.$(OBJ_SUFFIX) \
|
||||
../base/txAtoms.$(OBJ_SUFFIX) \
|
||||
../base/txExpandedNameMap.$(OBJ_SUFFIX) \
|
||||
../base/TxString.$(OBJ_SUFFIX) \
|
||||
../base/txStringUtils.$(OBJ_SUFFIX) \
|
||||
../base/txURIUtils.$(OBJ_SUFFIX) \
|
||||
../xml/dom/standalone/Attr.$(OBJ_SUFFIX) \
|
||||
../xml/dom/standalone/NodeListDefinition.$(OBJ_SUFFIX) \
|
||||
|
@ -95,7 +92,6 @@ OBJS =../base/ArrayList.$(OBJ_SUFFIX) \
|
|||
../xml/XMLDOMUtils.$(OBJ_SUFFIX) \
|
||||
../xml/parser/XMLParser.$(OBJ_SUFFIX) \
|
||||
../xslt/txOutputFormat.$(OBJ_SUFFIX) \
|
||||
../xslt/Names.$(OBJ_SUFFIX) \
|
||||
../xslt/ProcessorState.$(OBJ_SUFFIX) \
|
||||
../xslt/txHTMLOutput.$(OBJ_SUFFIX) \
|
||||
../xslt/txRtfHandler.$(OBJ_SUFFIX) \
|
||||
|
|
|
@ -34,105 +34,16 @@
|
|||
|
||||
|
||||
#include "txStandaloneXSLTProcessor.h"
|
||||
#include "CommandLineUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include <fstream.h>
|
||||
|
||||
//--------------/
|
||||
//- Prototypes -/
|
||||
//--------------/
|
||||
#include "nsDoubleHashtable.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
/**
|
||||
* Prints the command line help screen to the console
|
||||
**/
|
||||
void printHelp();
|
||||
|
||||
/**
|
||||
* prints the command line usage information to the console
|
||||
**/
|
||||
void printUsage();
|
||||
|
||||
/**
|
||||
* The TransforMiiX command line interface
|
||||
**/
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
nsresult rv;
|
||||
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!txXSLTProcessor::txInit())
|
||||
return 1;
|
||||
|
||||
//-- available flags
|
||||
StringList flags;
|
||||
flags.add(new String(NS_LITERAL_STRING("i"))); // XML input
|
||||
flags.add(new String(NS_LITERAL_STRING("s"))); // XSL input
|
||||
flags.add(new String(NS_LITERAL_STRING("o"))); // Output filename
|
||||
flags.add(new String(NS_LITERAL_STRING("h"))); // help
|
||||
flags.add(new String(NS_LITERAL_STRING("q"))); // quiet
|
||||
|
||||
NamedMap options;
|
||||
options.setObjectDeletion(MB_TRUE);
|
||||
CommandLineUtils::getOptions(options, argc, argv, flags);
|
||||
|
||||
if (!options.get(String(NS_LITERAL_STRING("q")))) {
|
||||
String copyright(NS_LITERAL_STRING("(C) 1999 The MITRE Corporation, Keith Visco, and contributors"));
|
||||
cerr << "TransforMiiX ";
|
||||
cerr << "1.2b pre" << endl;
|
||||
cerr << copyright << endl;
|
||||
//-- print banner line
|
||||
PRUint32 fillSize = copyright.Length() + 1;
|
||||
PRUint32 counter;
|
||||
for (counter = 0; counter < fillSize; ++counter)
|
||||
cerr << '-';
|
||||
cerr << endl << endl;
|
||||
}
|
||||
|
||||
if (options.get(String(NS_LITERAL_STRING("h")))) {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
String* xmlFilename = (String*)options.get(String(NS_LITERAL_STRING("i")));
|
||||
String* xsltFilename = (String*)options.get(String(NS_LITERAL_STRING("s")));
|
||||
String* outFilename = (String*)options.get(String(NS_LITERAL_STRING("o")));
|
||||
|
||||
//-- handle output stream
|
||||
ostream* resultOutput = &cout;
|
||||
ofstream resultFileStream;
|
||||
if (outFilename && !outFilename->getConstNSString().Equals(NS_LITERAL_STRING("-"))) {
|
||||
resultFileStream.open(NS_LossyConvertUCS2toASCII(*outFilename).get(),
|
||||
ios::out);
|
||||
if (!resultFileStream) {
|
||||
cerr << "error opening output file: " << *xmlFilename << endl;
|
||||
return -1;
|
||||
}
|
||||
resultOutput = &resultFileStream;
|
||||
}
|
||||
|
||||
SimpleErrorObserver obs;
|
||||
txStandaloneXSLTProcessor proc;
|
||||
//-- process
|
||||
if (!xsltFilename) {
|
||||
if (!xmlFilename) {
|
||||
cerr << "you must specify at least a source XML path" << endl;
|
||||
printUsage();
|
||||
return -1;
|
||||
}
|
||||
rv = proc.transform(*xmlFilename, *resultOutput, obs);
|
||||
}
|
||||
else {
|
||||
//-- open XSLT file
|
||||
rv = proc.transform(*xmlFilename, *xsltFilename, *resultOutput, obs);
|
||||
}
|
||||
resultFileStream.close();
|
||||
txXSLTProcessor::txShutdown();
|
||||
rv = NS_ShutdownXPCOM(nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return 0;
|
||||
} //-- main
|
||||
|
||||
void printHelp() {
|
||||
*/
|
||||
void printHelp()
|
||||
{
|
||||
cerr << "transfrmx [-h] [-i xml-file] [-s xslt-file] [-o output-file]" << endl << endl;
|
||||
cerr << "Options:";
|
||||
cerr << endl << endl;
|
||||
|
@ -146,8 +57,140 @@ void printHelp() {
|
|||
cerr << "standard output." << endl;
|
||||
cerr << endl;
|
||||
}
|
||||
void printUsage() {
|
||||
cerr << "transfrmx [-h] [-i xml-file] [-s xslt-file] [-o output-file]" << endl << endl;
|
||||
cerr << "For more infomation use the -h flag"<<endl;
|
||||
} //-- printUsage
|
||||
|
||||
/**
|
||||
* Prints the command line usage information to the console
|
||||
*/
|
||||
void printUsage()
|
||||
{
|
||||
cerr << "transfrmx [-h] [-i xml-file] [-s xslt-file] [-o output-file]" << endl << endl;
|
||||
cerr << "For more infomation use the -h flag" << endl;
|
||||
}
|
||||
|
||||
class txOptionEntry : public PLDHashCStringEntry
|
||||
{
|
||||
public:
|
||||
txOptionEntry(const void* aKey) : PLDHashCStringEntry(aKey)
|
||||
{
|
||||
}
|
||||
~txOptionEntry()
|
||||
{
|
||||
}
|
||||
nsCStringArray mValues;
|
||||
};
|
||||
|
||||
DECL_DHASH_WRAPPER(txOptions, txOptionEntry, nsACString&)
|
||||
DHASH_WRAPPER(txOptions, txOptionEntry, nsACString&)
|
||||
|
||||
/**
|
||||
* Parses the command line
|
||||
*/
|
||||
void parseCommandLine(int argc, char** argv, txOptions& aOptions)
|
||||
{
|
||||
nsCAutoString flag;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
nsDependentCString arg(argv[i]);
|
||||
if (*argv[i] == '-' && arg.Length() > 1) {
|
||||
// clean up previous flag
|
||||
if (!flag.IsEmpty()) {
|
||||
txOptionEntry* option = aOptions.AddEntry(flag);
|
||||
flag.Truncate();
|
||||
}
|
||||
|
||||
// get next flag
|
||||
flag = Substring(arg, 1, arg.Length() - 1);
|
||||
}
|
||||
else {
|
||||
txOptionEntry* option = aOptions.AddEntry(flag);
|
||||
if (option) {
|
||||
option->mValues.AppendCString(nsCString(arg));
|
||||
}
|
||||
flag.Truncate();
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag.IsEmpty()) {
|
||||
txOptionEntry* option = aOptions.AddEntry(flag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The TransforMiiX command line interface
|
||||
*/
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!txXSLTProcessor::txInit())
|
||||
return 1;
|
||||
|
||||
txOptions options;
|
||||
if (NS_FAILED(options.Init(4))) {
|
||||
return 1;
|
||||
}
|
||||
parseCommandLine(argc, argv, options);
|
||||
|
||||
if (!options.GetEntry(NS_LITERAL_CSTRING("q"))) {
|
||||
NS_NAMED_LITERAL_CSTRING(copyright, "(C) 1999 The MITRE Corporation, Keith Visco, and contributors");
|
||||
cerr << "TransforMiiX ";
|
||||
cerr << "1.3a pre" << endl;
|
||||
cerr << copyright.get() << endl;
|
||||
//-- print banner line
|
||||
PRUint32 fillSize = copyright.Length() + 1;
|
||||
PRUint32 counter;
|
||||
for (counter = 0; counter < fillSize; ++counter)
|
||||
cerr << '-';
|
||||
cerr << endl << endl;
|
||||
}
|
||||
|
||||
if (options.GetEntry(NS_LITERAL_CSTRING("h"))) {
|
||||
printHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-- handle output stream
|
||||
ostream* resultOutput = &cout;
|
||||
ofstream resultFileStream;
|
||||
|
||||
txOptionEntry* option = options.GetEntry(NS_LITERAL_CSTRING("o"));
|
||||
if (option &&
|
||||
option->mValues.Count() > 0 &&
|
||||
!option->mValues[0]->Equals(NS_LITERAL_CSTRING("-"))) {
|
||||
resultFileStream.open(option->mValues[0]->get(), ios::out);
|
||||
if (!resultFileStream) {
|
||||
cerr << "error opening output file: ";
|
||||
cerr << option->mValues[0]->get() << endl;
|
||||
return -1;
|
||||
}
|
||||
resultOutput = &resultFileStream;
|
||||
}
|
||||
|
||||
option = options.GetEntry(NS_LITERAL_CSTRING("i"));
|
||||
if (!option || option->mValues.Count() == 0) {
|
||||
cerr << "you must specify at least a source XML path" << endl;
|
||||
printUsage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
SimpleErrorObserver obs;
|
||||
txStandaloneXSLTProcessor proc;
|
||||
|
||||
txOptionEntry* styleOption = options.GetEntry(NS_LITERAL_CSTRING("s"));
|
||||
if (!styleOption || styleOption->mValues.Count() == 0) {
|
||||
rv = proc.transform(*option->mValues[0], *resultOutput, obs);
|
||||
}
|
||||
else {
|
||||
// XXX TODO: Handle multiple stylesheets
|
||||
rv = proc.transform(*option->mValues[0], *styleOption->mValues[0],
|
||||
*resultOutput, obs);
|
||||
}
|
||||
|
||||
resultFileStream.close();
|
||||
txXSLTProcessor::txShutdown();
|
||||
rv = NS_ShutdownXPCOM(nsnull);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ public:
|
|||
int loadStylesheet (char * filename)
|
||||
{
|
||||
delete mXSL;
|
||||
mXSL = parsePath(String(NS_ConvertASCIItoUCS2(filename)), mObserver);
|
||||
mXSL = parsePath(nsDependentCString(filename), mObserver);
|
||||
return mXSL ? 0 : 1;
|
||||
}
|
||||
int setInputDocument (char * filename)
|
||||
{
|
||||
delete mXML;
|
||||
mXML = parsePath(String(NS_ConvertASCIItoUCS2(filename)), mObserver);
|
||||
mXML = parsePath(nsDependentCString(filename), mObserver);
|
||||
return mXML ? 0 : 1;
|
||||
}
|
||||
int openOutput (char * outputFilename)
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
//
|
||||
//Construct an Attribute object using the specified name and document owner
|
||||
//
|
||||
Attr::Attr(const String& name, Document* owner):
|
||||
NodeDefinition(Node::ATTRIBUTE_NODE, name, NULL_STRING, owner)
|
||||
Attr::Attr(const nsAString& name, Document* owner):
|
||||
NodeDefinition(Node::ATTRIBUTE_NODE, name, nsString(), owner)
|
||||
{
|
||||
int idx = nodeName.indexOf(':');
|
||||
int idx = nodeName.FindChar(':');
|
||||
if (idx == kNotFound) {
|
||||
mLocalName = TX_GET_ATOM(nodeName);
|
||||
if (mLocalName == txXMLAtoms::xmlns)
|
||||
|
@ -44,15 +44,12 @@ Attr::Attr(const String& name, Document* owner):
|
|||
mNamespaceID = kNameSpaceID_None;
|
||||
}
|
||||
else {
|
||||
String tmp;
|
||||
nodeName.subString(idx + 1, tmp);
|
||||
mLocalName = TX_GET_ATOM(tmp);
|
||||
mLocalName = TX_GET_ATOM(Substring(nodeName, idx + 1,
|
||||
nodeName.Length() - (idx + 1)));
|
||||
// namespace handling has to be handled late, the attribute must
|
||||
// be added to the tree to resolve the prefix, unless it's
|
||||
// xmlns or xml, try to do that here
|
||||
String prefix;
|
||||
nodeName.subString(0, idx, prefix);
|
||||
txAtom* prefixAtom = TX_GET_ATOM(prefix);
|
||||
txAtom* prefixAtom = TX_GET_ATOM(Substring(nodeName, 0, idx));
|
||||
if (prefixAtom == txXMLAtoms::xmlns)
|
||||
mNamespaceID = kNameSpaceID_XMLNS;
|
||||
else if (prefixAtom == txXMLAtoms::xml)
|
||||
|
@ -63,19 +60,17 @@ Attr::Attr(const String& name, Document* owner):
|
|||
}
|
||||
}
|
||||
|
||||
Attr::Attr(const String& aNamespaceURI,
|
||||
const String& aName,
|
||||
Attr::Attr(const nsAString& aNamespaceURI,
|
||||
const nsAString& aName,
|
||||
Document* aOwner) :
|
||||
NodeDefinition(Node::ATTRIBUTE_NODE, aName, NULL_STRING, aOwner)
|
||||
NodeDefinition(Node::ATTRIBUTE_NODE, aName, nsString(), aOwner)
|
||||
{
|
||||
if (aNamespaceURI.IsEmpty())
|
||||
mNamespaceID = kNameSpaceID_None;
|
||||
else
|
||||
mNamespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
|
||||
|
||||
String localPart;
|
||||
XMLUtils::getLocalPart(nodeName, localPart);
|
||||
mLocalName = TX_GET_ATOM(localPart);
|
||||
XMLUtils::getLocalPart(nodeName, &mLocalName);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -86,42 +81,15 @@ Attr::~Attr()
|
|||
TX_IF_RELEASE_ATOM(mLocalName);
|
||||
}
|
||||
|
||||
//
|
||||
//Retrieve the value of the attribute.
|
||||
//
|
||||
const String& Attr::getValue()
|
||||
void Attr::setNodeValue(const nsAString& aValue)
|
||||
{
|
||||
return nodeValue;
|
||||
nodeValue = aValue;
|
||||
}
|
||||
|
||||
//
|
||||
//Set the nodevalue to the given value.
|
||||
//
|
||||
void Attr::setValue(const String& newValue)
|
||||
nsresult Attr::getNodeValue(nsAString& aValue)
|
||||
{
|
||||
nodeValue = newValue;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//Override the set node value member function to create a new TEXT node with
|
||||
//the String and to add it as the Attribute's child.
|
||||
// NOTE: Not currently impemented, just execute the default setNodeValue
|
||||
//
|
||||
void Attr::setNodeValue(const String& nodeValue)
|
||||
{
|
||||
setValue(nodeValue);
|
||||
}
|
||||
|
||||
//
|
||||
//Return a String represening the value of this node. If the value is an
|
||||
//Entity Reference then return the value of the reference. Otherwise, it is a
|
||||
//simple conversion of the text value.
|
||||
// NOTE: Not currently implemented, just execute the default getNodeValue
|
||||
//
|
||||
const String& Attr::getNodeValue()
|
||||
{
|
||||
return nodeValue;
|
||||
aValue = nodeValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -155,12 +123,12 @@ PRInt32 Attr::getNamespaceID()
|
|||
if (mNamespaceID >= 0)
|
||||
return mNamespaceID;
|
||||
|
||||
int idx = nodeName.indexOf(':');
|
||||
String prefix;
|
||||
nodeName.subString(0, idx, prefix);
|
||||
txAtom* prefixAtom = TX_GET_ATOM(prefix);
|
||||
mNamespaceID = lookupNamespaceID(prefixAtom);
|
||||
TX_IF_RELEASE_ATOM(prefixAtom);
|
||||
mNamespaceID = kNameSpaceID_None;
|
||||
PRInt32 idx = nodeName.FindChar(':');
|
||||
if (idx != kNotFound) {
|
||||
nsCOMPtr<txAtom> prefixAtom = TX_GET_ATOM(Substring(nodeName, 0, idx));
|
||||
mNamespaceID = lookupNamespaceID(prefixAtom);
|
||||
}
|
||||
return mNamespaceID;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,8 @@
|
|||
#include "List.h"
|
||||
#include "txAtom.h"
|
||||
#include "baseutils.h"
|
||||
|
||||
#ifndef NULL
|
||||
typedef 0 NULL;
|
||||
#endif
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#define kTxNsNodeIndexOffset 0x00000000;
|
||||
#define kTxAttrIndexOffset 0x40000000;
|
||||
|
@ -56,13 +54,6 @@ class Element;
|
|||
class Attr;
|
||||
class ProcessingInstruction;
|
||||
|
||||
/*
|
||||
* NULL string for use by Element::getAttribute() for when the attribute
|
||||
* specified by "name" does not exist, and therefore shoud be "NULL".
|
||||
* Used in txNamespaceManager as well.
|
||||
*/
|
||||
const String NULL_STRING;
|
||||
|
||||
#define kNameSpaceID_Unknown -1
|
||||
#define kNameSpaceID_None 0
|
||||
// not really a namespace, but it needs to play the game
|
||||
|
@ -98,8 +89,8 @@ class Node : public TxObject
|
|||
virtual ~Node() {}
|
||||
|
||||
//Read functions
|
||||
virtual const String& getNodeName() const = 0;
|
||||
virtual const String& getNodeValue() = 0;
|
||||
virtual nsresult getNodeName(nsAString& aName) const = 0;
|
||||
virtual nsresult getNodeValue(nsAString& aValue) = 0;
|
||||
virtual unsigned short getNodeType() const = 0;
|
||||
virtual Node* getParentNode() const = 0;
|
||||
virtual Node* getFirstChild() const = 0;
|
||||
|
@ -110,7 +101,7 @@ class Node : public TxObject
|
|||
virtual Document* getOwnerDocument() const = 0;
|
||||
|
||||
//Write functions
|
||||
virtual void setNodeValue(const String& nodeValue) = 0;
|
||||
virtual void setNodeValue(const nsAString& nodeValue) = 0;
|
||||
|
||||
//Node manipulation functions
|
||||
virtual Node* appendChild(Node* newChild) = 0;
|
||||
|
@ -118,10 +109,10 @@ class Node : public TxObject
|
|||
virtual MBool hasChildNodes() const = 0;
|
||||
|
||||
//From DOM3 26-Jan-2001 WD
|
||||
virtual String getBaseURI() = 0;
|
||||
virtual nsresult getBaseURI(nsAString& aURI) = 0;
|
||||
|
||||
//Introduced in DOM2
|
||||
virtual const String& getNamespaceURI() = 0;
|
||||
virtual nsresult getNamespaceURI(nsAString& aNSURI) = 0;
|
||||
|
||||
//txXPathNode functions
|
||||
virtual MBool getLocalName(txAtom** aLocalName) = 0;
|
||||
|
@ -190,12 +181,12 @@ class NamedNodeMap : public NodeListDefinition
|
|||
NamedNodeMap();
|
||||
virtual ~NamedNodeMap();
|
||||
|
||||
Node* getNamedItem(const String& name);
|
||||
Node* getNamedItem(const nsAString& name);
|
||||
virtual Node* setNamedItem(Node* arg);
|
||||
virtual Node* removeNamedItem(const String& name);
|
||||
virtual Node* removeNamedItem(const nsAString& name);
|
||||
|
||||
private:
|
||||
NodeListDefinition::ListItem* findListItemByName(const String& name);
|
||||
NodeListDefinition::ListItem* findListItemByName(const nsAString& name);
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -213,7 +204,7 @@ class AttrMap : public NamedNodeMap
|
|||
virtual ~AttrMap();
|
||||
|
||||
Node* setNamedItem(Node* arg);
|
||||
Node* removeNamedItem(const String& name);
|
||||
Node* removeNamedItem(const nsAString& name);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
|
@ -232,8 +223,8 @@ class NodeDefinition : public Node, public NodeList
|
|||
virtual ~NodeDefinition(); //Destructor, delete all children of node
|
||||
|
||||
//Read functions
|
||||
const String& getNodeName() const;
|
||||
virtual const String& getNodeValue();
|
||||
nsresult getNodeName(nsAString& aName) const;
|
||||
nsresult getNodeValue(nsAString& aValue);
|
||||
unsigned short getNodeType() const;
|
||||
Node* getParentNode() const;
|
||||
Node* getFirstChild() const;
|
||||
|
@ -244,7 +235,7 @@ class NodeDefinition : public Node, public NodeList
|
|||
Document* getOwnerDocument() const;
|
||||
|
||||
//Write functions
|
||||
virtual void setNodeValue(const String& nodeValue);
|
||||
virtual void setNodeValue(const nsAString& nodeValue);
|
||||
|
||||
//Child node manipulation functions
|
||||
virtual Node* appendChild(Node* newChild);
|
||||
|
@ -252,10 +243,10 @@ class NodeDefinition : public Node, public NodeList
|
|||
MBool hasChildNodes() const;
|
||||
|
||||
//From DOM3 26-Jan-2001 WD
|
||||
virtual String getBaseURI();
|
||||
virtual nsresult getBaseURI(nsAString& aURI);
|
||||
|
||||
//Introduced in DOM2
|
||||
const String& getNamespaceURI();
|
||||
nsresult getNamespaceURI(nsAString& aNSURI);
|
||||
|
||||
//txXPathNode functions
|
||||
virtual MBool getLocalName(txAtom** aLocalName);
|
||||
|
@ -269,23 +260,23 @@ class NodeDefinition : public Node, public NodeList
|
|||
PRUint32 getLength();
|
||||
|
||||
//Only to be used from XMLParser
|
||||
void appendData(PRUnichar* aData, int aLength)
|
||||
void appendData(const PRUnichar* aData, int aLength)
|
||||
{
|
||||
nodeValue.Append(aData, aLength);
|
||||
};
|
||||
|
||||
protected:
|
||||
friend class Document;
|
||||
NodeDefinition(NodeType type, const String& name,
|
||||
const String& value, Document* owner);
|
||||
NodeDefinition(NodeType aType, const String& aValue,
|
||||
NodeDefinition(NodeType type, const nsAString& name,
|
||||
const nsAString& value, Document* owner);
|
||||
NodeDefinition(NodeType aType, const nsAString& aValue,
|
||||
Document* aOwner);
|
||||
|
||||
//Name, value, and attributes for this node. Available to derrived
|
||||
//classes, since those derrived classes have a better idea how to use them,
|
||||
//than the generic node does.
|
||||
String nodeName;
|
||||
String nodeValue;
|
||||
nsString nodeName;
|
||||
nsString nodeValue;
|
||||
|
||||
NodeDefinition* implAppendChild(NodeDefinition* newChild);
|
||||
NodeDefinition* implRemoveChild(NodeDefinition* oldChild);
|
||||
|
@ -293,7 +284,7 @@ class NodeDefinition : public Node, public NodeList
|
|||
void DeleteChildren();
|
||||
|
||||
private:
|
||||
void Init(NodeType aType, const String& aValue, Document* aOwner);
|
||||
void Init(NodeType aType, const nsAString& aValue, Document* aOwner);
|
||||
|
||||
//Type of node this is
|
||||
NodeType nodeType;
|
||||
|
@ -360,7 +351,7 @@ class DocumentFragment : public NodeDefinition
|
|||
private:
|
||||
friend class Document;
|
||||
DocumentFragment(Document* aOwner) :
|
||||
NodeDefinition(Node::DOCUMENT_FRAGMENT_NODE, NULL_STRING, aOwner)
|
||||
NodeDefinition(Node::DOCUMENT_FRAGMENT_NODE, nsString(), aOwner)
|
||||
{
|
||||
};
|
||||
};
|
||||
|
@ -376,37 +367,37 @@ class Document : public NodeDefinition
|
|||
Element* getDocumentElement();
|
||||
|
||||
//Factory functions for various node types
|
||||
Node* createComment(const String& aData);
|
||||
Node* createComment(const nsAString& aData);
|
||||
Node* createDocumentFragment();
|
||||
ProcessingInstruction* createProcessingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
Node* createTextNode(const String& theData);
|
||||
ProcessingInstruction* createProcessingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
Node* createTextNode(const nsAString& theData);
|
||||
|
||||
Element* createElement(const String& tagName);
|
||||
Attr* createAttribute(const String& name);
|
||||
Element* createElement(const nsAString& tagName);
|
||||
Attr* createAttribute(const nsAString& name);
|
||||
|
||||
// Introduced in DOM Level 2
|
||||
Element* createElementNS(const String& aNamespaceURI,
|
||||
const String& aTagName);
|
||||
Attr* createAttributeNS(const String& aNamespaceURI,
|
||||
const String& aName);
|
||||
Element* getElementById(const String aID);
|
||||
Element* createElementNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aTagName);
|
||||
Attr* createAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aName);
|
||||
Element* getElementById(const nsAString& aID);
|
||||
|
||||
// Node manipulation functions
|
||||
Node* appendChild(Node* newChild);
|
||||
|
||||
//Override to return documentBaseURI
|
||||
String getBaseURI();
|
||||
nsresult getBaseURI(nsAString& aURI);
|
||||
|
||||
PRInt32 namespaceURIToID(const String& aNamespaceURI);
|
||||
void namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI);
|
||||
PRInt32 namespaceURIToID(const nsAString& aNamespaceURI);
|
||||
void namespaceIDToURI(PRInt32 aNamespaceID, nsAString& aNamespaceURI);
|
||||
|
||||
private:
|
||||
Element* documentElement;
|
||||
|
||||
// This class is friend to be able to set the documentBaseURI
|
||||
friend class XMLParser;
|
||||
String documentBaseURI;
|
||||
nsString documentBaseURI;
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -418,11 +409,11 @@ class Element : public NodeDefinition
|
|||
virtual ~Element();
|
||||
|
||||
NamedNodeMap* getAttributes();
|
||||
void setAttribute(const String& name, const String& value);
|
||||
void setAttributeNS(const String& aNamespaceURI,
|
||||
const String& aName,
|
||||
const String& aValue);
|
||||
Attr* getAttributeNode(const String& name);
|
||||
void setAttribute(const nsAString& name, const nsAString& value);
|
||||
void setAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aValue);
|
||||
Attr* getAttributeNode(const nsAString& name);
|
||||
|
||||
// Node manipulation functions
|
||||
Node* appendChild(Node* newChild);
|
||||
|
@ -430,13 +421,13 @@ class Element : public NodeDefinition
|
|||
//txXPathNode functions override
|
||||
MBool getLocalName(txAtom** aLocalName);
|
||||
PRInt32 getNamespaceID();
|
||||
MBool getAttr(txAtom* aLocalName, PRInt32 aNSID, String& aValue);
|
||||
MBool getAttr(txAtom* aLocalName, PRInt32 aNSID, nsAString& aValue);
|
||||
MBool hasAttr(txAtom* aLocalName, PRInt32 aNSID);
|
||||
|
||||
private:
|
||||
friend class Document;
|
||||
Element(const String& tagName, Document* owner);
|
||||
Element(const String& aNamespaceURI, const String& aTagName,
|
||||
Element(const nsAString& tagName, Document* owner);
|
||||
Element(const nsAString& aNamespaceURI, const nsAString& aTagName,
|
||||
Document* aOwner);
|
||||
|
||||
AttrMap mAttributes;
|
||||
|
@ -454,13 +445,10 @@ class Attr : public NodeDefinition
|
|||
public:
|
||||
virtual ~Attr();
|
||||
|
||||
const String& getValue();
|
||||
void setValue(const String& newValue);
|
||||
|
||||
//Override the set and get member functions for a node's value to create a
|
||||
//new TEXT node when set, and to interpret its children when read.
|
||||
void setNodeValue(const String& nodeValue);
|
||||
const String& getNodeValue();
|
||||
void setNodeValue(const nsAString& aValue);
|
||||
nsresult getNodeValue(nsAString& aValue);
|
||||
|
||||
// Node manipulation functions
|
||||
Node* appendChild(Node* newChild);
|
||||
|
@ -472,8 +460,8 @@ class Attr : public NodeDefinition
|
|||
|
||||
private:
|
||||
friend class Document;
|
||||
Attr(const String& name, Document* owner);
|
||||
Attr(const String& aNamespaceURI, const String& aName,
|
||||
Attr(const nsAString& name, Document* owner);
|
||||
Attr(const nsAString& aNamespaceURI, const nsAString& aName,
|
||||
Document* aOwner);
|
||||
|
||||
// These need to be friend to be able to update the ownerElement
|
||||
|
@ -504,7 +492,7 @@ class ProcessingInstruction : public NodeDefinition
|
|||
|
||||
private:
|
||||
friend class Document;
|
||||
ProcessingInstruction(const String& theTarget, const String& theData,
|
||||
ProcessingInstruction(const nsAString& theTarget, const nsAString& theData,
|
||||
Document* owner);
|
||||
|
||||
txAtom* mLocalName;
|
||||
|
@ -513,40 +501,35 @@ class ProcessingInstruction : public NodeDefinition
|
|||
class txNamespaceManager
|
||||
{
|
||||
public:
|
||||
static PRInt32 getNamespaceID(const String& aURI)
|
||||
static PRInt32 getNamespaceID(const nsAString& aURI)
|
||||
{
|
||||
if (!mNamespaces && !init())
|
||||
return kNameSpaceID_Unknown;
|
||||
txListIterator nameIter(mNamespaces);
|
||||
PRInt32 id=0;
|
||||
String* uri;
|
||||
while (nameIter.hasNext()) {
|
||||
uri = (String*)nameIter.next();
|
||||
id++;
|
||||
if (uri->Equals(aURI))
|
||||
return id;
|
||||
|
||||
PRInt32 id = mNamespaces->IndexOf(aURI);
|
||||
if (id != -1) {
|
||||
return id + 1;
|
||||
}
|
||||
uri = new String(aURI);
|
||||
NS_ASSERTION(uri, "Out of memory, namespaces are getting lost");
|
||||
if (!uri)
|
||||
|
||||
if (!mNamespaces->AppendString(aURI)) {
|
||||
NS_ASSERTION(0, "Out of memory, namespaces are getting lost");
|
||||
return kNameSpaceID_Unknown;
|
||||
mNamespaces->add(uri);
|
||||
id++;
|
||||
return id;
|
||||
}
|
||||
|
||||
return mNamespaces->Count();
|
||||
}
|
||||
|
||||
static const String& getNamespaceURI(const PRInt32 aID)
|
||||
static nsresult getNamespaceURI(const PRInt32 aID, nsAString& aNSURI)
|
||||
{
|
||||
// empty namespace, and errors
|
||||
if (aID <= 0)
|
||||
return NULL_STRING;
|
||||
if (!mNamespaces && !init())
|
||||
return NULL_STRING;
|
||||
txListIterator nameIter(mNamespaces);
|
||||
String* aURI = (String*)nameIter.advance(aID);
|
||||
if (aURI)
|
||||
return *aURI;
|
||||
return NULL_STRING;
|
||||
aNSURI.Truncate();
|
||||
if (aID <= 0 || (!mNamespaces && !init()) ||
|
||||
aID > mNamespaces->Count()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
aNSURI = *mNamespaces->StringAt(aID - 1);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static MBool init()
|
||||
|
@ -555,7 +538,7 @@ public:
|
|||
"called without matching shutdown()");
|
||||
if (mNamespaces)
|
||||
return MB_TRUE;
|
||||
mNamespaces = new txList();
|
||||
mNamespaces = new nsStringArray();
|
||||
if (!mNamespaces)
|
||||
return MB_FALSE;
|
||||
/*
|
||||
|
@ -564,27 +547,14 @@ public:
|
|||
* xmlns prefix is 1, mapped to http://www.w3.org/2000/xmlns/
|
||||
* xml prefix is 2, mapped to http://www.w3.org/XML/1998/namespace
|
||||
*/
|
||||
String* XMLNSUri = new String(NS_LITERAL_STRING("http://www.w3.org/2000/xmlns/"));
|
||||
if (!XMLNSUri) {
|
||||
if (!mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/2000/xmlns/")) ||
|
||||
!mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/XML/1998/namespace")) ||
|
||||
!mNamespaces->AppendString(NS_LITERAL_STRING("http://www.w3.org/1999/XSL/Transform"))) {
|
||||
delete mNamespaces;
|
||||
mNamespaces = 0;
|
||||
return MB_FALSE;
|
||||
}
|
||||
mNamespaces->add(XMLNSUri);
|
||||
String* XMLUri = new String(NS_LITERAL_STRING("http://www.w3.org/XML/1998/namespace"));
|
||||
if (!XMLUri) {
|
||||
delete mNamespaces;
|
||||
mNamespaces = 0;
|
||||
return MB_FALSE;
|
||||
}
|
||||
mNamespaces->add(XMLUri);
|
||||
String* XSLTUri = new String(NS_LITERAL_STRING("http://www.w3.org/1999/XSL/Transform"));
|
||||
if (!XSLTUri) {
|
||||
delete mNamespaces;
|
||||
mNamespaces = 0;
|
||||
return MB_FALSE;
|
||||
}
|
||||
mNamespaces->add(XSLTUri);
|
||||
|
||||
return MB_TRUE;
|
||||
}
|
||||
|
||||
|
@ -593,18 +563,15 @@ public:
|
|||
NS_ASSERTION(mNamespaces, "called without matching init()");
|
||||
if (!mNamespaces)
|
||||
return;
|
||||
txListIterator iter(mNamespaces);
|
||||
while (iter.hasNext())
|
||||
delete (String*)iter.next();
|
||||
delete mNamespaces;
|
||||
mNamespaces = NULL;
|
||||
mNamespaces = nsnull;
|
||||
}
|
||||
|
||||
private:
|
||||
static txList* mNamespaces;
|
||||
static nsStringArray* mNamespaces;
|
||||
};
|
||||
|
||||
#define TX_IMPL_DOM_STATICS \
|
||||
txList* txNamespaceManager::mNamespaces = 0
|
||||
nsStringArray* txNamespaceManager::mNamespaces = 0
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
//Construct a Document. Currently no parameters are required, but the the
|
||||
//node constructor is called to identify the node type.
|
||||
//
|
||||
Document::Document() : NodeDefinition(Node::DOCUMENT_NODE, NULL_STRING, NULL)
|
||||
Document::Document() : NodeDefinition(Node::DOCUMENT_NODE, nsString(), NULL)
|
||||
{
|
||||
documentElement = NULL;
|
||||
documentElement = nsnull;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -64,13 +64,13 @@ Node* Document::createDocumentFragment()
|
|||
//Construct an element with the specified tag name.
|
||||
// NOTE: The caller is responsible for cleaning up the element's menory
|
||||
//
|
||||
Element* Document::createElement(const String& tagName)
|
||||
Element* Document::createElement(const nsAString& tagName)
|
||||
{
|
||||
return new Element(tagName, this);
|
||||
}
|
||||
|
||||
Element* Document::createElementNS(const String& aNamespaceURI,
|
||||
const String& aTagName)
|
||||
Element* Document::createElementNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aTagName)
|
||||
{
|
||||
return new Element(aNamespaceURI, aTagName, this);
|
||||
}
|
||||
|
@ -78,13 +78,13 @@ Element* Document::createElementNS(const String& aNamespaceURI,
|
|||
//
|
||||
//Construct an attribute with the specified name
|
||||
//
|
||||
Attr* Document::createAttribute(const String& name)
|
||||
Attr* Document::createAttribute(const nsAString& name)
|
||||
{
|
||||
return new Attr(name, this);
|
||||
}
|
||||
|
||||
Attr* Document::createAttributeNS(const String& aNamespaceURI,
|
||||
const String& aName)
|
||||
Attr* Document::createAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aName)
|
||||
{
|
||||
return new Attr(aNamespaceURI, aName, this);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ Attr* Document::createAttributeNS(const String& aNamespaceURI,
|
|||
//
|
||||
//Construct a text node with the given data
|
||||
//
|
||||
Node* Document::createTextNode(const String& theData)
|
||||
Node* Document::createTextNode(const nsAString& theData)
|
||||
{
|
||||
return new NodeDefinition(Node::TEXT_NODE, theData, this);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ Node* Document::createTextNode(const String& theData)
|
|||
//
|
||||
//Construct a comment node with the given data
|
||||
//
|
||||
Node* Document::createComment(const String& theData)
|
||||
Node* Document::createComment(const nsAString& theData)
|
||||
{
|
||||
return new NodeDefinition(Node::COMMENT_NODE, theData, this);
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ Node* Document::createComment(const String& theData)
|
|||
//Construct a ProcessingInstruction node with the given targe and data.
|
||||
//
|
||||
ProcessingInstruction*
|
||||
Document::createProcessingInstruction(const String& target,
|
||||
const String& data)
|
||||
Document::createProcessingInstruction(const nsAString& target,
|
||||
const nsAString& data)
|
||||
{
|
||||
return new ProcessingInstruction(target, data, this);
|
||||
}
|
||||
|
@ -118,13 +118,13 @@ ProcessingInstruction*
|
|||
//
|
||||
//Return an Element by ID, introduced by DOM2
|
||||
//
|
||||
Element* Document::getElementById(const String aID)
|
||||
Element* Document::getElementById(const nsAString& aID)
|
||||
{
|
||||
/* This would need knowledge of the DTD, and we don't have it.
|
||||
* If we knew that we deal with HTML4 or XHTML1 we could check
|
||||
* for the "id" attribute, but we don't, so return NULL
|
||||
*/
|
||||
return NULL;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
Node* Document::appendChild(Node* newChild)
|
||||
|
@ -163,18 +163,18 @@ Node* Document::appendChild(Node* newChild)
|
|||
return nsnull;
|
||||
}
|
||||
|
||||
String Document::getBaseURI()
|
||||
nsresult Document::getBaseURI(nsAString& aURI)
|
||||
{
|
||||
return documentBaseURI;
|
||||
aURI = documentBaseURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 Document::namespaceURIToID(const String& aNamespaceURI)
|
||||
PRInt32 Document::namespaceURIToID(const nsAString& aNamespaceURI)
|
||||
{
|
||||
return txNamespaceManager::getNamespaceID(aNamespaceURI);
|
||||
}
|
||||
|
||||
void Document::namespaceIDToURI(PRInt32 aNamespaceID, String& aNamespaceURI)
|
||||
void Document::namespaceIDToURI(PRInt32 aNamespaceID, nsAString& aNamespaceURI)
|
||||
{
|
||||
aNamespaceURI = txNamespaceManager::getNamespaceURI(aNamespaceID);
|
||||
return;
|
||||
txNamespaceManager::getNamespaceURI(aNamespaceID, aNamespaceURI);
|
||||
}
|
||||
|
|
|
@ -34,27 +34,26 @@
|
|||
//Simply call the constructor for NodeDefinition, and specify the proper node
|
||||
//type.
|
||||
//
|
||||
Element::Element(const String& tagName, Document* owner) :
|
||||
NodeDefinition(Node::ELEMENT_NODE, tagName, NULL_STRING, owner)
|
||||
Element::Element(const nsAString& tagName, Document* owner) :
|
||||
NodeDefinition(Node::ELEMENT_NODE, tagName, nsString(), owner)
|
||||
{
|
||||
mAttributes.ownerElement = this;
|
||||
mNamespaceID = kNameSpaceID_Unknown;
|
||||
|
||||
int idx = nodeName.indexOf(':');
|
||||
int idx = tagName.FindChar(':');
|
||||
if (idx == kNotFound) {
|
||||
mLocalName = TX_GET_ATOM(nodeName);
|
||||
mLocalName = TX_GET_ATOM(tagName);
|
||||
}
|
||||
else {
|
||||
String tmp;
|
||||
nodeName.subString(idx+1, tmp);
|
||||
mLocalName = TX_GET_ATOM(tmp);
|
||||
mLocalName = TX_GET_ATOM(Substring(tagName, idx + 1,
|
||||
tagName.Length() - (idx + 1)));
|
||||
}
|
||||
}
|
||||
|
||||
Element::Element(const String& aNamespaceURI,
|
||||
const String& aTagName,
|
||||
Element::Element(const nsAString& aNamespaceURI,
|
||||
const nsAString& aTagName,
|
||||
Document* aOwner) :
|
||||
NodeDefinition(Node::ELEMENT_NODE, aTagName, NULL_STRING, aOwner)
|
||||
NodeDefinition(Node::ELEMENT_NODE, aTagName, nsString(), aOwner)
|
||||
{
|
||||
Element(aTagName, aOwner);
|
||||
if (aNamespaceURI.IsEmpty())
|
||||
|
@ -116,11 +115,11 @@ PRInt32 Element::getNamespaceID()
|
|||
{
|
||||
if (mNamespaceID>=0)
|
||||
return mNamespaceID;
|
||||
int idx = nodeName.indexOf(':');
|
||||
int idx = nodeName.FindChar(':');
|
||||
if (idx == kNotFound) {
|
||||
Node* node = this;
|
||||
while (node && node->getNodeType() == Node::ELEMENT_NODE) {
|
||||
String nsURI;
|
||||
nsAutoString nsURI;
|
||||
if (((Element*)node)->getAttr(txXMLAtoms::xmlns, kNameSpaceID_XMLNS,
|
||||
nsURI)) {
|
||||
// xmlns = "" sets the default namespace ID to kNameSpaceID_None;
|
||||
|
@ -137,11 +136,8 @@ PRInt32 Element::getNamespaceID()
|
|||
mNamespaceID = kNameSpaceID_None;
|
||||
}
|
||||
else {
|
||||
String prefix;
|
||||
nodeName.subString(0, idx, prefix);
|
||||
txAtom* prefixAtom = TX_GET_ATOM(prefix);
|
||||
mNamespaceID = lookupNamespaceID(prefixAtom);
|
||||
TX_IF_RELEASE_ATOM(prefixAtom);
|
||||
nsCOMPtr<nsIAtom> prefix = do_GetAtom(Substring(nodeName, 0, idx));
|
||||
mNamespaceID = lookupNamespaceID(prefix);
|
||||
}
|
||||
return mNamespaceID;
|
||||
}
|
||||
|
@ -156,7 +152,7 @@ NamedNodeMap* Element::getAttributes()
|
|||
//name and value specified. Then add the Attr to the the Element's
|
||||
//mAttributes NamedNodeMap.
|
||||
//
|
||||
void Element::setAttribute(const String& name, const String& value)
|
||||
void Element::setAttribute(const nsAString& name, const nsAString& value)
|
||||
{
|
||||
// Check to see if an attribute with this name already exists. If it does
|
||||
// overwrite its value, if not, add it.
|
||||
|
@ -172,16 +168,15 @@ void Element::setAttribute(const String& name, const String& value)
|
|||
}
|
||||
}
|
||||
|
||||
void Element::setAttributeNS(const String& aNamespaceURI,
|
||||
const String& aName,
|
||||
const String& aValue)
|
||||
void Element::setAttributeNS(const nsAString& aNamespaceURI,
|
||||
const nsAString& aName,
|
||||
const nsAString& aValue)
|
||||
{
|
||||
// Check to see if an attribute with this name already exists. If it does
|
||||
// overwrite its value, if not, add it.
|
||||
PRInt32 namespaceID = txNamespaceManager::getNamespaceID(aNamespaceURI);
|
||||
String localPart;
|
||||
XMLUtils::getLocalPart(aName, localPart);
|
||||
txAtom* localName = TX_GET_ATOM(localPart);
|
||||
nsCOMPtr<nsIAtom> localName;
|
||||
XMLUtils::getLocalPart(aName, getter_AddRefs(localName));
|
||||
|
||||
Attr* foundNode = 0;
|
||||
AttrMap::ListItem* item = mAttributes.firstItem;
|
||||
|
@ -198,7 +193,6 @@ void Element::setAttributeNS(const String& aNamespaceURI,
|
|||
foundNode = 0;
|
||||
item = item->next;
|
||||
}
|
||||
TX_IF_RELEASE_ATOM(localName);
|
||||
|
||||
if (foundNode) {
|
||||
foundNode->setNodeValue(aValue);
|
||||
|
@ -215,7 +209,7 @@ void Element::setAttributeNS(const String& aNamespaceURI,
|
|||
//
|
||||
//Return the attribute specified by name
|
||||
//
|
||||
Attr* Element::getAttributeNode(const String& name)
|
||||
Attr* Element::getAttributeNode(const nsAString& name)
|
||||
{
|
||||
return (Attr*)mAttributes.getNamedItem(name);
|
||||
}
|
||||
|
@ -226,7 +220,7 @@ Attr* Element::getAttributeNode(const String& name)
|
|||
// Return false, if the attribute does not exist.
|
||||
//
|
||||
MBool Element::getAttr(txAtom* aLocalName, PRInt32 aNSID,
|
||||
String& aValue)
|
||||
nsAString& aValue)
|
||||
{
|
||||
aValue.Truncate();
|
||||
AttrMap::ListItem* item = mAttributes.firstItem;
|
||||
|
@ -236,7 +230,7 @@ MBool Element::getAttr(txAtom* aLocalName, PRInt32 aNSID,
|
|||
if (attrNode->getLocalName(&localName) &&
|
||||
aNSID == attrNode->getNamespaceID() &&
|
||||
aLocalName == localName) {
|
||||
aValue.Append(attrNode->getValue());
|
||||
attrNode->getNodeValue(aValue);
|
||||
TX_IF_RELEASE_ATOM(localName);
|
||||
return MB_TRUE;
|
||||
}
|
||||
|
|
|
@ -30,46 +30,46 @@
|
|||
//
|
||||
|
||||
#include "dom.h"
|
||||
#include "ArrayList.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "txURIUtils.h"
|
||||
#include "txAtoms.h"
|
||||
#include <string.h>
|
||||
|
||||
NodeDefinition::NodeDefinition(NodeType type, const String& name,
|
||||
const String& value, Document* owner)
|
||||
NodeDefinition::NodeDefinition(NodeType type, const nsAString& name,
|
||||
const nsAString& value, Document* owner)
|
||||
{
|
||||
nodeName = name;
|
||||
Init(type, value, owner);
|
||||
}
|
||||
|
||||
NodeDefinition::NodeDefinition(NodeType aType, const String& aValue,
|
||||
NodeDefinition::NodeDefinition(NodeType aType, const nsAString& aValue,
|
||||
Document* aOwner)
|
||||
{
|
||||
switch (aType)
|
||||
{
|
||||
case CDATA_SECTION_NODE:
|
||||
{
|
||||
nodeName.Append(NS_LITERAL_STRING("#cdata-section"));
|
||||
nodeName = NS_LITERAL_STRING("#cdata-section");
|
||||
break;
|
||||
}
|
||||
case COMMENT_NODE:
|
||||
{
|
||||
nodeName.Append(NS_LITERAL_STRING("#comment"));
|
||||
nodeName = NS_LITERAL_STRING("#comment");
|
||||
break;
|
||||
}
|
||||
case DOCUMENT_NODE:
|
||||
{
|
||||
nodeName.Append(NS_LITERAL_STRING("#document"));
|
||||
nodeName = NS_LITERAL_STRING("#document");
|
||||
break;
|
||||
}
|
||||
case DOCUMENT_FRAGMENT_NODE:
|
||||
{
|
||||
nodeName.Append(NS_LITERAL_STRING("#document-fragment"));
|
||||
nodeName = NS_LITERAL_STRING("#document-fragment");
|
||||
break;
|
||||
}
|
||||
case TEXT_NODE:
|
||||
{
|
||||
nodeName.Append(NS_LITERAL_STRING("#text"));
|
||||
nodeName = NS_LITERAL_STRING("#text");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -90,18 +90,18 @@ NodeDefinition::~NodeDefinition()
|
|||
}
|
||||
|
||||
void
|
||||
NodeDefinition::Init(NodeType aType, const String& aValue,
|
||||
NodeDefinition::Init(NodeType aType, const nsAString& aValue,
|
||||
Document* aOwner)
|
||||
{
|
||||
nodeType = aType;
|
||||
nodeValue = aValue;
|
||||
ownerDocument = aOwner;
|
||||
|
||||
parentNode = NULL;
|
||||
previousSibling = NULL;
|
||||
nextSibling = NULL;;
|
||||
firstChild = NULL;
|
||||
lastChild = NULL;
|
||||
parentNode = nsnull;
|
||||
previousSibling = nsnull;
|
||||
nextSibling = nsnull;;
|
||||
firstChild = nsnull;
|
||||
lastChild = nsnull;
|
||||
|
||||
length = 0;
|
||||
|
||||
|
@ -124,18 +124,20 @@ void NodeDefinition::DeleteChildren()
|
|||
}
|
||||
|
||||
length = 0;
|
||||
firstChild = NULL;
|
||||
lastChild = NULL;
|
||||
firstChild = nsnull;
|
||||
lastChild = nsnull;
|
||||
}
|
||||
|
||||
const String& NodeDefinition::getNodeName() const
|
||||
nsresult NodeDefinition::getNodeName(nsAString& aName) const
|
||||
{
|
||||
return nodeName;
|
||||
aName = nodeName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const String& NodeDefinition::getNodeValue()
|
||||
nsresult NodeDefinition::getNodeValue(nsAString& aValue)
|
||||
{
|
||||
return nodeValue;
|
||||
aValue = nodeValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
unsigned short NodeDefinition::getNodeType() const
|
||||
|
@ -191,7 +193,7 @@ Node* NodeDefinition::item(PRUint32 index)
|
|||
return pSelectNode;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRUint32 NodeDefinition::getLength()
|
||||
|
@ -199,7 +201,7 @@ PRUint32 NodeDefinition::getLength()
|
|||
return length;
|
||||
}
|
||||
|
||||
void NodeDefinition::setNodeValue(const String& newNodeValue)
|
||||
void NodeDefinition::setNodeValue(const nsAString& newNodeValue)
|
||||
{
|
||||
nodeValue = newNodeValue;
|
||||
}
|
||||
|
@ -258,7 +260,7 @@ NodeDefinition* NodeDefinition::implRemoveChild(NodeDefinition* oldChild)
|
|||
|
||||
MBool NodeDefinition::hasChildNodes() const
|
||||
{
|
||||
if (firstChild != NULL)
|
||||
if (firstChild)
|
||||
return MB_TRUE;
|
||||
else
|
||||
return MB_FALSE;
|
||||
|
@ -272,9 +274,9 @@ MBool NodeDefinition::getLocalName(txAtom** aLocalName)
|
|||
return MB_TRUE;
|
||||
}
|
||||
|
||||
const String& NodeDefinition::getNamespaceURI()
|
||||
nsresult NodeDefinition::getNamespaceURI(nsAString& aNSURI)
|
||||
{
|
||||
return txNamespaceManager::getNamespaceURI(getNamespaceID());
|
||||
return txNamespaceManager::getNamespaceURI(getNamespaceID(), aNSURI);
|
||||
}
|
||||
|
||||
PRInt32 NodeDefinition::getNamespaceID()
|
||||
|
@ -303,10 +305,10 @@ PRInt32 NodeDefinition::lookupNamespaceID(txAtom* aPrefix)
|
|||
if (node->getNodeType() != Node::ELEMENT_NODE)
|
||||
node = node->getXPathParent();
|
||||
|
||||
String name(NS_LITERAL_STRING("xmlns:"));
|
||||
nsAutoString name(NS_LITERAL_STRING("xmlns:"));
|
||||
if (aPrefix && (aPrefix != txXMLAtoms::_empty)) {
|
||||
// We have a prefix, search for xmlns:prefix attributes.
|
||||
String prefixString;
|
||||
nsAutoString prefixString;
|
||||
TX_GET_ATOM_STRING(aPrefix, prefixString);
|
||||
name.Append(prefixString);
|
||||
}
|
||||
|
@ -317,14 +319,15 @@ PRInt32 NodeDefinition::lookupNamespaceID(txAtom* aPrefix)
|
|||
}
|
||||
Attr* xmlns;
|
||||
while (node && node->getNodeType() == Node::ELEMENT_NODE) {
|
||||
String nsURI;
|
||||
if ((xmlns = ((Element*)node)->getAttributeNode(name))) {
|
||||
/*
|
||||
* xmlns:foo = "" makes "" a valid URI, so get that.
|
||||
* xmlns = "" resolves to 0 (null Namespace) (caught above)
|
||||
* in Element::getNamespaceID()
|
||||
*/
|
||||
return txNamespaceManager::getNamespaceID(xmlns->getValue());
|
||||
nsAutoString nsURI;
|
||||
xmlns->getNodeValue(nsURI);
|
||||
return txNamespaceManager::getNamespaceID(nsURI);
|
||||
}
|
||||
node = node->getXPathParent();
|
||||
}
|
||||
|
@ -344,23 +347,23 @@ Node* NodeDefinition::getXPathParent()
|
|||
//
|
||||
// @return base URI for the node
|
||||
//
|
||||
String NodeDefinition::getBaseURI()
|
||||
nsresult NodeDefinition::getBaseURI(nsAString& aURI)
|
||||
{
|
||||
Node* node = this;
|
||||
ArrayList baseUrls;
|
||||
String url;
|
||||
String attValue;
|
||||
nsStringArray baseUrls;
|
||||
nsAutoString url;
|
||||
|
||||
while (node) {
|
||||
switch (node->getNodeType()) {
|
||||
case Node::ELEMENT_NODE :
|
||||
if (((Element*)node)->getAttr(txXMLAtoms::base, kNameSpaceID_XML,
|
||||
attValue))
|
||||
baseUrls.add(new String(attValue));
|
||||
url))
|
||||
baseUrls.AppendString(url);
|
||||
break;
|
||||
|
||||
case Node::DOCUMENT_NODE :
|
||||
baseUrls.add(new String(((Document*)node)->getBaseURI()));
|
||||
node->getBaseURI(url);
|
||||
baseUrls.AppendString(url);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -369,19 +372,18 @@ String NodeDefinition::getBaseURI()
|
|||
node = node->getParentNode();
|
||||
}
|
||||
|
||||
if (baseUrls.size()) {
|
||||
url = *((String*)baseUrls.get(baseUrls.size()-1));
|
||||
PRInt32 count = baseUrls.Count();
|
||||
if (count) {
|
||||
baseUrls.StringAt(--count, aURI);
|
||||
|
||||
for (int i=baseUrls.size()-2;i>=0;i--) {
|
||||
String dest;
|
||||
URIUtils::resolveHref(*(String*)baseUrls.get(i), url, dest);
|
||||
url = dest;
|
||||
while (count > 0) {
|
||||
nsAutoString dest;
|
||||
URIUtils::resolveHref(*baseUrls[--count], aURI, dest);
|
||||
aURI = dest;
|
||||
}
|
||||
}
|
||||
|
||||
baseUrls.clear(MB_TRUE);
|
||||
|
||||
return url;
|
||||
return NS_OK;
|
||||
} // getBaseURI
|
||||
|
||||
/*
|
||||
|
|
|
@ -35,8 +35,8 @@
|
|||
//
|
||||
//Construct a text object with the specified document owner and data
|
||||
//
|
||||
ProcessingInstruction::ProcessingInstruction(const String& theTarget,
|
||||
const String& theData,
|
||||
ProcessingInstruction::ProcessingInstruction(const nsAString& theTarget,
|
||||
const nsAString& theData,
|
||||
Document* owner) :
|
||||
NodeDefinition(Node::PROCESSING_INSTRUCTION_NODE,
|
||||
theTarget, theData, owner)
|
||||
|
|
|
@ -30,33 +30,31 @@
|
|||
*/
|
||||
|
||||
#include "XMLUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "txAtoms.h"
|
||||
|
||||
nsresult txExpandedName::init(const String& aQName,
|
||||
nsresult txExpandedName::init(const nsAString& aQName,
|
||||
Node* aResolver,
|
||||
MBool aUseDefault)
|
||||
{
|
||||
NS_ASSERTION(aResolver, "missing resolve node");
|
||||
if (!XMLUtils::isValidQName(aQName))
|
||||
if (!XMLUtils::isValidQName(PromiseFlatString(aQName)))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PRInt32 idx = aQName.indexOf(':');
|
||||
PRInt32 idx = aQName.FindChar(':');
|
||||
if (idx != kNotFound) {
|
||||
String localName, prefixStr;
|
||||
aQName.subString(0, (PRUint32)idx, prefixStr);
|
||||
txAtom* prefix = TX_GET_ATOM(prefixStr);
|
||||
nsCOMPtr<nsIAtom> prefix =
|
||||
do_GetAtom(Substring(aQName, 0, (PRUint32)idx));
|
||||
PRInt32 namespaceID = aResolver->lookupNamespaceID(prefix);
|
||||
if (namespaceID == kNameSpaceID_Unknown)
|
||||
return NS_ERROR_FAILURE;
|
||||
mNamespaceID = namespaceID;
|
||||
|
||||
aQName.subString((PRUint32)idx + 1, localName);
|
||||
TX_IF_RELEASE_ATOM(mLocalName);
|
||||
mLocalName = TX_GET_ATOM(localName);
|
||||
mLocalName = do_GetAtom(Substring(aQName, (PRUint32)idx + 1,
|
||||
aQName.Length() - (idx + 1)));
|
||||
}
|
||||
else {
|
||||
TX_IF_RELEASE_ATOM(mLocalName);
|
||||
mLocalName = TX_GET_ATOM(aQName);
|
||||
mLocalName = do_GetAtom(aQName);
|
||||
if (aUseDefault)
|
||||
mNamespaceID = aResolver->lookupNamespaceID(0);
|
||||
else
|
||||
|
@ -69,38 +67,37 @@ nsresult txExpandedName::init(const String& aQName,
|
|||
//- Implementation of XMLUtils -/
|
||||
//------------------------------/
|
||||
|
||||
void XMLUtils::getPrefix(const String& src, String& dest)
|
||||
void XMLUtils::getPrefix(const nsAString& src, nsIAtom** dest)
|
||||
{
|
||||
// Anything preceding ':' is the namespace part of the name
|
||||
PRInt32 idx = src.indexOf(':');
|
||||
PRInt32 idx = src.FindChar(':');
|
||||
if (idx == kNotFound) {
|
||||
*dest = nsnull;
|
||||
return;
|
||||
}
|
||||
// Use a temporary String to prevent any chars in dest
|
||||
// from being lost.
|
||||
|
||||
NS_ASSERTION(idx > 0, "This QName looks invalid.");
|
||||
String tmp;
|
||||
src.subString(0, (PRUint32)idx, tmp);
|
||||
dest.Append(tmp);
|
||||
*dest = NS_NewAtom(Substring(src, 0, idx));
|
||||
}
|
||||
|
||||
void XMLUtils::getLocalPart(const String& src, String& dest)
|
||||
const nsDependentSubstring XMLUtils::getLocalPart(const nsAString& src)
|
||||
{
|
||||
// Anything after ':' is the local part of the name
|
||||
PRInt32 idx = src.indexOf(':');
|
||||
PRInt32 idx = src.FindChar(':');
|
||||
if (idx == kNotFound) {
|
||||
dest.Append(src);
|
||||
return;
|
||||
return Substring(src, 0, src.Length());
|
||||
}
|
||||
// Use a temporary String to prevent any chars in dest
|
||||
// from being lost.
|
||||
|
||||
NS_ASSERTION(idx > 0, "This QName looks invalid.");
|
||||
String tmp;
|
||||
src.subString((PRUint32)idx + 1, tmp);
|
||||
dest.Append(tmp);
|
||||
return Substring(src, idx + 1, src.Length() - (idx + 1));
|
||||
}
|
||||
|
||||
MBool XMLUtils::isValidQName(const String& aName)
|
||||
void XMLUtils::getLocalPart(const nsAString& src, nsIAtom** dest)
|
||||
{
|
||||
*dest = NS_NewAtom(getLocalPart(src));
|
||||
}
|
||||
|
||||
MBool XMLUtils::isValidQName(const nsAFlatString& aName)
|
||||
{
|
||||
if (aName.IsEmpty()) {
|
||||
return MB_FALSE;
|
||||
|
@ -142,27 +139,36 @@ MBool XMLUtils::isValidQName(const String& aName)
|
|||
|
||||
/**
|
||||
* Returns true if the given string has only whitespace characters
|
||||
**/
|
||||
MBool XMLUtils::isWhitespace(const String& aText)
|
||||
*/
|
||||
PRBool XMLUtils::isWhitespace(const nsAFlatString& aText)
|
||||
{
|
||||
const nsAFlatString& text = aText.getConstNSString();
|
||||
nsAFlatString::const_char_iterator start, end;
|
||||
text.BeginReading(start);
|
||||
text.EndReading(end);
|
||||
aText.BeginReading(start);
|
||||
aText.EndReading(end);
|
||||
for ( ; start != end; ++start) {
|
||||
if (!isWhitespace(*start)) {
|
||||
return MB_FALSE;
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return MB_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given node's value has only whitespace characters
|
||||
*/
|
||||
PRBool XMLUtils::isWhitespace(Node* aNode)
|
||||
{
|
||||
nsAutoString text;
|
||||
aNode->getNodeValue(text);
|
||||
return isWhitespace(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processing instruction
|
||||
**/
|
||||
void XMLUtils::normalizePIValue(String& piValue)
|
||||
void XMLUtils::normalizePIValue(nsAString& piValue)
|
||||
{
|
||||
String origValue(piValue);
|
||||
nsAutoString origValue(piValue);
|
||||
PRUint32 origLength = origValue.Length();
|
||||
PRUint32 conversionLoop = 0;
|
||||
PRUnichar prevCh = 0;
|
||||
|
@ -198,7 +204,7 @@ MBool XMLUtils::getXMLSpacePreserve(Node* aNode)
|
|||
{
|
||||
NS_ASSERTION(aNode, "Calling preserveXMLSpace with NULL node!");
|
||||
|
||||
String value;
|
||||
nsAutoString value;
|
||||
Node* parent = aNode;
|
||||
while (parent) {
|
||||
if (parent->getNodeType() == Node::ELEMENT_NODE) {
|
||||
|
|
|
@ -32,15 +32,13 @@
|
|||
|
||||
#include "baseutils.h"
|
||||
#include "dom.h"
|
||||
#include "nsDependentSubstring.h"
|
||||
#include "txAtom.h"
|
||||
#include "txError.h"
|
||||
|
||||
class String;
|
||||
|
||||
class txExpandedName {
|
||||
public:
|
||||
txExpandedName() : mNamespaceID(kNameSpaceID_None),
|
||||
mLocalName(0)
|
||||
txExpandedName() : mNamespaceID(kNameSpaceID_None)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -48,29 +46,24 @@ public:
|
|||
txAtom* aLocalName) : mNamespaceID(aNsID),
|
||||
mLocalName(aLocalName)
|
||||
{
|
||||
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);
|
||||
nsresult init(const nsAString& 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;
|
||||
}
|
||||
|
||||
|
@ -87,21 +80,21 @@ public:
|
|||
}
|
||||
|
||||
PRInt32 mNamespaceID;
|
||||
txAtom* mLocalName;
|
||||
nsCOMPtr<nsIAtom> mLocalName;
|
||||
};
|
||||
|
||||
class XMLUtils {
|
||||
|
||||
public:
|
||||
|
||||
static void getPrefix(const String& src, String& dest);
|
||||
static void getLocalPart(const String& src, String& dest);
|
||||
|
||||
static void getPrefix(const nsAString& src, txAtom** dest);
|
||||
static const nsDependentSubstring getLocalPart(const nsAString& src);
|
||||
static void getLocalPart(const nsAString& src, txAtom** dest);
|
||||
|
||||
/**
|
||||
* Returns true if the given String is a valid XML QName
|
||||
* Returns true if the given string is a valid XML QName
|
||||
*/
|
||||
static MBool isValidQName(const String& aName);
|
||||
static MBool isValidQName(const nsAFlatString& aName);
|
||||
|
||||
/*
|
||||
* Returns true if the given character is whitespace.
|
||||
|
@ -115,13 +108,19 @@ public:
|
|||
|
||||
/**
|
||||
* Returns true if the given string has only whitespace characters
|
||||
**/
|
||||
static MBool isWhitespace(const String& aText);
|
||||
*/
|
||||
static PRBool isWhitespace(const nsAFlatString& aText);
|
||||
|
||||
/**
|
||||
* Returns true if the given node's DOM nodevalue has only whitespace
|
||||
* characters
|
||||
*/
|
||||
static PRBool isWhitespace(Node* aNode);
|
||||
|
||||
/**
|
||||
* Normalizes the value of a XML processingInstruction
|
||||
**/
|
||||
static void normalizePIValue(String& attValue);
|
||||
static void normalizePIValue(nsAString& attValue);
|
||||
|
||||
/*
|
||||
* Returns true if the given character represents a numeric letter (digit).
|
||||
|
|
|
@ -73,9 +73,9 @@ nsXPathEvaluator::CreateExpression(const nsAString & aExpression,
|
|||
nsIDOMXPathNSResolver *aResolver,
|
||||
nsIDOMXPathExpression **aResult)
|
||||
{
|
||||
String expressionString(aExpression);
|
||||
ParseContextImpl pContext(aResolver);
|
||||
Expr* expression = ExprParser::createExpr(expressionString, &pContext);
|
||||
Expr* expression = ExprParser::createExpr(PromiseFlatString(aExpression),
|
||||
&pContext);
|
||||
if (!expression)
|
||||
return NS_ERROR_DOM_INVALID_EXPRESSION_ERR;
|
||||
|
||||
|
@ -162,8 +162,8 @@ nsresult nsXPathEvaluator::ParseContextImpl::resolveFunctionCall(txAtom* aName,
|
|||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
}
|
||||
|
||||
void nsXPathEvaluator::ParseContextImpl::receiveError(const String& aMsg,
|
||||
nsresult aRes)
|
||||
void nsXPathEvaluator::ParseContextImpl::receiveError(const nsAString& aMsg,
|
||||
nsresult aRes)
|
||||
{
|
||||
mLastError = aRes;
|
||||
// forward aMsg to console service?
|
||||
|
|
|
@ -80,7 +80,7 @@ private:
|
|||
nsresult resolveNamespacePrefix(txAtom* aPrefix, PRInt32& aID);
|
||||
nsresult resolveFunctionCall(txAtom* aName, PRInt32 aID,
|
||||
FunctionCall*& aFunction);
|
||||
void receiveError(const String& aMsg, nsresult aRes);
|
||||
void receiveError(const nsAString& aMsg, nsresult aRes);
|
||||
|
||||
private:
|
||||
nsIDOMXPathNSResolver* mResolver;
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include "nsCRT.h"
|
||||
#include "nsIDOMClassInfo.h"
|
||||
#include "nsIBaseDOMException.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
|
||||
static const char* kInvalidExpressionErrName = "NS_ERROR_DOM_INVALID_EXPRESSION_ERR";
|
||||
|
|
|
@ -178,8 +178,8 @@ MBool nsXPathExpression::EvalContextImpl::isStripSpaceAllowed(Node* aNode)
|
|||
return MB_FALSE;
|
||||
}
|
||||
|
||||
void nsXPathExpression::EvalContextImpl::receiveError(const String& aMsg,
|
||||
nsresult aRes)
|
||||
void nsXPathExpression::EvalContextImpl::receiveError(const nsAString& aMsg,
|
||||
nsresult aRes)
|
||||
{
|
||||
mLastError = aRes;
|
||||
// forward aMsg to console service?
|
||||
|
|
|
@ -276,7 +276,7 @@ nsXPathResult::SetExprResult(ExprResult* aExprResult, PRUint16 aResultType)
|
|||
}
|
||||
|
||||
if (mResultType == STRING_TYPE) {
|
||||
mStringValue = new String;
|
||||
mStringValue = new nsString;
|
||||
NS_ENSURE_TRUE(mStringValue, NS_ERROR_OUT_OF_MEMORY);
|
||||
aExprResult->stringValue(*mStringValue);
|
||||
return NS_OK;
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "nsCOMArray.h"
|
||||
|
||||
class ExprResult;
|
||||
class String;
|
||||
|
||||
// {15b9b301-2012-11d6-a7f2-e6d0a678995c}
|
||||
#define NS_IXPATHRESULT_IID \
|
||||
|
@ -90,7 +89,7 @@ private:
|
|||
|
||||
union {
|
||||
double mNumberValue;
|
||||
String* mStringValue;
|
||||
nsString* mStringValue;
|
||||
PRBool mBooleanValue;
|
||||
nsIDOMNode* mNode;
|
||||
nsCOMArray<nsIDOMNode>* mElements;
|
||||
|
|
|
@ -94,7 +94,7 @@ ExprResult* AdditiveExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void AdditiveExpr::toString(String& str) {
|
||||
void AdditiveExpr::toString(nsAString& str) {
|
||||
|
||||
if ( leftExpr ) leftExpr->toString(str);
|
||||
else str.Append(NS_LITERAL_STRING("null"));
|
||||
|
|
|
@ -62,7 +62,7 @@ void AttributeValueTemplate::addExpr(Expr* expr) {
|
|||
ExprResult* AttributeValueTemplate::evaluate(txIEvalContext* aContext)
|
||||
{
|
||||
txListIterator iter(&expressions);
|
||||
String result;
|
||||
nsAutoString result;
|
||||
while (iter.hasNext()) {
|
||||
Expr* expr = (Expr*)iter.next();
|
||||
ExprResult* exprResult = expr->evaluate(aContext);
|
||||
|
@ -80,7 +80,7 @@ ExprResult* AttributeValueTemplate::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void AttributeValueTemplate::toString(String& str) {
|
||||
void AttributeValueTemplate::toString(nsAString& str) {
|
||||
txListIterator iter(&expressions);
|
||||
while (iter.hasNext()) {
|
||||
str.Append(PRUnichar('{'));
|
||||
|
|
|
@ -92,7 +92,7 @@ ExprResult* BooleanExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void BooleanExpr::toString(String& str) {
|
||||
void BooleanExpr::toString(nsAString& str) {
|
||||
|
||||
if ( leftExpr ) leftExpr->toString(str);
|
||||
else str.Append(NS_LITERAL_STRING("null"));
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
#include "FunctionLib.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "txStringUtils.h"
|
||||
|
||||
/**
|
||||
* Creates a default BooleanFunctionCall, which always evaluates to False
|
||||
|
@ -65,7 +67,7 @@ ExprResult* BooleanFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(1, 1, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String lang;
|
||||
nsAutoString lang;
|
||||
Node* node = aContext->getContextNode();
|
||||
while (node) {
|
||||
if (node->getNodeType() == Node::ELEMENT_NODE) {
|
||||
|
@ -79,11 +81,10 @@ ExprResult* BooleanFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
MBool result = MB_FALSE;
|
||||
if (node) {
|
||||
String arg;
|
||||
nsAutoString arg;
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg);
|
||||
arg.toUpperCase(); // case-insensitive comparison
|
||||
lang.toUpperCase();
|
||||
result = lang.indexOf(arg) == 0 &&
|
||||
result = arg.Equals(Substring(lang, 0, arg.Length()),
|
||||
txCaseInsensitiveStringComparator()) &&
|
||||
(lang.Length() == arg.Length() ||
|
||||
lang.CharAt(arg.Length()) == '-');
|
||||
}
|
||||
|
@ -114,8 +115,8 @@ ExprResult* BooleanFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
|
||||
String err(NS_LITERAL_STRING("Internal error"));
|
||||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
aContext->receiveError(NS_LITERAL_STRING("Internal error"),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ short BooleanResult::getResultType() {
|
|||
return ExprResult::BOOLEAN;
|
||||
} //-- getResultType
|
||||
|
||||
void BooleanResult::stringValue(String& str) {
|
||||
void BooleanResult::stringValue(nsAString& str) {
|
||||
if ( value ) str.Append(NS_LITERAL_STRING("true"));
|
||||
else str.Append(NS_LITERAL_STRING("false"));
|
||||
} //-- toString
|
||||
|
|
|
@ -38,9 +38,9 @@
|
|||
#include "baseutils.h"
|
||||
#include "dom.h"
|
||||
#include "List.h"
|
||||
#include "nsString.h"
|
||||
#include "txAtom.h"
|
||||
#include "TxObject.h"
|
||||
#include "TxString.h"
|
||||
|
||||
/*
|
||||
XPath class definitions.
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
virtual void toString(String& str) = 0;
|
||||
virtual void toString(nsAString& str) = 0;
|
||||
|
||||
}; //-- Expr
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
#define TX_DECL_EXPR \
|
||||
TX_DECL_EVALUATE; \
|
||||
void toString(String& aDest)
|
||||
void toString(nsAString& aDest)
|
||||
|
||||
#define TX_DECL_FUNCTION \
|
||||
TX_DECL_EVALUATE; \
|
||||
|
@ -107,8 +107,8 @@ class FunctionCall : public Expr {
|
|||
|
||||
public:
|
||||
|
||||
static const String INVALID_PARAM_COUNT;
|
||||
static const String INVALID_PARAM_VALUE;
|
||||
static const nsString INVALID_PARAM_COUNT;
|
||||
static const nsString INVALID_PARAM_VALUE;
|
||||
|
||||
virtual ~FunctionCall();
|
||||
|
||||
|
@ -116,7 +116,7 @@ public:
|
|||
* Virtual methods from Expr
|
||||
**/
|
||||
virtual ExprResult* evaluate(txIEvalContext* aContext) = 0;
|
||||
void toString(String& aDest);
|
||||
void toString(nsAString& aDest);
|
||||
|
||||
/**
|
||||
* Adds the given parameter to this FunctionCall's parameter list
|
||||
|
@ -143,7 +143,7 @@ protected:
|
|||
* The value is appended to the given destination String
|
||||
*/
|
||||
void evaluateToString(Expr* aExpr, txIEvalContext* aContext,
|
||||
String& aDest);
|
||||
nsAString& aDest);
|
||||
|
||||
/*
|
||||
* Evaluates the given Expression and converts its result to a number.
|
||||
|
@ -206,13 +206,13 @@ public:
|
|||
*/
|
||||
virtual MBool matches(Node* aNode, txIMatchContext* aContext) = 0;
|
||||
virtual double getDefaultPriority() = 0;
|
||||
virtual void toString(String& aDest) = 0;
|
||||
virtual void toString(nsAString& aDest) = 0;
|
||||
};
|
||||
|
||||
#define TX_DECL_NODE_TEST \
|
||||
MBool matches(Node* aNode, txIMatchContext* aContext); \
|
||||
double getDefaultPriority(); \
|
||||
void toString(String& aDest)
|
||||
void toString(nsAString& aDest)
|
||||
|
||||
/*
|
||||
* This class represents a NameTest as defined by the XPath spec
|
||||
|
@ -261,7 +261,7 @@ public:
|
|||
/*
|
||||
* Sets the name of the node to match. Only availible for pi nodes
|
||||
*/
|
||||
void setNodeName(const String& aName);
|
||||
void setNodeName(const nsAString& aName);
|
||||
|
||||
TX_DECL_NODE_TEST;
|
||||
|
||||
|
@ -309,7 +309,7 @@ public:
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this PredicateList.
|
||||
**/
|
||||
virtual void toString(String& dest);
|
||||
virtual void toString(nsAString& dest);
|
||||
|
||||
protected:
|
||||
//-- list of predicates
|
||||
|
@ -408,13 +408,13 @@ class StringExpr : public Expr {
|
|||
|
||||
public:
|
||||
|
||||
StringExpr(const String& value);
|
||||
StringExpr(const nsAString& value);
|
||||
|
||||
TX_DECL_EXPR;
|
||||
|
||||
private:
|
||||
|
||||
String value;
|
||||
nsString value;
|
||||
}; //-- StringExpr
|
||||
|
||||
|
||||
|
@ -596,8 +596,6 @@ public:
|
|||
TX_DECL_EXPR;
|
||||
|
||||
private:
|
||||
static const String RTF_INVALID_OP;
|
||||
static const String NODESET_EXPECTED;
|
||||
struct PathExprItem {
|
||||
Expr* expr;
|
||||
PathOperator pathOp;
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
**/
|
||||
|
||||
#include "ExprLexer.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txStringUtils.h"
|
||||
#include "XMLUtils.h"
|
||||
|
||||
//---------------------------/
|
||||
|
@ -68,7 +70,7 @@ Token::Token(short type)
|
|||
* @param value the value of this Token
|
||||
* @param type, the type of Token being represented
|
||||
**/
|
||||
Token::Token(const String& value, short type)
|
||||
Token::Token(const nsAString& value, short type)
|
||||
{
|
||||
this->type = type;
|
||||
//-- make copy of value String
|
||||
|
@ -103,44 +105,14 @@ Token::~Token()
|
|||
//- Implementation of ExprLexer -/
|
||||
//-------------------------------/
|
||||
|
||||
/*
|
||||
* Complex Tokens
|
||||
*/
|
||||
//-- Nodetype tokens
|
||||
const String ExprLexer::COMMENT(NS_LITERAL_STRING("comment"));
|
||||
const String ExprLexer::NODE(NS_LITERAL_STRING("node"));
|
||||
const String ExprLexer::PROC_INST(NS_LITERAL_STRING("processing-instruction"));
|
||||
const String ExprLexer::TEXT(NS_LITERAL_STRING("text"));
|
||||
|
||||
//-- boolean
|
||||
const String ExprLexer::AND(NS_LITERAL_STRING("and"));
|
||||
const String ExprLexer::OR(NS_LITERAL_STRING("or"));
|
||||
|
||||
//-- multiplicative operators
|
||||
const String ExprLexer::MODULUS(NS_LITERAL_STRING("mod"));
|
||||
const String ExprLexer::DIVIDE(NS_LITERAL_STRING("div"));
|
||||
|
||||
/**
|
||||
* The set of Lexer error messages
|
||||
**/
|
||||
const String ExprLexer::error_message[] =
|
||||
{
|
||||
String(NS_LITERAL_STRING("VariableReference expected")),
|
||||
String(NS_LITERAL_STRING("Operator expected")),
|
||||
String(NS_LITERAL_STRING("Literal is not closed")),
|
||||
String(NS_LITERAL_STRING(": not expected")),
|
||||
String(NS_LITERAL_STRING("! not expected, use != or not()")),
|
||||
String(NS_LITERAL_STRING("found a unkown character"))
|
||||
};
|
||||
|
||||
//---------------/
|
||||
//- Contructors -/
|
||||
//---------------/
|
||||
|
||||
/**
|
||||
* Creates a new ExprLexer using the given String
|
||||
* Creates a new ExprLexer using the given string
|
||||
**/
|
||||
ExprLexer::ExprLexer(const String& pattern)
|
||||
ExprLexer::ExprLexer(const nsAFlatString& pattern)
|
||||
{
|
||||
firstItem = 0;
|
||||
lastItem = 0;
|
||||
|
@ -230,14 +202,14 @@ MBool ExprLexer::nextIsOperatorToken(Token* token)
|
|||
} //-- nextIsOperatorToken
|
||||
|
||||
/**
|
||||
* Parses the given String into the set of Tokens
|
||||
* Parses the given string into the set of Tokens
|
||||
**/
|
||||
void ExprLexer::parse(const String& pattern)
|
||||
void ExprLexer::parse(const nsAFlatString& pattern)
|
||||
{
|
||||
if (pattern.IsEmpty())
|
||||
return;
|
||||
|
||||
String tokenBuffer;
|
||||
nsAutoString tokenBuffer;
|
||||
PRUint32 iter = 0, start;
|
||||
PRUint32 size = pattern.Length();
|
||||
short defType;
|
||||
|
@ -291,13 +263,17 @@ void ExprLexer::parse(const String& pattern)
|
|||
iter--; // step back
|
||||
}
|
||||
if (nextIsOperatorToken(prevToken)) {
|
||||
if (pattern.subString(start,iter,subStr).Equals(AND))
|
||||
if (TX_StringEqualsAtom(Substring(pattern, start, iter - start),
|
||||
txXPathAtoms::_and))
|
||||
defType = Token::AND_OP;
|
||||
else if (pattern.subString(start,iter,subStr).Equals(OR))
|
||||
else if (TX_StringEqualsAtom(Substring(pattern, start, iter - start),
|
||||
txXPathAtoms::_or))
|
||||
defType = Token::OR_OP;
|
||||
else if (pattern.subString(start,iter,subStr).Equals(MODULUS))
|
||||
else if (TX_StringEqualsAtom(Substring(pattern, start, iter - start),
|
||||
txXPathAtoms::mod))
|
||||
defType = Token::MODULUS_OP;
|
||||
else if (pattern.subString(start,iter,subStr).Equals(DIVIDE))
|
||||
else if (TX_StringEqualsAtom(Substring(pattern, start, iter - start),
|
||||
txXPathAtoms::div))
|
||||
defType = Token::DIVIDE_OP;
|
||||
else {
|
||||
// Error "operator expected"
|
||||
|
@ -312,7 +288,7 @@ void ExprLexer::parse(const String& pattern)
|
|||
iter=size; // bail
|
||||
}
|
||||
}
|
||||
addToken(new Token(pattern.subString(start,iter,subStr),defType));
|
||||
addToken(new Token(Substring(pattern, start, iter - start), defType));
|
||||
}
|
||||
else if (isXPathDigit(ch)) {
|
||||
start = iter;
|
||||
|
@ -321,7 +297,8 @@ void ExprLexer::parse(const String& pattern)
|
|||
if (iter < size && pattern.CharAt(iter) == '.')
|
||||
while (++iter < size &&
|
||||
isXPathDigit(pattern.CharAt(iter))) /* just go */;
|
||||
addToken(new Token(pattern.subString(start,iter,subStr),Token::NUMBER));
|
||||
addToken(new Token(Substring(pattern, start, iter - start),
|
||||
Token::NUMBER));
|
||||
}
|
||||
else {
|
||||
switch (ch) {
|
||||
|
@ -335,7 +312,7 @@ void ExprLexer::parse(const String& pattern)
|
|||
case S_QUOTE :
|
||||
case D_QUOTE :
|
||||
start=iter;
|
||||
iter = pattern.indexOf(ch, (PRInt32)start + 1);
|
||||
iter = pattern.FindChar(ch, start + 1);
|
||||
if ((PRInt32)iter == kNotFound) {
|
||||
// XXX Error reporting "unclosed literal"
|
||||
errorPos = start;
|
||||
|
@ -347,7 +324,7 @@ void ExprLexer::parse(const String& pattern)
|
|||
iter=size; // bail
|
||||
}
|
||||
else {
|
||||
addToken(new Token(pattern.subString(start+1,iter,subStr),
|
||||
addToken(new Token(Substring(pattern, start + 1, iter - (start + 1)),
|
||||
Token::LITERAL));
|
||||
++iter;
|
||||
}
|
||||
|
@ -360,11 +337,11 @@ void ExprLexer::parse(const String& pattern)
|
|||
start=iter-1;
|
||||
while (++iter < size &&
|
||||
isXPathDigit(pattern.CharAt(iter))) /* just go */;
|
||||
addToken(new Token(pattern.subString(start,iter,subStr),
|
||||
addToken(new Token(Substring(pattern, start, iter - start),
|
||||
Token::NUMBER));
|
||||
}
|
||||
else if (ch==PERIOD) {
|
||||
addToken(new Token(pattern.subString(iter-1,iter++,subStr),
|
||||
addToken(new Token(Substring(pattern, ++iter - 2, 2),
|
||||
Token::PARENT_NODE));
|
||||
}
|
||||
else
|
||||
|
@ -376,7 +353,7 @@ void ExprLexer::parse(const String& pattern)
|
|||
|
||||
break;
|
||||
case COLON: // QNames are dealt above, must be axis ident
|
||||
if (++iter < size && pattern.CharAt(iter)==COLON &&
|
||||
if (++iter < size && pattern.CharAt(iter) == COLON &&
|
||||
prevToken->type == Token::CNAME) {
|
||||
prevToken->type = Token::AXIS_IDENTIFIER;
|
||||
++iter;
|
||||
|
@ -393,8 +370,8 @@ void ExprLexer::parse(const String& pattern)
|
|||
}
|
||||
break;
|
||||
case FORWARD_SLASH :
|
||||
if (++iter < size && pattern.CharAt(iter)==ch) {
|
||||
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
|
||||
if (++iter < size && pattern.CharAt(iter) == ch) {
|
||||
addToken(new Token(Substring(pattern, ++iter - 2, 2),
|
||||
Token::ANCESTOR_OP));
|
||||
}
|
||||
else {
|
||||
|
@ -402,8 +379,8 @@ void ExprLexer::parse(const String& pattern)
|
|||
}
|
||||
break;
|
||||
case BANG : // can only be !=
|
||||
if (++iter < size && pattern.CharAt(iter)==EQUAL) {
|
||||
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
|
||||
if (++iter < size && pattern.CharAt(iter) == EQUAL) {
|
||||
addToken(new Token(Substring(pattern, ++iter - 2, 2),
|
||||
Token::NOT_EQUAL_OP));
|
||||
}
|
||||
else {
|
||||
|
@ -422,16 +399,16 @@ void ExprLexer::parse(const String& pattern)
|
|||
++iter;
|
||||
break;
|
||||
case L_ANGLE:
|
||||
if (++iter < size && pattern.CharAt(iter)==EQUAL) {
|
||||
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
|
||||
if (++iter < size && pattern.CharAt(iter) == EQUAL) {
|
||||
addToken(new Token(Substring(pattern, ++iter - 2, 2),
|
||||
Token::LESS_OR_EQUAL_OP));
|
||||
}
|
||||
else
|
||||
addToken(new Token(ch,Token::LESS_THAN_OP));
|
||||
break;
|
||||
case R_ANGLE:
|
||||
if (++iter < size && pattern.CharAt(iter)==EQUAL) {
|
||||
addToken(new Token(pattern.subString(iter-1,++iter,subStr),
|
||||
if (++iter < size && pattern.CharAt(iter) == EQUAL) {
|
||||
addToken(new Token(Substring(pattern, ++iter - 2, 2),
|
||||
Token::GREATER_OR_EQUAL_OP));
|
||||
}
|
||||
else
|
||||
|
@ -450,13 +427,14 @@ void ExprLexer::parse(const String& pattern)
|
|||
break;
|
||||
case L_PAREN:
|
||||
if (prevToken->type == Token::CNAME) {
|
||||
if (prevToken->value.Equals(COMMENT))
|
||||
if (TX_StringEqualsAtom(prevToken->value, txXPathAtoms::comment))
|
||||
prevToken->type = Token::COMMENT;
|
||||
else if (prevToken->value.Equals(NODE))
|
||||
else if (TX_StringEqualsAtom(prevToken->value, txXPathAtoms::node))
|
||||
prevToken->type = Token::NODE;
|
||||
else if (prevToken->value.Equals(PROC_INST))
|
||||
else if (TX_StringEqualsAtom(prevToken->value,
|
||||
txXPathAtoms::processingInstruction))
|
||||
prevToken->type = Token::PROC_INST;
|
||||
else if (prevToken->value.Equals(TEXT))
|
||||
else if (TX_StringEqualsAtom(prevToken->value, txXPathAtoms::text))
|
||||
prevToken->type = Token::TEXT;
|
||||
else
|
||||
prevToken->type = Token::FUNCTION_NAME;
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
#ifndef MITREXSL_EXPRLEXER_H
|
||||
#define MITREXSL_EXPRLEXER_H
|
||||
|
||||
#include "TxString.h"
|
||||
#include "baseutils.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/**
|
||||
* A Token class for the ExprLexer.
|
||||
|
@ -118,7 +118,7 @@ public:
|
|||
**/
|
||||
Token();
|
||||
Token(short type);
|
||||
Token(const String& value, short type);
|
||||
Token(const nsAString& value, short type);
|
||||
Token(PRUnichar uniChar, short type);
|
||||
/**
|
||||
* Copy Constructor
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
Token(const Token& token);
|
||||
|
||||
~Token();
|
||||
String value;
|
||||
nsString value;
|
||||
short type;
|
||||
}; //--Token
|
||||
|
||||
|
@ -181,27 +181,9 @@ public:
|
|||
ERROR_BANG,
|
||||
ERROR_UNKNOWN_CHAR
|
||||
};
|
||||
static const String error_message[];
|
||||
PRUint32 errorPos;
|
||||
short errorCode;
|
||||
|
||||
/*
|
||||
* Complex Tokens
|
||||
*/
|
||||
//-- Nodetype tokens
|
||||
static const String COMMENT;
|
||||
static const String NODE;
|
||||
static const String PROC_INST;
|
||||
static const String TEXT;
|
||||
|
||||
//-- boolean
|
||||
static const String AND;
|
||||
static const String OR;
|
||||
|
||||
//-- Multiplicative
|
||||
static const String MODULUS;
|
||||
static const String DIVIDE;
|
||||
|
||||
/*
|
||||
* Default Token Set
|
||||
*/
|
||||
|
@ -211,7 +193,7 @@ public:
|
|||
/**
|
||||
* Constructor for ExprLexer
|
||||
**/
|
||||
ExprLexer(const String& pattern);
|
||||
ExprLexer(const nsAFlatString& pattern);
|
||||
|
||||
~ExprLexer();
|
||||
|
||||
|
@ -259,8 +241,7 @@ private:
|
|||
return (ch >= '0' && ch <= '9');
|
||||
}
|
||||
|
||||
String subStr;
|
||||
void parse(const String& pattern);
|
||||
void parse(const nsAFlatString& pattern);
|
||||
|
||||
}; //-- ExprLexer
|
||||
|
||||
|
|
|
@ -41,72 +41,10 @@
|
|||
#include "ExprParser.h"
|
||||
#include "ExprLexer.h"
|
||||
#include "FunctionLib.h"
|
||||
#include "Names.h"
|
||||
#include "Stack.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txIXPathContext.h"
|
||||
|
||||
// XXX This is ugly, but this is the last file to use them,
|
||||
// once we convert the parser to directly compare with
|
||||
// atoms we should remove these.
|
||||
class XPathNames {
|
||||
public:
|
||||
static const String BOOLEAN_FN;
|
||||
static const String CONCAT_FN;
|
||||
static const String CONTAINS_FN;
|
||||
static const String COUNT_FN ;
|
||||
static const String FALSE_FN;
|
||||
static const String ID_FN;
|
||||
static const String LANG_FN;
|
||||
static const String LAST_FN;
|
||||
static const String LOCAL_NAME_FN;
|
||||
static const String NAME_FN;
|
||||
static const String NAMESPACE_URI_FN;
|
||||
static const String NORMALIZE_SPACE_FN;
|
||||
static const String NOT_FN;
|
||||
static const String POSITION_FN;
|
||||
static const String STARTS_WITH_FN;
|
||||
static const String STRING_FN;
|
||||
static const String STRING_LENGTH_FN;
|
||||
static const String SUBSTRING_FN;
|
||||
static const String SUBSTRING_AFTER_FN;
|
||||
static const String SUBSTRING_BEFORE_FN;
|
||||
static const String SUM_FN;
|
||||
static const String TRANSLATE_FN;
|
||||
static const String TRUE_FN;
|
||||
static const String NUMBER_FN;
|
||||
static const String ROUND_FN;
|
||||
static const String CEILING_FN;
|
||||
static const String FLOOR_FN;
|
||||
};
|
||||
|
||||
const String XPathNames::BOOLEAN_FN(NS_LITERAL_STRING("boolean"));
|
||||
const String XPathNames::CONCAT_FN(NS_LITERAL_STRING("concat"));
|
||||
const String XPathNames::CONTAINS_FN(NS_LITERAL_STRING("contains"));
|
||||
const String XPathNames::COUNT_FN(NS_LITERAL_STRING("count"));
|
||||
const String XPathNames::FALSE_FN(NS_LITERAL_STRING("false"));
|
||||
const String XPathNames::ID_FN(NS_LITERAL_STRING("id"));
|
||||
const String XPathNames::LAST_FN(NS_LITERAL_STRING("last"));
|
||||
const String XPathNames::LOCAL_NAME_FN(NS_LITERAL_STRING("local-name"));
|
||||
const String XPathNames::NAME_FN(NS_LITERAL_STRING("name"));
|
||||
const String XPathNames::NAMESPACE_URI_FN(NS_LITERAL_STRING("namespace-uri"));
|
||||
const String XPathNames::NORMALIZE_SPACE_FN(NS_LITERAL_STRING("normalize-space"));
|
||||
const String XPathNames::NOT_FN(NS_LITERAL_STRING("not"));
|
||||
const String XPathNames::POSITION_FN(NS_LITERAL_STRING("position"));
|
||||
const String XPathNames::STARTS_WITH_FN(NS_LITERAL_STRING("starts-with"));
|
||||
const String XPathNames::STRING_FN(NS_LITERAL_STRING("string"));
|
||||
const String XPathNames::STRING_LENGTH_FN(NS_LITERAL_STRING("string-length"));
|
||||
const String XPathNames::SUBSTRING_FN(NS_LITERAL_STRING("substring"));
|
||||
const String XPathNames::SUBSTRING_AFTER_FN(NS_LITERAL_STRING("substring-after"));
|
||||
const String XPathNames::SUBSTRING_BEFORE_FN(NS_LITERAL_STRING("substring-before"));
|
||||
const String XPathNames::SUM_FN(NS_LITERAL_STRING("sum"));
|
||||
const String XPathNames::TRANSLATE_FN(NS_LITERAL_STRING("translate"));
|
||||
const String XPathNames::TRUE_FN(NS_LITERAL_STRING("true"));
|
||||
const String XPathNames::NUMBER_FN(NS_LITERAL_STRING("number"));
|
||||
const String XPathNames::ROUND_FN(NS_LITERAL_STRING("round"));
|
||||
const String XPathNames::CEILING_FN(NS_LITERAL_STRING("ceiling"));
|
||||
const String XPathNames::FLOOR_FN(NS_LITERAL_STRING("floor"));
|
||||
const String XPathNames::LANG_FN(NS_LITERAL_STRING("lang"));
|
||||
#include "txStringUtils.h"
|
||||
|
||||
|
||||
/**
|
||||
|
@ -114,7 +52,7 @@ const String XPathNames::LANG_FN(NS_LITERAL_STRING("lang"));
|
|||
* This should move to XSLProcessor class
|
||||
**/
|
||||
AttributeValueTemplate* ExprParser::createAttributeValueTemplate
|
||||
(const String& attValue, txIParseContext* aContext)
|
||||
(const nsAFlatString& attValue, txIParseContext* aContext)
|
||||
{
|
||||
AttributeValueTemplate* avt = new AttributeValueTemplate();
|
||||
if (!avt) {
|
||||
|
@ -129,7 +67,7 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate
|
|||
PRUint32 cc = 0;
|
||||
PRUnichar nextCh;
|
||||
PRUnichar ch;
|
||||
String buffer;
|
||||
nsAutoString buffer;
|
||||
MBool inExpr = MB_FALSE;
|
||||
MBool inLiteral = MB_FALSE;
|
||||
PRUnichar endLiteral = 0;
|
||||
|
@ -229,7 +167,7 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate
|
|||
|
||||
} //-- createAttributeValueTemplate
|
||||
|
||||
Expr* ExprParser::createExpr(const String& aExpression,
|
||||
Expr* ExprParser::createExpr(const nsAFlatString& aExpression,
|
||||
txIParseContext* aContext)
|
||||
{
|
||||
ExprLexer lexer(aExpression);
|
||||
|
@ -470,85 +408,85 @@ Expr* ExprParser::createFunctionCall(ExprLexer& lexer,
|
|||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (XPathNames::BOOLEAN_FN.Equals(tok->value)) {
|
||||
if (TX_StringEqualsAtom(tok->value, txXPathAtoms::boolean)) {
|
||||
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_BOOLEAN);
|
||||
}
|
||||
else if (XPathNames::CONCAT_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::concat)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::CONCAT);
|
||||
}
|
||||
else if (XPathNames::CONTAINS_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::contains)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::CONTAINS);
|
||||
}
|
||||
else if (XPathNames::COUNT_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::count)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::COUNT);
|
||||
}
|
||||
else if (XPathNames::FALSE_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::_false)) {
|
||||
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_FALSE);
|
||||
}
|
||||
else if (XPathNames::ID_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::id)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::ID);
|
||||
}
|
||||
else if (XPathNames::LANG_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::lang)) {
|
||||
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_LANG);
|
||||
}
|
||||
else if (XPathNames::LAST_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::last)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LAST);
|
||||
}
|
||||
else if (XPathNames::LOCAL_NAME_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::localName)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::LOCAL_NAME);
|
||||
}
|
||||
else if (XPathNames::NAME_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::name)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAME);
|
||||
}
|
||||
else if (XPathNames::NAMESPACE_URI_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::namespaceUri)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::NAMESPACE_URI);
|
||||
}
|
||||
else if (XPathNames::NORMALIZE_SPACE_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::normalizeSpace)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::NORMALIZE_SPACE);
|
||||
}
|
||||
else if (XPathNames::NOT_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::_not)) {
|
||||
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_NOT);
|
||||
}
|
||||
else if (XPathNames::POSITION_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::position)) {
|
||||
fnCall = new NodeSetFunctionCall(NodeSetFunctionCall::POSITION);
|
||||
}
|
||||
else if (XPathNames::STARTS_WITH_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::startsWith)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::STARTS_WITH);
|
||||
}
|
||||
else if (XPathNames::STRING_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::string)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::STRING);
|
||||
}
|
||||
else if (XPathNames::STRING_LENGTH_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::stringLength)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::STRING_LENGTH);
|
||||
}
|
||||
else if (XPathNames::SUBSTRING_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::substring)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING);
|
||||
}
|
||||
else if (XPathNames::SUBSTRING_AFTER_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::substringAfter)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_AFTER);
|
||||
}
|
||||
else if (XPathNames::SUBSTRING_BEFORE_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::substringBefore)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::SUBSTRING_BEFORE);
|
||||
}
|
||||
else if (XPathNames::SUM_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::sum)) {
|
||||
fnCall = new NumberFunctionCall(NumberFunctionCall::SUM);
|
||||
}
|
||||
else if (XPathNames::TRANSLATE_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::translate)) {
|
||||
fnCall = new StringFunctionCall(StringFunctionCall::TRANSLATE);
|
||||
}
|
||||
else if (XPathNames::TRUE_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::_true)) {
|
||||
fnCall = new BooleanFunctionCall(BooleanFunctionCall::TX_TRUE);
|
||||
}
|
||||
else if (XPathNames::NUMBER_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::number)) {
|
||||
fnCall = new NumberFunctionCall(NumberFunctionCall::NUMBER);
|
||||
}
|
||||
else if (XPathNames::ROUND_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::round)) {
|
||||
fnCall = new NumberFunctionCall(NumberFunctionCall::ROUND);
|
||||
}
|
||||
else if (XPathNames::CEILING_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::ceiling)) {
|
||||
fnCall = new NumberFunctionCall(NumberFunctionCall::CEILING);
|
||||
}
|
||||
else if (XPathNames::FLOOR_FN.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::floor)) {
|
||||
fnCall = new NumberFunctionCall(NumberFunctionCall::FLOOR);
|
||||
}
|
||||
else {
|
||||
|
@ -572,9 +510,8 @@ Expr* ExprParser::createFunctionCall(ExprLexer& lexer,
|
|||
if (!parseParameters(0, lexer, aContext)) {
|
||||
return 0;
|
||||
}
|
||||
String err(tok->value);
|
||||
err.Append(NS_LITERAL_STRING(" not implemented."));
|
||||
return new StringExpr(err);
|
||||
return new StringExpr(tok->value +
|
||||
NS_LITERAL_STRING(" not implemented."));
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -612,43 +549,52 @@ LocationStep* ExprParser::createLocationStep(ExprLexer& lexer,
|
|||
//-- eat token
|
||||
lexer.nextToken();
|
||||
//-- should switch to a hash here for speed if necessary
|
||||
if (ANCESTOR_AXIS.Equals(tok->value)) {
|
||||
if (TX_StringEqualsAtom(tok->value, txXPathAtoms::ancestor)) {
|
||||
axisIdentifier = LocationStep::ANCESTOR_AXIS;
|
||||
}
|
||||
else if (ANCESTOR_OR_SELF_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::ancestorOrSelf)) {
|
||||
axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS;
|
||||
}
|
||||
else if (ATTRIBUTE_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::attribute)) {
|
||||
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
|
||||
}
|
||||
else if (CHILD_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::child)) {
|
||||
axisIdentifier = LocationStep::CHILD_AXIS;
|
||||
}
|
||||
else if (DESCENDANT_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::descendant)) {
|
||||
axisIdentifier = LocationStep::DESCENDANT_AXIS;
|
||||
}
|
||||
else if (DESCENDANT_OR_SELF_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::descendantOrSelf)) {
|
||||
axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS;
|
||||
}
|
||||
else if (FOLLOWING_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::following)) {
|
||||
axisIdentifier = LocationStep::FOLLOWING_AXIS;
|
||||
}
|
||||
else if (FOLLOWING_SIBLING_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::followingSibling)) {
|
||||
axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS;
|
||||
}
|
||||
else if (NAMESPACE_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::_namespace)) {
|
||||
axisIdentifier = LocationStep::NAMESPACE_AXIS;
|
||||
}
|
||||
else if (PARENT_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::parent)) {
|
||||
axisIdentifier = LocationStep::PARENT_AXIS;
|
||||
}
|
||||
else if (PRECEDING_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::preceding)) {
|
||||
axisIdentifier = LocationStep::PRECEDING_AXIS;
|
||||
}
|
||||
else if (PRECEDING_SIBLING_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value,
|
||||
txXPathAtoms::precedingSibling)) {
|
||||
axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS;
|
||||
}
|
||||
else if (SELF_AXIS.Equals(tok->value)) {
|
||||
else if (TX_StringEqualsAtom(tok->value, txXPathAtoms::self)) {
|
||||
axisIdentifier = LocationStep::SELF_AXIS;
|
||||
}
|
||||
else {
|
||||
|
@ -1066,21 +1012,19 @@ short ExprParser::precedenceLevel(short tokenType) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
nsresult ExprParser::resolveQName(const String& aQName,
|
||||
nsresult ExprParser::resolveQName(const nsAString& aQName,
|
||||
txAtom*& aPrefix, txIParseContext* aContext,
|
||||
txAtom*& aLocalName, PRInt32& aNamespace)
|
||||
{
|
||||
aNamespace = kNameSpaceID_None;
|
||||
String prefix, lName;
|
||||
PRInt32 idx = aQName.indexOf(':');
|
||||
PRInt32 idx = aQName.FindChar(':');
|
||||
if (idx > 0) {
|
||||
aQName.subString(0, (PRUint32)idx, prefix);
|
||||
aPrefix = TX_GET_ATOM(prefix);
|
||||
aPrefix = TX_GET_ATOM(Substring(aQName, 0, (PRUint32)idx));
|
||||
if (!aPrefix) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aQName.subString((PRUint32)idx + 1, lName);
|
||||
aLocalName = TX_GET_ATOM(lName);
|
||||
aLocalName = TX_GET_ATOM(Substring(aQName, (PRUint32)idx + 1,
|
||||
aQName.Length() - (idx + 1)));
|
||||
if (!aLocalName) {
|
||||
TX_RELEASE_ATOM(aPrefix);
|
||||
aPrefix = 0;
|
||||
|
|
|
@ -42,7 +42,6 @@ class ExprLexer;
|
|||
class FunctionCall;
|
||||
class LocationStep;
|
||||
class PredicateList;
|
||||
class String;
|
||||
class Token;
|
||||
class txIParseContext;
|
||||
class txNodeTypeTest;
|
||||
|
@ -51,14 +50,14 @@ class ExprParser
|
|||
{
|
||||
public:
|
||||
|
||||
static Expr* createExpr(const String& aExpression,
|
||||
static Expr* createExpr(const nsAFlatString& aExpression,
|
||||
txIParseContext* aContext);
|
||||
|
||||
/**
|
||||
* Creates an Attribute Value Template using the given value
|
||||
**/
|
||||
static AttributeValueTemplate* createAttributeValueTemplate
|
||||
(const String& attValue, txIParseContext* aContext);
|
||||
(const nsAFlatString& attValue, txIParseContext* aContext);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -83,7 +82,7 @@ protected:
|
|||
* Resolve a QName, given the mContext parse context.
|
||||
* Returns prefix and localName as well as namespace ID
|
||||
**/
|
||||
static nsresult resolveQName(const String& aQName, txAtom*& aPrefix,
|
||||
static nsresult resolveQName(const nsAString& aQName, txAtom*& aPrefix,
|
||||
txIParseContext* aContext,
|
||||
txAtom*& aLocalName, PRInt32& aNamespace);
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "primitives.h"
|
||||
#include "TxObject.h"
|
||||
#include "TxString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
/*
|
||||
* ExprResult
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
* Creates a String representation of this ExprResult
|
||||
* @param str the destination string to append the String representation to.
|
||||
**/
|
||||
virtual void stringValue(String& str) = 0;
|
||||
virtual void stringValue(nsAString& str) = 0;
|
||||
|
||||
/**
|
||||
* Converts this ExprResult to a Boolean (MBool) value
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual void stringValue(nsAString& str);
|
||||
virtual MBool booleanValue();
|
||||
virtual double numberValue();
|
||||
|
||||
|
@ -114,7 +114,7 @@ public:
|
|||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual void stringValue(nsAString& str);
|
||||
virtual MBool booleanValue();
|
||||
virtual double numberValue();
|
||||
|
||||
|
@ -125,21 +125,17 @@ private:
|
|||
|
||||
|
||||
class StringResult : public ExprResult {
|
||||
|
||||
public:
|
||||
|
||||
StringResult();
|
||||
StringResult(const nsAString& str);
|
||||
|
||||
virtual ExprResult* clone();
|
||||
virtual short getResultType();
|
||||
virtual void stringValue(String& str);
|
||||
virtual void stringValue(nsAString& str);
|
||||
virtual MBool booleanValue();
|
||||
virtual double numberValue();
|
||||
|
||||
|
||||
private:
|
||||
String value;
|
||||
nsString mValue;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -73,7 +73,7 @@ ExprResult* FilterExpr::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
else if(!isEmpty()) {
|
||||
// We can't filter a non-nodeset
|
||||
String err(NS_LITERAL_STRING("Expecting nodeset as result of: "));
|
||||
nsAutoString err(NS_LITERAL_STRING("Expecting nodeset as result of: "));
|
||||
expr->toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_EVAL_FAILED);
|
||||
delete exprResult;
|
||||
|
@ -88,7 +88,7 @@ ExprResult* FilterExpr::evaluate(txIEvalContext* aContext)
|
|||
* @param str the destination String to append to
|
||||
* @see Expr
|
||||
**/
|
||||
void FilterExpr::toString(String& str) {
|
||||
void FilterExpr::toString(nsAString& str) {
|
||||
if ( expr ) expr->toString(str);
|
||||
else str.Append(NS_LITERAL_STRING("null"));
|
||||
PredicateList::toString(str);
|
||||
|
|
|
@ -69,11 +69,11 @@ MBool txForwardContext::isStripSpaceAllowed(Node* aNode)
|
|||
return mInner->isStripSpaceAllowed(aNode);
|
||||
}
|
||||
|
||||
void txForwardContext::receiveError(const String& aMsg, nsresult aRes)
|
||||
void txForwardContext::receiveError(const nsAString& aMsg, nsresult aRes)
|
||||
{
|
||||
NS_ASSERTION(mInner, "mInner is null!!!");
|
||||
#ifdef DEBUG
|
||||
String error(NS_LITERAL_STRING("forwarded error: "));
|
||||
nsAutoString error(NS_LITERAL_STRING("forwarded error: "));
|
||||
error.Append(aMsg);
|
||||
mInner->receiveError(error, aRes);
|
||||
#else
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
* This class represents a FunctionCall as defined by the XSL Working Draft
|
||||
**/
|
||||
|
||||
const String FunctionCall::INVALID_PARAM_COUNT(
|
||||
const nsString FunctionCall::INVALID_PARAM_COUNT(
|
||||
NS_LITERAL_STRING("invalid number of parameters for function: "));
|
||||
|
||||
const String FunctionCall::INVALID_PARAM_VALUE(
|
||||
const nsString FunctionCall::INVALID_PARAM_VALUE(
|
||||
NS_LITERAL_STRING("invalid parameter value for function: "));
|
||||
|
||||
FunctionCall::FunctionCall()
|
||||
|
@ -73,7 +73,7 @@ nsresult FunctionCall::addParam(Expr* aExpr)
|
|||
* The value is appended to the given destination String
|
||||
*/
|
||||
void FunctionCall::evaluateToString(Expr* aExpr, txIEvalContext* aContext,
|
||||
String& aDest)
|
||||
nsAString& aDest)
|
||||
{
|
||||
NS_ASSERTION(aExpr, "missing expression");
|
||||
ExprResult* exprResult = aExpr->evaluate(aContext);
|
||||
|
@ -126,8 +126,7 @@ NodeSet* FunctionCall::evaluateToNodeSet(Expr* aExpr, txIEvalContext* aContext)
|
|||
return 0;
|
||||
|
||||
if (exprResult->getResultType() != ExprResult::NODESET) {
|
||||
String err(NS_LITERAL_STRING("NodeSet expected as argument"));
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
aContext->receiveError(NS_LITERAL_STRING("NodeSet expected as argument"), NS_ERROR_XPATH_INVALID_ARG);
|
||||
delete exprResult;
|
||||
return 0;
|
||||
}
|
||||
|
@ -144,7 +143,7 @@ MBool FunctionCall::requireParams (int paramCountMin,
|
|||
{
|
||||
int argc = params.getLength();
|
||||
if ((argc < paramCountMin) || (argc > paramCountMax)) {
|
||||
String err(INVALID_PARAM_COUNT);
|
||||
nsAutoString err(INVALID_PARAM_COUNT);
|
||||
toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
return MB_FALSE;
|
||||
|
@ -159,7 +158,7 @@ MBool FunctionCall::requireParams(int paramCountMin, txIEvalContext* aContext)
|
|||
{
|
||||
int argc = params.getLength();
|
||||
if (argc < paramCountMin) {
|
||||
String err(INVALID_PARAM_COUNT);
|
||||
nsAutoString err(INVALID_PARAM_COUNT);
|
||||
toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
return MB_FALSE;
|
||||
|
@ -175,10 +174,10 @@ MBool FunctionCall::requireParams(int paramCountMin, txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this NodeExpr.
|
||||
**/
|
||||
void FunctionCall::toString(String& aDest)
|
||||
void FunctionCall::toString(nsAString& aDest)
|
||||
{
|
||||
txAtom* functionNameAtom = 0;
|
||||
String functionName;
|
||||
nsAutoString functionName;
|
||||
if (!NS_SUCCEEDED(getNameAtom(&functionNameAtom)) ||
|
||||
!TX_GET_ATOM_STRING(functionNameAtom, functionName)) {
|
||||
NS_ASSERTION(0, "Can't get function name.");
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
|
||||
#include "primitives.h"
|
||||
#include "Expr.h"
|
||||
#include "TxString.h"
|
||||
|
||||
/**
|
||||
* The following are definitions for the XPath functions
|
||||
|
@ -93,15 +92,15 @@ class ErrorFunctionCall : public FunctionCall {
|
|||
public:
|
||||
|
||||
ErrorFunctionCall();
|
||||
ErrorFunctionCall(const String& errorMsg);
|
||||
ErrorFunctionCall(const nsAString& errorMsg);
|
||||
|
||||
TX_DECL_FUNCTION;
|
||||
|
||||
void setErrorMessage(String& errorMsg);
|
||||
void setErrorMessage(nsAString& errorMsg);
|
||||
|
||||
private:
|
||||
|
||||
String errorMessage;
|
||||
nsString errorMessage;
|
||||
|
||||
}; //-- ErrorFunctionCall
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
class ExprResult;
|
||||
class FunctionCall;
|
||||
class Node;
|
||||
class String;
|
||||
|
||||
/*
|
||||
* txIParseContext
|
||||
|
@ -79,7 +78,7 @@ public:
|
|||
/*
|
||||
* Callback to be used by the Parser if errors are detected.
|
||||
*/
|
||||
virtual void receiveError(const String& aMsg, nsresult aRes) = 0;
|
||||
virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -114,14 +113,14 @@ public:
|
|||
/*
|
||||
* Callback to be used by the expression/pattern if errors are detected.
|
||||
*/
|
||||
virtual void receiveError(const String& aMsg, nsresult aRes) = 0;
|
||||
virtual void receiveError(const nsAString& aMsg, nsresult aRes) = 0;
|
||||
};
|
||||
|
||||
#define TX_DECL_MATCH_CONTEXT \
|
||||
nsresult getVariable(PRInt32 aNamespace, txAtom* aLName, \
|
||||
ExprResult*& aResult); \
|
||||
MBool isStripSpaceAllowed(Node* aNode); \
|
||||
void receiveError(const String& aMsg, nsresult aRes)
|
||||
void receiveError(const nsAString& aMsg, nsresult aRes)
|
||||
|
||||
class txIEvalContext : public txIMatchContext
|
||||
{
|
||||
|
|
|
@ -250,7 +250,7 @@ void LocationStep::fromDescendantsRev(Node* node, txIMatchContext* cs,
|
|||
* @param str the destination String to append to
|
||||
* @see Expr
|
||||
**/
|
||||
void LocationStep::toString(String& str) {
|
||||
void LocationStep::toString(nsAString& str) {
|
||||
switch (mAxisIdentifier) {
|
||||
case ANCESTOR_AXIS :
|
||||
str.Append(NS_LITERAL_STRING("ancestor::"));
|
||||
|
|
|
@ -129,7 +129,7 @@ ExprResult* MultiplicativeExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void MultiplicativeExpr::toString(String& str) {
|
||||
void MultiplicativeExpr::toString(nsAString& str) {
|
||||
|
||||
if ( leftExpr ) leftExpr->toString(str);
|
||||
else str.Append(NS_LITERAL_STRING("null"));
|
||||
|
|
|
@ -92,15 +92,15 @@ double txNameTest::getDefaultPriority()
|
|||
* @param aDest the String to use when creating the string representation.
|
||||
* The string representation will be appended to the string.
|
||||
*/
|
||||
void txNameTest::toString(String& aDest)
|
||||
void txNameTest::toString(nsAString& aDest)
|
||||
{
|
||||
if (mPrefix) {
|
||||
String prefix;
|
||||
TX_GET_ATOM_STRING(mPrefix, prefix);
|
||||
aDest.Append(prefix);
|
||||
const PRUnichar* prefix;
|
||||
mPrefix->GetUnicode(&prefix);
|
||||
aDest.Append(nsDependentString(prefix));
|
||||
aDest.Append(PRUnichar(':'));
|
||||
}
|
||||
String localName;
|
||||
TX_GET_ATOM_STRING(mLocalName, localName);
|
||||
aDest.Append(localName);
|
||||
const PRUnichar* localName;
|
||||
mLocalName->GetUnicode(&localName);
|
||||
aDest.Append(nsDependentString(localName));
|
||||
}
|
||||
|
|
|
@ -68,11 +68,11 @@ MBool txNodeSetContext::isStripSpaceAllowed(Node* aNode)
|
|||
return mInner->isStripSpaceAllowed(aNode);
|
||||
}
|
||||
|
||||
void txNodeSetContext::receiveError(const String& aMsg, nsresult aRes)
|
||||
void txNodeSetContext::receiveError(const nsAString& aMsg, nsresult aRes)
|
||||
{
|
||||
NS_ASSERTION(mInner, "mInner is null!!!");
|
||||
#ifdef DEBUG
|
||||
String error(NS_LITERAL_STRING("forwarded error: "));
|
||||
nsAutoString error(NS_LITERAL_STRING("forwarded error: "));
|
||||
error.Append(aMsg);
|
||||
mInner->receiveError(error, aRes);
|
||||
#else
|
||||
|
|
|
@ -98,7 +98,7 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
NodeSet* nodes = (NodeSet*)exprResult;
|
||||
int i;
|
||||
for (i = 0; i < nodes->size(); i++) {
|
||||
String idList, id;
|
||||
nsAutoString idList, id;
|
||||
XMLDOMUtils::getNodeValue(nodes->get(i), idList);
|
||||
txTokenizer tokenizer(idList);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
|
@ -110,7 +110,7 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
}
|
||||
}
|
||||
else {
|
||||
String idList, id;
|
||||
nsAutoString idList, id;
|
||||
exprResult->stringValue(idList);
|
||||
txTokenizer tokenizer(idList);
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
|
@ -160,7 +160,7 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
switch (mType) {
|
||||
case LOCAL_NAME:
|
||||
{
|
||||
String localName;
|
||||
nsAutoString localName;
|
||||
txAtom* localNameAtom;
|
||||
node->getLocalName(&localNameAtom);
|
||||
if (localNameAtom) {
|
||||
|
@ -173,7 +173,11 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
}
|
||||
case NAMESPACE_URI:
|
||||
{
|
||||
return new StringResult(node->getNamespaceURI());
|
||||
StringResult* result = new StringResult();
|
||||
if (result) {
|
||||
node->getNamespaceURI(result->mValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
case NAME:
|
||||
{
|
||||
|
@ -181,10 +185,18 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
case Node::ATTRIBUTE_NODE:
|
||||
case Node::ELEMENT_NODE:
|
||||
case Node::PROCESSING_INSTRUCTION_NODE:
|
||||
{
|
||||
// XXX Namespace: namespaces have a name
|
||||
return new StringResult(node->getNodeName());
|
||||
StringResult* result = new StringResult();
|
||||
if (result) {
|
||||
node->getNodeName(result->mValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new StringResult();
|
||||
}
|
||||
|
@ -203,8 +215,8 @@ ExprResult* NodeSetFunctionCall::evaluate(txIEvalContext* aContext) {
|
|||
}
|
||||
}
|
||||
|
||||
String err(NS_LITERAL_STRING("Internal error"));
|
||||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
aContext->receiveError(NS_LITERAL_STRING("Internal error"),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ txNodeTypeTest::~txNodeTypeTest()
|
|||
TX_IF_RELEASE_ATOM(mNodeName);
|
||||
}
|
||||
|
||||
void txNodeTypeTest::setNodeName(const String& aName)
|
||||
void txNodeTypeTest::setNodeName(const nsAString& aName)
|
||||
{
|
||||
mNodeName = TX_GET_ATOM(aName);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ double txNodeTypeTest::getDefaultPriority()
|
|||
* @param aDest the String to use when creating the string representation.
|
||||
* The string representation will be appended to the string.
|
||||
*/
|
||||
void txNodeTypeTest::toString(String& aDest)
|
||||
void txNodeTypeTest::toString(nsAString& aDest)
|
||||
{
|
||||
switch (mNodeType) {
|
||||
case COMMENT_TYPE:
|
||||
|
@ -106,7 +106,7 @@ void txNodeTypeTest::toString(String& aDest)
|
|||
case PI_TYPE:
|
||||
aDest.Append(NS_LITERAL_STRING("processing-instruction("));
|
||||
if (mNodeName) {
|
||||
String str;
|
||||
nsAutoString str;
|
||||
TX_GET_ATOM_STRING(mNodeName, str);
|
||||
aDest.Append(PRUnichar('\''));
|
||||
aDest.Append(str);
|
||||
|
|
|
@ -112,7 +112,7 @@ ExprResult* NumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
double res = 0;
|
||||
int i;
|
||||
for (i = 0; i < nodes->size(); i++) {
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
XMLDOMUtils::getNodeValue(nodes->get(i), resultStr);
|
||||
res += Double::toDouble(resultStr);
|
||||
}
|
||||
|
@ -127,14 +127,14 @@ ExprResult* NumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
evaluateToNumber((Expr*)iter.next(), aContext));
|
||||
}
|
||||
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
XMLDOMUtils::getNodeValue(aContext->getContextNode(), resultStr);
|
||||
return new NumberResult(Double::toDouble(resultStr));
|
||||
}
|
||||
}
|
||||
|
||||
String err(NS_LITERAL_STRING("Internal error"));
|
||||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
aContext->receiveError(NS_LITERAL_STRING("Internal error"),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ short NumberResult::getResultType() {
|
|||
return ExprResult::NUMBER;
|
||||
} //-- getResultType
|
||||
|
||||
void NumberResult::stringValue(String& str) {
|
||||
void NumberResult::stringValue(nsAString& str) {
|
||||
Double::toString(value, str);
|
||||
} //-- stringValue
|
||||
|
||||
|
|
|
@ -41,11 +41,6 @@
|
|||
//- PathExpr -/
|
||||
//------------/
|
||||
|
||||
const String PathExpr::RTF_INVALID_OP(
|
||||
NS_LITERAL_STRING("Result tree fragments don't allow location steps"));
|
||||
const String PathExpr::NODESET_EXPECTED(
|
||||
NS_LITERAL_STRING("Filter expression must evaluate to a NodeSet"));
|
||||
|
||||
/**
|
||||
* Creates a new PathExpr
|
||||
**/
|
||||
|
@ -172,13 +167,13 @@ void PathExpr::evalDescendants (Expr* aStep, Node* aNode,
|
|||
delete res;
|
||||
|
||||
MBool filterWS = aContext->isStripSpaceAllowed(aNode);
|
||||
|
||||
|
||||
Node* child = aNode->getFirstChild();
|
||||
while (child) {
|
||||
if (!(filterWS &&
|
||||
(child->getNodeType() == Node::TEXT_NODE ||
|
||||
child->getNodeType() == Node::CDATA_SECTION_NODE) &&
|
||||
XMLUtils::isWhitespace(child->getNodeValue())))
|
||||
XMLUtils::isWhitespace(child)))
|
||||
evalDescendants(aStep, child, aContext, resNodes);
|
||||
child = child->getNextSibling();
|
||||
}
|
||||
|
@ -192,7 +187,7 @@ void PathExpr::evalDescendants (Expr* aStep, Node* aNode,
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void PathExpr::toString(String& dest)
|
||||
void PathExpr::toString(nsAString& dest)
|
||||
{
|
||||
txListIterator iter(&expressions);
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ MBool PredicateList::isEmpty()
|
|||
return (MBool)(predicates.getLength() == 0);
|
||||
} // isEmpty
|
||||
|
||||
void PredicateList::toString(String& dest)
|
||||
void PredicateList::toString(nsAString& dest)
|
||||
{
|
||||
txListIterator iter(&predicates);
|
||||
while (iter.hasNext()) {
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
#include "Expr.h"
|
||||
#include "NodeSet.h"
|
||||
#include "TxString.h"
|
||||
#include "XMLDOMUtils.h"
|
||||
|
||||
//------------------/
|
||||
|
@ -67,7 +66,7 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
|
|||
|
||||
NodeSet* nodeSet = (NodeSet*)left;
|
||||
for ( int i = 0; i < nodeSet->size(); i++) {
|
||||
String str;
|
||||
nsAutoString str;
|
||||
Node* node = nodeSet->get(i);
|
||||
XMLDOMUtils::getNodeValue(node, str);
|
||||
StringResult strResult(str);
|
||||
|
@ -84,7 +83,7 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
|
|||
|
||||
NodeSet* nodeSet = (NodeSet*)right;
|
||||
for ( int i = 0; i < nodeSet->size(); i++) {
|
||||
String str;
|
||||
nsAutoString str;
|
||||
Node* node = nodeSet->get(i);
|
||||
XMLDOMUtils::getNodeValue(node, str);
|
||||
StringResult strResult(str);
|
||||
|
@ -114,9 +113,9 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
|
|||
#endif
|
||||
}
|
||||
else {
|
||||
String lStr;
|
||||
nsAutoString lStr;
|
||||
left->stringValue(lStr);
|
||||
String rStr;
|
||||
nsAutoString rStr;
|
||||
right->stringValue(rStr);
|
||||
result = !lStr.Equals(rStr);
|
||||
}
|
||||
|
@ -141,9 +140,9 @@ MBool RelationalExpr::compareResults(ExprResult* left, ExprResult* right) {
|
|||
#endif
|
||||
}
|
||||
else {
|
||||
String lStr;
|
||||
nsAutoString lStr;
|
||||
left->stringValue(lStr);
|
||||
String rStr;
|
||||
nsAutoString rStr;
|
||||
right->stringValue(rStr);
|
||||
result = lStr.Equals(rStr);
|
||||
}
|
||||
|
@ -237,7 +236,7 @@ ExprResult* RelationalExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void RelationalExpr::toString(String& str) {
|
||||
void RelationalExpr::toString(nsAString& str) {
|
||||
|
||||
if ( leftExpr ) leftExpr->toString(str);
|
||||
else str.Append(NS_LITERAL_STRING("null"));
|
||||
|
|
|
@ -63,7 +63,7 @@ ExprResult* RootExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void RootExpr::toString(String& dest) {
|
||||
void RootExpr::toString(nsAString& dest) {
|
||||
if (mSerialize)
|
||||
dest.Append(PRUnichar('/'));
|
||||
} //-- toString
|
||||
|
|
|
@ -66,11 +66,11 @@ public:
|
|||
return mInner->isStripSpaceAllowed(aNode);
|
||||
}
|
||||
|
||||
void receiveError(const String& aMsg, nsresult aRes)
|
||||
void receiveError(const nsAString& aMsg, nsresult aRes)
|
||||
{
|
||||
NS_ASSERTION(mInner, "mInner is null!!!");
|
||||
#ifdef DEBUG
|
||||
String error(NS_LITERAL_STRING("forwarded error: "));
|
||||
nsAutoString error(NS_LITERAL_STRING("forwarded error: "));
|
||||
error.Append(aMsg);
|
||||
mInner->receiveError(error, aRes);
|
||||
#else
|
||||
|
|
|
@ -60,7 +60,7 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(2, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
while (iter.hasNext()) {
|
||||
evaluateToString((Expr*)iter.next(), aContext, resultStr);
|
||||
}
|
||||
|
@ -71,17 +71,17 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(2, 2, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String arg1, arg2;
|
||||
nsAutoString arg1, arg2;
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg1);
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg2);
|
||||
return new BooleanResult(arg1.indexOf(arg2) >= 0);
|
||||
return new BooleanResult(arg1.Find(arg2) >= 0);
|
||||
}
|
||||
case NORMALIZE_SPACE:
|
||||
{
|
||||
if (!requireParams(0, 1, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
if (iter.hasNext())
|
||||
evaluateToString((Expr*)iter.next(), aContext, resultStr);
|
||||
else
|
||||
|
@ -90,8 +90,8 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
MBool addSpace = MB_FALSE;
|
||||
MBool first = MB_TRUE;
|
||||
String normed;
|
||||
normed.getNSString().SetCapacity(resultStr.Length());
|
||||
nsAutoString normed;
|
||||
normed.SetCapacity(resultStr.Length());
|
||||
PRUnichar c;
|
||||
PRUint32 src;
|
||||
for (src = 0; src < resultStr.Length(); src++) {
|
||||
|
@ -115,17 +115,17 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(2, 2, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String arg1, arg2;
|
||||
nsAutoString arg1, arg2;
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg1);
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg2);
|
||||
return new BooleanResult(arg1.indexOf(arg2) == 0);
|
||||
return new BooleanResult(arg1.Find(arg2) == 0);
|
||||
}
|
||||
case STRING_LENGTH:
|
||||
{
|
||||
if (!requireParams(0, 1, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
if (iter.hasNext())
|
||||
evaluateToString((Expr*)iter.next(), aContext, resultStr);
|
||||
else
|
||||
|
@ -138,7 +138,7 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(2, 3, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String src;
|
||||
nsAutoString src;
|
||||
double start, end;
|
||||
evaluateToString((Expr*)iter.next(), aContext, src);
|
||||
start = evaluateToNumber((Expr*)iter.next(), aContext);
|
||||
|
@ -171,23 +171,22 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (start > end)
|
||||
return new StringResult();
|
||||
|
||||
String resultStr;
|
||||
src.subString((PRUint32)start, (PRUint32)end, resultStr);
|
||||
return new StringResult(resultStr);
|
||||
return new StringResult(Substring(src, (PRUint32)start,
|
||||
(PRUint32)end - (PRUint32)start));
|
||||
}
|
||||
case SUBSTRING_AFTER:
|
||||
{
|
||||
if (!requireParams(2, 2, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String arg1, arg2;
|
||||
nsAutoString arg1, arg2;
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg1);
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg2);
|
||||
PRInt32 idx = arg1.indexOf(arg2);
|
||||
PRInt32 idx = arg1.Find(arg2);
|
||||
if (idx != kNotFound) {
|
||||
PRUint32 len = arg2.Length();
|
||||
arg1.subString(idx + len, arg2);
|
||||
return new StringResult(arg2);
|
||||
return new StringResult(Substring(arg1, idx + len,
|
||||
arg1.Length() - (idx + len)));
|
||||
}
|
||||
return new StringResult();
|
||||
}
|
||||
|
@ -196,14 +195,12 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(2, 2, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String arg1, arg2;
|
||||
nsAutoString arg1, arg2;
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg1);
|
||||
evaluateToString((Expr*)iter.next(), aContext, arg2);
|
||||
PRInt32 idx = arg1.indexOf(arg2);
|
||||
PRInt32 idx = arg1.Find(arg2);
|
||||
if (idx != kNotFound) {
|
||||
arg2.Truncate();
|
||||
arg1.subString(0, idx, arg2);
|
||||
return new StringResult(arg2);
|
||||
return new StringResult(Substring(arg1, 0, idx));
|
||||
}
|
||||
return new StringResult();
|
||||
}
|
||||
|
@ -212,18 +209,18 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(3, 3, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String src;
|
||||
nsAutoString src;
|
||||
evaluateToString((Expr*)iter.next(), aContext, src);
|
||||
if (src.IsEmpty())
|
||||
return new StringResult();
|
||||
|
||||
String oldChars, newChars, dest;
|
||||
nsAutoString oldChars, newChars, dest;
|
||||
evaluateToString((Expr*)iter.next(), aContext, oldChars);
|
||||
evaluateToString((Expr*)iter.next(), aContext, newChars);
|
||||
PRUint32 i;
|
||||
PRInt32 newCharsLength = (PRInt32)newChars.Length();
|
||||
for (i = 0; i < src.Length(); i++) {
|
||||
PRInt32 idx = oldChars.indexOf(src.CharAt(i));
|
||||
PRInt32 idx = oldChars.FindChar(src.CharAt(i));
|
||||
if (idx != kNotFound) {
|
||||
if (idx < newCharsLength)
|
||||
dest.Append(newChars.CharAt((PRUint32)idx));
|
||||
|
@ -239,7 +236,7 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (!requireParams(0, 1, aContext))
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
|
||||
String resultStr;
|
||||
nsAutoString resultStr;
|
||||
if (iter.hasNext())
|
||||
evaluateToString((Expr*)iter.next(), aContext, resultStr);
|
||||
else
|
||||
|
@ -249,8 +246,8 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
|
||||
String err(NS_LITERAL_STRING("Internal error"));
|
||||
aContext->receiveError(err, NS_ERROR_UNEXPECTED);
|
||||
aContext->receiveError(NS_LITERAL_STRING("Internal error"),
|
||||
NS_ERROR_UNEXPECTED);
|
||||
return new StringResult(NS_LITERAL_STRING("error"));
|
||||
}
|
||||
|
||||
|
|
|
@ -40,10 +40,9 @@ StringResult::StringResult() {
|
|||
* Creates a new StringResult with the value of the given String parameter
|
||||
* @param str the String to use for initialization of this StringResult's value
|
||||
**/
|
||||
StringResult::StringResult(const nsAString& str) {
|
||||
//-- copy str
|
||||
this->value.Append(str);
|
||||
} //-- StringResult
|
||||
StringResult::StringResult(const nsAString& str) : mValue(str)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Virtual Methods from ExprResult
|
||||
|
@ -51,22 +50,22 @@ StringResult::StringResult(const nsAString& str) {
|
|||
|
||||
ExprResult* StringResult::clone()
|
||||
{
|
||||
return new StringResult(value);
|
||||
return new StringResult(mValue);
|
||||
}
|
||||
|
||||
short StringResult::getResultType() {
|
||||
return ExprResult::STRING;
|
||||
} //-- getResultType
|
||||
|
||||
void StringResult::stringValue(String& str) {
|
||||
str.Append(this->value);
|
||||
void StringResult::stringValue(nsAString& str) {
|
||||
str.Append(mValue);
|
||||
} //-- stringValue
|
||||
|
||||
MBool StringResult::booleanValue() {
|
||||
return !value.IsEmpty();
|
||||
return !mValue.IsEmpty();
|
||||
} //-- booleanValue
|
||||
|
||||
double StringResult::numberValue() {
|
||||
return Double::toDouble(value);
|
||||
return Double::toDouble(mValue);
|
||||
} //-- numberValue
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ ExprResult* UnaryExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
*/
|
||||
void UnaryExpr::toString(String& str)
|
||||
void UnaryExpr::toString(nsAString& str)
|
||||
{
|
||||
if (!expr)
|
||||
return;
|
||||
|
|
|
@ -101,7 +101,7 @@ ExprResult* UnionExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void UnionExpr::toString(String& dest) {
|
||||
void UnionExpr::toString(nsAString& dest) {
|
||||
txListIterator iter(&expressions);
|
||||
|
||||
short count = 0;
|
||||
|
|
|
@ -81,16 +81,16 @@ ExprResult* VariableRefExpr::evaluate(txIEvalContext* aContext)
|
|||
* other #toString() methods for Expressions.
|
||||
* @return the String representation of this Expr.
|
||||
**/
|
||||
void VariableRefExpr::toString(String& aDest)
|
||||
void VariableRefExpr::toString(nsAString& aDest)
|
||||
{
|
||||
aDest.Append(PRUnichar('$'));
|
||||
if (mPrefix) {
|
||||
String prefix;
|
||||
nsAutoString prefix;
|
||||
TX_GET_ATOM_STRING(mPrefix, prefix);
|
||||
aDest.Append(prefix);
|
||||
aDest.Append(PRUnichar(':'));
|
||||
}
|
||||
String lname;
|
||||
nsAutoString lname;
|
||||
TX_GET_ATOM_STRING(mLocalName, lname);
|
||||
aDest.Append(lname);
|
||||
} //-- toString
|
||||
|
|
|
@ -36,24 +36,31 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
TX_ATOM(_and, "and");
|
||||
TX_ATOM(_asterix, "*");
|
||||
TX_ATOM(boolean, "boolean");
|
||||
TX_ATOM(ceiling, "ceiling");
|
||||
TX_ATOM(comment, "comment");
|
||||
TX_ATOM(concat, "concat");
|
||||
TX_ATOM(contains, "contains");
|
||||
TX_ATOM(count, "count");
|
||||
TX_ATOM(div, "div");
|
||||
TX_ATOM(_false, "false");
|
||||
TX_ATOM(floor, "floor");
|
||||
TX_ATOM(id, "id");
|
||||
TX_ATOM(lang, "lang");
|
||||
TX_ATOM(last, "last");
|
||||
TX_ATOM(localName, "local-name");
|
||||
TX_ATOM(mod, "mod");
|
||||
TX_ATOM(name, "name");
|
||||
TX_ATOM(namespaceUri, "namespace-uri");
|
||||
TX_ATOM(node, "node");
|
||||
TX_ATOM(normalizeSpace, "normalize-space");
|
||||
TX_ATOM(_not, "not");
|
||||
TX_ATOM(number, "number");
|
||||
TX_ATOM(_or, "or");
|
||||
TX_ATOM(position, "position");
|
||||
TX_ATOM(processingInstruction, "processing-instruction");
|
||||
TX_ATOM(round, "round");
|
||||
TX_ATOM(startsWith, "starts-with");
|
||||
TX_ATOM(string, "string");
|
||||
|
@ -62,6 +69,7 @@ TX_ATOM(substring, "substring");
|
|||
TX_ATOM(substringAfter, "substring-after");
|
||||
TX_ATOM(substringBefore, "substring-before");
|
||||
TX_ATOM(sum, "sum");
|
||||
TX_ATOM(text, "text");
|
||||
TX_ATOM(translate, "translate");
|
||||
TX_ATOM(_true, "true");
|
||||
|
||||
|
|
|
@ -47,8 +47,7 @@ REQUIRES += dom \
|
|||
$(NULL)
|
||||
endif
|
||||
|
||||
CPPSRCS = Names.cpp \
|
||||
txOutputFormat.cpp \
|
||||
CPPSRCS = txOutputFormat.cpp \
|
||||
ProcessorState.cpp \
|
||||
txRtfHandler.cpp \
|
||||
txTextHandler.cpp \
|
||||
|
|
|
@ -68,7 +68,7 @@ ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
txListIterator iter(¶ms);
|
||||
Expr* param1 = (Expr*)iter.next();
|
||||
ExprResult* exprResult1 = param1->evaluate(aContext);
|
||||
String baseURI;
|
||||
nsAutoString baseURI;
|
||||
MBool baseURISet = MB_FALSE;
|
||||
|
||||
if (iter.hasNext()) {
|
||||
|
@ -77,7 +77,7 @@ ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
Expr* param2 = (Expr*)iter.next();
|
||||
ExprResult* exprResult2 = param2->evaluate(aContext);
|
||||
if (exprResult2->getResultType() != ExprResult::NODESET) {
|
||||
String err(NS_LITERAL_STRING("node-set expected as second argument to document(): "));
|
||||
nsAutoString err(NS_LITERAL_STRING("node-set expected as second argument to document(): "));
|
||||
toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
delete exprResult1;
|
||||
|
@ -92,7 +92,7 @@ ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
NodeSet* nodeSet2 = (NodeSet*) exprResult2;
|
||||
if (!nodeSet2->isEmpty()) {
|
||||
baseURI = nodeSet2->get(0)->getBaseURI();
|
||||
nodeSet2->get(0)->getBaseURI(baseURI);
|
||||
}
|
||||
delete exprResult2;
|
||||
}
|
||||
|
@ -103,29 +103,24 @@ ExprResult* DocumentFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
int i;
|
||||
for (i = 0; i < nodeSet1->size(); i++) {
|
||||
Node* node = nodeSet1->get(i);
|
||||
String uriStr;
|
||||
nsAutoString uriStr;
|
||||
XMLDOMUtils::getNodeValue(node, uriStr);
|
||||
if (!baseURISet) {
|
||||
// if the second argument wasn't specified, use
|
||||
// the baseUri of node itself
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr, node->getBaseURI()));
|
||||
}
|
||||
else {
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr, baseURI));
|
||||
node->getBaseURI(baseURI);
|
||||
}
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr, baseURI));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The first argument is not a NodeSet
|
||||
String uriStr;
|
||||
nsAutoString uriStr;
|
||||
exprResult1->stringValue(uriStr);
|
||||
if (!baseURISet) {
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr,
|
||||
mDefResolveNode->getBaseURI()));
|
||||
}
|
||||
else {
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr, baseURI));
|
||||
mDefResolveNode->getBaseURI(baseURI);
|
||||
}
|
||||
nodeSet->add(mProcessorState->retrieveDocument(uriStr, baseURI));
|
||||
}
|
||||
delete exprResult1;
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ ElementAvailableFunctionCall::ElementAvailableFunctionCall(Node* aQNameResolveNo
|
|||
**/
|
||||
ExprResult* ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
||||
{
|
||||
ExprResult* result = NULL;
|
||||
ExprResult* result = nsnull;
|
||||
|
||||
if (requireParams(1, 1, aContext)) {
|
||||
txListIterator iter(¶ms);
|
||||
|
@ -74,7 +74,7 @@ ExprResult* ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
ExprResult* exprResult = param->evaluate(aContext);
|
||||
if (exprResult &&
|
||||
exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
nsAutoString property;
|
||||
exprResult->stringValue(property);
|
||||
txExpandedName qname;
|
||||
nsresult rv = qname.init(property, mQNameResolveNode, MB_TRUE);
|
||||
|
@ -119,7 +119,7 @@ ExprResult* ElementAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
else {
|
||||
String err(NS_LITERAL_STRING("Invalid argument passed to element-available(), expecting String"));
|
||||
NS_NAMED_LITERAL_STRING(err, "Invalid argument passed to element-available(), expecting String");
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
result = new StringResult(err);
|
||||
}
|
||||
|
|
|
@ -83,13 +83,13 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
txListIterator iter(¶ms);
|
||||
|
||||
double value;
|
||||
String formatStr;
|
||||
nsAutoString formatStr;
|
||||
txExpandedName formatName;
|
||||
|
||||
value = evaluateToNumber((Expr*)iter.next(), aContext);
|
||||
evaluateToString((Expr*)iter.next(), aContext, formatStr);
|
||||
if (iter.hasNext()) {
|
||||
String formatQName;
|
||||
nsAutoString formatQName;
|
||||
evaluateToString((Expr*)iter.next(), aContext, formatQName);
|
||||
rv = formatName.init(formatQName, mQNameResolveNode, MB_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -98,7 +98,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
txDecimalFormat* format = mPs->getDecimalFormat(formatName);
|
||||
if (!format) {
|
||||
String err(NS_LITERAL_STRING("unknown decimal format for: "));
|
||||
nsAutoString err(NS_LITERAL_STRING("unknown decimal format for: "));
|
||||
toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
return new StringResult(err);
|
||||
|
@ -112,15 +112,15 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return new StringResult(format->mInfinity);
|
||||
|
||||
if (value == Double::NEGATIVE_INFINITY) {
|
||||
String res;
|
||||
nsAutoString res;
|
||||
res.Append(format->mMinusSign);
|
||||
res.Append(format->mInfinity);
|
||||
return new StringResult(res);
|
||||
}
|
||||
|
||||
// Value is a normal finite number
|
||||
String prefix;
|
||||
String suffix;
|
||||
nsAutoString prefix;
|
||||
nsAutoString suffix;
|
||||
int minIntegerSize=0;
|
||||
int minFractionSize=0;
|
||||
int maxFractionSize=0;
|
||||
|
@ -167,7 +167,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (multiplier == 1)
|
||||
multiplier = 100;
|
||||
else {
|
||||
String err(INVALID_PARAM_VALUE);
|
||||
nsAutoString err(INVALID_PARAM_VALUE);
|
||||
toString(err);
|
||||
aContext->receiveError(err,
|
||||
NS_ERROR_XPATH_EVAL_FAILED);
|
||||
|
@ -178,7 +178,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (multiplier == 1)
|
||||
multiplier = 1000;
|
||||
else {
|
||||
String err(INVALID_PARAM_VALUE);
|
||||
nsAutoString err(INVALID_PARAM_VALUE);
|
||||
toString(err);
|
||||
aContext->receiveError(err,
|
||||
NS_ERROR_XPATH_EVAL_FAILED);
|
||||
|
@ -263,7 +263,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if ((c != format->mPatternSeparator && pos < formatLen) ||
|
||||
inQuote ||
|
||||
groupSize == 0) {
|
||||
String err(INVALID_PARAM_VALUE);
|
||||
nsAutoString err(INVALID_PARAM_VALUE);
|
||||
toString(err);
|
||||
aContext->receiveError(err,
|
||||
NS_ERROR_XPATH_EVAL_FAILED);
|
||||
|
@ -279,7 +279,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
value = fabs(value) * multiplier;
|
||||
|
||||
// Prefix
|
||||
String res(prefix);
|
||||
nsAutoString res(prefix);
|
||||
|
||||
#ifdef TX_EXE
|
||||
|
||||
|
@ -386,11 +386,11 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
groupSize = intDigits + 10; //to simplify grouping
|
||||
|
||||
// XXX We shouldn't use SetLength.
|
||||
res.getNSString().SetLength(res.Length() +
|
||||
intDigits + // integer digits
|
||||
1 + // decimal separator
|
||||
maxFractionSize + // fractions
|
||||
(intDigits-1)/groupSize); // group separators
|
||||
res.SetLength(res.Length() +
|
||||
intDigits + // integer digits
|
||||
1 + // decimal separator
|
||||
maxFractionSize + // fractions
|
||||
(intDigits-1)/groupSize); // group separators
|
||||
|
||||
PRInt32 i = bufIntDigits + maxFractionSize - 1;
|
||||
MBool carry = (i+1 < buflen) && (buf[i+1] >= '5');
|
||||
|
@ -415,8 +415,8 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
if (hasFraction || digit != 0 || i < bufIntDigits+minFractionSize) {
|
||||
hasFraction = MB_TRUE;
|
||||
res.replace(resPos--,
|
||||
(PRUnichar)(digit + format->mZeroDigit));
|
||||
res.SetCharAt((PRUnichar)(digit + format->mZeroDigit),
|
||||
resPos--);
|
||||
}
|
||||
else {
|
||||
res.Truncate(resPos--);
|
||||
|
@ -425,7 +425,7 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
|
||||
// Decimal separator
|
||||
if (hasFraction) {
|
||||
res.replace(resPos--, format->mDecimalSeparator);
|
||||
res.SetCharAt(format->mDecimalSeparator, resPos--);
|
||||
}
|
||||
else {
|
||||
res.Truncate(resPos--);
|
||||
|
@ -447,17 +447,17 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
|
||||
if (i != 0 && i%groupSize == 0) {
|
||||
res.replace(resPos--, format->mGroupingSeparator);
|
||||
res.SetCharAt(format->mGroupingSeparator, resPos--);
|
||||
}
|
||||
|
||||
res.replace(resPos--, (PRUnichar)(digit + format->mZeroDigit));
|
||||
res.SetCharAt((PRUnichar)(digit + format->mZeroDigit), resPos--);
|
||||
}
|
||||
|
||||
if (carry) {
|
||||
if (i%groupSize == 0) {
|
||||
res.insert(resPos + 1, format->mGroupingSeparator);
|
||||
res.Insert(format->mGroupingSeparator, resPos + 1);
|
||||
}
|
||||
res.insert(resPos + 1, (PRUnichar)(1 + format->mZeroDigit));
|
||||
res.Insert((PRUnichar)(1 + format->mZeroDigit), resPos + 1);
|
||||
}
|
||||
|
||||
if (!hasFraction && !intDigits && !carry) {
|
||||
|
|
|
@ -64,7 +64,7 @@ FunctionAvailableFunctionCall::FunctionAvailableFunctionCall(Node* aQNameResolve
|
|||
**/
|
||||
ExprResult* FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
||||
{
|
||||
ExprResult* result = NULL;
|
||||
ExprResult* result = nsnull;
|
||||
|
||||
if (requireParams(1, 1, aContext)) {
|
||||
txListIterator iter(¶ms);
|
||||
|
@ -72,7 +72,7 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
ExprResult* exprResult = param->evaluate(aContext);
|
||||
if (exprResult &&
|
||||
exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
nsAutoString property;
|
||||
exprResult->stringValue(property);
|
||||
txExpandedName qname;
|
||||
nsresult rv = qname.init(property, mQNameResolveNode, MB_FALSE);
|
||||
|
@ -118,7 +118,7 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
else {
|
||||
String err(NS_LITERAL_STRING("Invalid argument passed to function-available, expecting String"));
|
||||
NS_NAMED_LITERAL_STRING(err, "Invalid argument passed to function-available, expecting String");
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
result = new StringResult(err);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ ExprResult* GenerateIdFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
return 0;
|
||||
|
||||
if (exprResult->getResultType() != ExprResult::NODESET) {
|
||||
String err(NS_LITERAL_STRING("Invalid argument passed to generate-id(), expecting NodeSet"));
|
||||
NS_NAMED_LITERAL_STRING(err, "Invalid argument passed to generate-id(), expecting NodeSet");
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
delete exprResult;
|
||||
return new StringResult(err);
|
||||
|
|
|
@ -37,97 +37,172 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txHTMLOutput.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsStaticNameTable.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txOutputFormat.h"
|
||||
#include "txStringUtils.h"
|
||||
#include "XMLUtils.h"
|
||||
|
||||
txHTMLOutput::txHTMLOutput(txOutputFormat* aFormat, ostream* aOut)
|
||||
: txXMLOutput(aFormat, aOut), mHTMLEmptyTags(EMPTY_ELEMENTS_COUNT)
|
||||
#define EMPTY_ELEMENTS_COUNT 13
|
||||
const char* kHTMLEmptyTags[] =
|
||||
{
|
||||
mUseEmptyElementShorthand = MB_FALSE;
|
||||
"area",
|
||||
"base",
|
||||
"basefont",
|
||||
"br",
|
||||
"col",
|
||||
"frame",
|
||||
"hr",
|
||||
"img",
|
||||
"input",
|
||||
"isindex",
|
||||
"link",
|
||||
"meta",
|
||||
"param"
|
||||
};
|
||||
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::area);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::base);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::basefont);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::br);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::col);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::frame);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::hr);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::img);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::input);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::isindex);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::link);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::meta);
|
||||
mHTMLEmptyTags.AppendObject(txHTMLAtoms::param);
|
||||
#define SHORTHAND_ATTR_COUNT 12
|
||||
const char* kHTMLEmptyAttributes[] =
|
||||
{
|
||||
"checked",
|
||||
"compact",
|
||||
"declare",
|
||||
"defer",
|
||||
"disabled",
|
||||
"ismap",
|
||||
"multiple",
|
||||
"noresize",
|
||||
"noshade",
|
||||
"nowrap",
|
||||
"readonly",
|
||||
"selected"
|
||||
};
|
||||
|
||||
// checked
|
||||
mHTMLEmptyAttributes[0].mAttrName = txHTMLAtoms::checked;
|
||||
mHTMLEmptyAttributes[0].mElementList.AppendObject(txHTMLAtoms::input);
|
||||
struct txEmptyAttributesMaps
|
||||
{
|
||||
typedef nsCOMArray<nsIAtom> EmptyAttrBag;
|
||||
EmptyAttrBag mMaps[SHORTHAND_ATTR_COUNT];
|
||||
};
|
||||
|
||||
// compact
|
||||
mHTMLEmptyAttributes[1].mAttrName = txHTMLAtoms::compact;
|
||||
mHTMLEmptyAttributes[1].mElementList.AppendObject(txHTMLAtoms::dir);
|
||||
mHTMLEmptyAttributes[1].mElementList.AppendObject(txHTMLAtoms::dl);
|
||||
mHTMLEmptyAttributes[1].mElementList.AppendObject(txHTMLAtoms::menu);
|
||||
mHTMLEmptyAttributes[1].mElementList.AppendObject(txHTMLAtoms::ol);
|
||||
mHTMLEmptyAttributes[1].mElementList.AppendObject(txHTMLAtoms::ul);
|
||||
static PRInt32 gTableRefCount;
|
||||
static nsStaticCaseInsensitiveNameTable* gHTMLEmptyTagsTable;
|
||||
static nsStaticCaseInsensitiveNameTable* gHTMLEmptyAttributesTable;
|
||||
static txEmptyAttributesMaps* gHTMLEmptyAttributesMaps;
|
||||
|
||||
// declare
|
||||
mHTMLEmptyAttributes[2].mAttrName = txHTMLAtoms::declare;
|
||||
mHTMLEmptyAttributes[2].mElementList.AppendObject(txHTMLAtoms::object);
|
||||
/* static */
|
||||
nsresult
|
||||
txHTMLOutput::init()
|
||||
{
|
||||
if (0 == gTableRefCount++) {
|
||||
NS_ASSERTION(!gHTMLEmptyTagsTable, "pre existing array!");
|
||||
gHTMLEmptyTagsTable = new nsStaticCaseInsensitiveNameTable();
|
||||
if (!gHTMLEmptyTagsTable) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// defer
|
||||
mHTMLEmptyAttributes[3].mAttrName = txHTMLAtoms::defer;
|
||||
mHTMLEmptyAttributes[3].mElementList.AppendObject(txHTMLAtoms::script);
|
||||
gHTMLEmptyTagsTable->Init(kHTMLEmptyTags, EMPTY_ELEMENTS_COUNT);
|
||||
|
||||
// disabled
|
||||
mHTMLEmptyAttributes[4].mAttrName = txHTMLAtoms::disabled;
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::button);
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::input);
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::optgroup);
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::option);
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::select);
|
||||
mHTMLEmptyAttributes[4].mElementList.AppendObject(txHTMLAtoms::textarea);
|
||||
NS_ASSERTION(!gHTMLEmptyAttributesTable, "pre existing array!");
|
||||
gHTMLEmptyAttributesTable = new nsStaticCaseInsensitiveNameTable();
|
||||
if (!gHTMLEmptyAttributesTable) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// ismap
|
||||
mHTMLEmptyAttributes[5].mAttrName = txHTMLAtoms::ismap;
|
||||
mHTMLEmptyAttributes[5].mElementList.AppendObject(txHTMLAtoms::img);
|
||||
mHTMLEmptyAttributes[5].mElementList.AppendObject(txHTMLAtoms::input);
|
||||
gHTMLEmptyAttributesTable->Init(kHTMLEmptyAttributes,
|
||||
SHORTHAND_ATTR_COUNT);
|
||||
|
||||
// multiple
|
||||
mHTMLEmptyAttributes[6].mAttrName = txHTMLAtoms::multiple;
|
||||
mHTMLEmptyAttributes[6].mElementList.AppendObject(txHTMLAtoms::select);
|
||||
NS_ASSERTION(!gHTMLEmptyAttributesMaps, "pre existing map!");
|
||||
gHTMLEmptyAttributesMaps = new txEmptyAttributesMaps();
|
||||
if (!gHTMLEmptyAttributesMaps) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// noresize
|
||||
mHTMLEmptyAttributes[7].mAttrName = txHTMLAtoms::noresize;
|
||||
mHTMLEmptyAttributes[7].mElementList.AppendObject(txHTMLAtoms::frame);
|
||||
// checked
|
||||
gHTMLEmptyAttributesMaps->mMaps[0].AppendObject(txHTMLAtoms::input);
|
||||
|
||||
// noshade
|
||||
mHTMLEmptyAttributes[8].mAttrName = txHTMLAtoms::noshade;
|
||||
mHTMLEmptyAttributes[8].mElementList.AppendObject(txHTMLAtoms::hr);
|
||||
// compact
|
||||
gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dir);
|
||||
gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::dl);
|
||||
gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::menu);
|
||||
gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ol);
|
||||
gHTMLEmptyAttributesMaps->mMaps[1].AppendObject(txHTMLAtoms::ul);
|
||||
|
||||
// nowrap
|
||||
mHTMLEmptyAttributes[9].mAttrName = txHTMLAtoms::nowrap;
|
||||
mHTMLEmptyAttributes[9].mElementList.AppendObject(txHTMLAtoms::td);
|
||||
mHTMLEmptyAttributes[9].mElementList.AppendObject(txHTMLAtoms::th);
|
||||
// declare
|
||||
gHTMLEmptyAttributesMaps->mMaps[2].AppendObject(txHTMLAtoms::object);
|
||||
|
||||
// readonly
|
||||
mHTMLEmptyAttributes[10].mAttrName = txHTMLAtoms::readonly;
|
||||
mHTMLEmptyAttributes[10].mElementList.AppendObject(txHTMLAtoms::input);
|
||||
mHTMLEmptyAttributes[10].mElementList.AppendObject(txHTMLAtoms::textarea);
|
||||
// defer
|
||||
gHTMLEmptyAttributesMaps->mMaps[3].AppendObject(txHTMLAtoms::script);
|
||||
|
||||
// selected
|
||||
mHTMLEmptyAttributes[11].mAttrName = txHTMLAtoms::selected;
|
||||
mHTMLEmptyAttributes[11].mElementList.AppendObject(txHTMLAtoms::option);
|
||||
// disabled
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::button);
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::input);
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::optgroup);
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::option);
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::select);
|
||||
gHTMLEmptyAttributesMaps->mMaps[4].AppendObject(txHTMLAtoms::textarea);
|
||||
|
||||
// ismap
|
||||
gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::img);
|
||||
gHTMLEmptyAttributesMaps->mMaps[5].AppendObject(txHTMLAtoms::input);
|
||||
|
||||
// multiple
|
||||
gHTMLEmptyAttributesMaps->mMaps[6].AppendObject(txHTMLAtoms::select);
|
||||
|
||||
// noresize
|
||||
gHTMLEmptyAttributesMaps->mMaps[7].AppendObject(txHTMLAtoms::frame);
|
||||
|
||||
// noshade
|
||||
gHTMLEmptyAttributesMaps->mMaps[8].AppendObject(txHTMLAtoms::hr);
|
||||
|
||||
// nowrap
|
||||
gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::td);
|
||||
gHTMLEmptyAttributesMaps->mMaps[9].AppendObject(txHTMLAtoms::th);
|
||||
|
||||
// readonly
|
||||
gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::input);
|
||||
gHTMLEmptyAttributesMaps->mMaps[10].AppendObject(txHTMLAtoms::textarea);
|
||||
|
||||
// selected
|
||||
gHTMLEmptyAttributesMaps->mMaps[11].AppendObject(txHTMLAtoms::option);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void
|
||||
txHTMLOutput::shutdown()
|
||||
{
|
||||
if (0 == --gTableRefCount) {
|
||||
if (gHTMLEmptyTagsTable) {
|
||||
delete gHTMLEmptyTagsTable;
|
||||
gHTMLEmptyTagsTable = nsnull;
|
||||
}
|
||||
if (gHTMLEmptyAttributesTable) {
|
||||
delete gHTMLEmptyAttributesTable;
|
||||
gHTMLEmptyAttributesTable = nsnull;
|
||||
}
|
||||
if (gHTMLEmptyAttributesMaps) {
|
||||
delete gHTMLEmptyAttributesMaps;
|
||||
gHTMLEmptyAttributesMaps = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
txHTMLOutput::txHTMLOutput(txOutputFormat* aFormat, ostream* aOut)
|
||||
: txXMLOutput(aFormat, aOut)
|
||||
{
|
||||
mUseEmptyElementShorthand = PR_FALSE;
|
||||
}
|
||||
|
||||
txHTMLOutput::~txHTMLOutput()
|
||||
{
|
||||
}
|
||||
|
||||
void txHTMLOutput::attribute(const String& aName,
|
||||
void txHTMLOutput::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
if (!mStartTagOpen)
|
||||
// XXX Signal this? (can't add attributes after element closed)
|
||||
|
@ -135,10 +210,10 @@ void txHTMLOutput::attribute(const String& aName,
|
|||
|
||||
MBool shortHand = MB_FALSE;
|
||||
if (aNsID == kNameSpaceID_None) {
|
||||
String localPart;
|
||||
XMLUtils::getLocalPart(aName, localPart);
|
||||
const nsAString& localPart = XMLUtils::getLocalPart(aName);
|
||||
shortHand = isShorthandAttribute(localPart);
|
||||
if (shortHand && localPart.isEqualIgnoreCase(aValue)) {
|
||||
if (shortHand &&
|
||||
localPart.Equals(aValue, txCaseInsensitiveStringComparator())) {
|
||||
txListIterator iter(&mAttributes);
|
||||
txAttribute* setAtt = 0;
|
||||
txAtom* localName = TX_GET_ATOM(localPart);
|
||||
|
@ -150,7 +225,7 @@ void txHTMLOutput::attribute(const String& aName,
|
|||
}
|
||||
}
|
||||
if (!setAtt) {
|
||||
setAtt = new txAttribute(aNsID, localName, String());
|
||||
setAtt = new txAttribute(aNsID, localName, nsString());
|
||||
setAtt->mShorthand = MB_TRUE;
|
||||
mAttributes.add(setAtt);
|
||||
}
|
||||
|
@ -161,7 +236,7 @@ void txHTMLOutput::attribute(const String& aName,
|
|||
txXMLOutput::attribute(aName, aNsID, aValue);
|
||||
}
|
||||
|
||||
void txHTMLOutput::characters(const String& aData)
|
||||
void txHTMLOutput::characters(const nsAString& aData)
|
||||
{
|
||||
// Special-case script and style
|
||||
txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
|
||||
|
@ -177,10 +252,11 @@ void txHTMLOutput::characters(const String& aData)
|
|||
}
|
||||
}
|
||||
|
||||
void txHTMLOutput::endElement(const String& aName,
|
||||
void txHTMLOutput::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
if ((aNsID == kNameSpaceID_None) && isShorthandElement(aName) &&
|
||||
const nsAString& localPart = XMLUtils::getLocalPart(aName);
|
||||
if ((aNsID == kNameSpaceID_None) && isShorthandElement(localPart) &&
|
||||
mStartTagOpen) {
|
||||
MBool newLine = (mOutputFormat.mIndent == eTrue) &&
|
||||
mAfterEndTag;
|
||||
|
@ -197,14 +273,19 @@ void txHTMLOutput::endElement(const String& aName,
|
|||
delete (txExpandedName*)mCurrentElements.pop();
|
||||
}
|
||||
|
||||
void txHTMLOutput::processingInstruction(const String& aTarget, const String& aData)
|
||||
void txHTMLOutput::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
closeStartTag(MB_FALSE);
|
||||
if (mOutputFormat.mIndent == eTrue) {
|
||||
for (PRUint32 i = 0; i < mIndentLevel; i++)
|
||||
*mOut << ' ';
|
||||
}
|
||||
*mOut << PI_START << aTarget << SPACE << aData << R_ANGLE_BRACKET;
|
||||
*mOut << PI_START;
|
||||
printUTF8Chars(aTarget);
|
||||
*mOut << SPACE;
|
||||
printUTF8Chars(aData);
|
||||
*mOut << R_ANGLE_BRACKET;
|
||||
if (mOutputFormat.mIndent == eTrue)
|
||||
*mOut << endl;
|
||||
}
|
||||
|
@ -218,15 +299,15 @@ void txHTMLOutput::startDocument()
|
|||
*mOut << DOCTYPE_END << endl;
|
||||
}
|
||||
|
||||
void txHTMLOutput::startElement(const String& aName,
|
||||
void txHTMLOutput::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
txXMLOutput::startElement(aName, aNsID);
|
||||
|
||||
txAtom* localAtom;
|
||||
if (aNsID == kNameSpaceID_None) {
|
||||
String localName(aName);
|
||||
localName.toLowerCase();
|
||||
nsAutoString localName;
|
||||
TX_ToLowerCase(aName, localName);
|
||||
localAtom = TX_GET_ATOM(localName);
|
||||
}
|
||||
else {
|
||||
|
@ -253,41 +334,30 @@ void txHTMLOutput::closeStartTag(MBool aUseEmptyElementShorthand)
|
|||
*mOut << ' ';
|
||||
}
|
||||
*mOut << LT << "meta http-equiv=" << QUOTE << "Content-Type" << QUOTE;
|
||||
*mOut << " content=" << QUOTE << mOutputFormat.mMediaType << ";";
|
||||
*mOut << " charset=" << mOutputFormat.mEncoding << QUOTE << GT;
|
||||
*mOut << " content=" << QUOTE;
|
||||
printUTF8Chars(mOutputFormat.mMediaType);
|
||||
*mOut << "; charset=";
|
||||
printUTF8Chars(mOutputFormat.mEncoding);
|
||||
*mOut << QUOTE << GT;
|
||||
}
|
||||
else {
|
||||
txXMLOutput::closeStartTag(aUseEmptyElementShorthand);
|
||||
}
|
||||
}
|
||||
|
||||
MBool txHTMLOutput::isShorthandElement(const String& aName)
|
||||
MBool txHTMLOutput::isShorthandElement(const nsAString& aLocalName)
|
||||
{
|
||||
String localName;
|
||||
XMLUtils::getLocalPart(aName, localName);
|
||||
localName.toLowerCase();
|
||||
nsCOMPtr<nsIAtom> localAtom = do_GetAtom(localName);
|
||||
if (localAtom && mHTMLEmptyTags.IndexOf(localAtom) > -1) {
|
||||
return MB_TRUE;
|
||||
}
|
||||
return MB_FALSE;
|
||||
return (gHTMLEmptyTagsTable->Lookup(aLocalName) !=
|
||||
nsStaticCaseInsensitiveNameTable::NOT_FOUND);
|
||||
}
|
||||
|
||||
MBool txHTMLOutput::isShorthandAttribute(const String& aLocalName)
|
||||
MBool txHTMLOutput::isShorthandAttribute(const nsAString& aLocalName)
|
||||
{
|
||||
String localName(aLocalName);
|
||||
localName.toLowerCase();
|
||||
nsCOMPtr<nsIAtom> localAtom = do_GetAtom(localName);
|
||||
PRUint8 k = 0;
|
||||
for ( ; k < SHORTHAND_ATTR_COUNT; ++k) {
|
||||
if (mHTMLEmptyAttributes[k].mAttrName == localAtom) {
|
||||
txExpandedName* currentElement =
|
||||
(txExpandedName*)mCurrentElements.peek();
|
||||
if (mHTMLEmptyAttributes[k].mElementList.IndexOf(currentElement->mLocalName) > -1) {
|
||||
return MB_TRUE;
|
||||
}
|
||||
return MB_FALSE;
|
||||
}
|
||||
PRInt32 index = gHTMLEmptyTagsTable->Lookup(aLocalName);
|
||||
if (index == nsStaticCaseInsensitiveNameTable::NOT_FOUND) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
return MB_FALSE;
|
||||
|
||||
txExpandedName* currentElement = (txExpandedName*)mCurrentElements.peek();
|
||||
return (gHTMLEmptyAttributesMaps->mMaps[index].IndexOf(currentElement->mLocalName) > -1);
|
||||
}
|
||||
|
|
|
@ -40,12 +40,7 @@
|
|||
#define TRANSFRMX_HTML_OUTPUT_H
|
||||
|
||||
#include "txXMLOutput.h"
|
||||
#include "Map.h"
|
||||
#include "Stack.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
#define SHORTHAND_ATTR_COUNT 12
|
||||
#define EMPTY_ELEMENTS_COUNT 13
|
||||
|
||||
class txHTMLOutput : public txXMLOutput
|
||||
{
|
||||
|
@ -53,6 +48,12 @@ public:
|
|||
txHTMLOutput(txOutputFormat* aFormat, ostream* aOut);
|
||||
~txHTMLOutput();
|
||||
|
||||
/**
|
||||
* Init/release table with shorthands.
|
||||
*/
|
||||
static nsresult init();
|
||||
static void shutdown();
|
||||
|
||||
/*
|
||||
* Signals to receive the start of an attribute.
|
||||
*
|
||||
|
@ -60,16 +61,16 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/*
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive the end of an element.
|
||||
|
@ -77,7 +78,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/*
|
||||
|
@ -86,8 +87,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the start of a document.
|
||||
|
@ -100,20 +101,14 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
private:
|
||||
void closeStartTag(MBool aUseEmptyElementShorthand);
|
||||
MBool isShorthandElement(const String& aName);
|
||||
MBool isShorthandAttribute(const String& aLocalName);
|
||||
MBool isShorthandElement(const nsAString& aName);
|
||||
MBool isShorthandAttribute(const nsAString& aLocalName);
|
||||
|
||||
nsCOMArray<nsIAtom> mHTMLEmptyTags;
|
||||
struct EmptyAttrBag {
|
||||
nsCOMPtr<nsIAtom> mAttrName;
|
||||
nsCOMArray<nsIAtom> mElementList;
|
||||
};
|
||||
EmptyAttrBag mHTMLEmptyAttributes[SHORTHAND_ATTR_COUNT];
|
||||
Stack mCurrentElements;
|
||||
};
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ ExprResult* txKeyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
|
||||
txListIterator iter(¶ms);
|
||||
String keyQName;
|
||||
nsAutoString keyQName;
|
||||
evaluateToString((Expr*)iter.next(), aContext, keyQName);
|
||||
Expr* param = (Expr*) iter.next();
|
||||
|
||||
|
@ -71,7 +71,7 @@ ExprResult* txKeyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
|
||||
if (!key) {
|
||||
String err(NS_LITERAL_STRING("No key with that name in: "));
|
||||
nsAutoString err(NS_LITERAL_STRING("No key with that name in: "));
|
||||
toString(err);
|
||||
aContext->receiveError(err, NS_ERROR_INVALID_ARG);
|
||||
return res;
|
||||
|
@ -91,13 +91,13 @@ ExprResult* txKeyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
if (exprResult->getResultType() == ExprResult::NODESET) {
|
||||
NodeSet* nodeSet = (NodeSet*) exprResult;
|
||||
for (int i=0; i<nodeSet->size(); i++) {
|
||||
String val;
|
||||
nsAutoString val;
|
||||
XMLDOMUtils::getNodeValue(nodeSet->get(i), val);
|
||||
res->add(key->getNodes(val, contextDoc));
|
||||
}
|
||||
}
|
||||
else {
|
||||
String val;
|
||||
nsAutoString val;
|
||||
exprResult->stringValue(val);
|
||||
res->append(key->getNodes(val, contextDoc));
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ txXSLKey::~txXSLKey()
|
|||
* @return a NodeSet* containing all nodes in doc matching with value
|
||||
* keyValue
|
||||
*/
|
||||
const NodeSet* txXSLKey::getNodes(String& aKeyValue, Document* aDoc)
|
||||
const NodeSet* txXSLKey::getNodes(const nsAString& aKeyValue, Document* aDoc)
|
||||
{
|
||||
NS_ASSERTION(aDoc, "missing document");
|
||||
if (!aDoc)
|
||||
|
@ -196,7 +196,7 @@ NamedMap* txXSLKey::addDocument(Document* aDoc)
|
|||
{
|
||||
NamedMap* map = new NamedMap;
|
||||
if (!map)
|
||||
return NULL;
|
||||
return nsnull;
|
||||
map->setObjectDeletion(MB_TRUE);
|
||||
mMaps.put(aDoc, map);
|
||||
indexTree(aDoc, map);
|
||||
|
@ -236,7 +236,7 @@ void txXSLKey::indexTree(Node* aNode, NamedMap* aMap)
|
|||
*/
|
||||
void txXSLKey::testNode(Node* aNode, NamedMap* aMap)
|
||||
{
|
||||
String val;
|
||||
nsAutoString val;
|
||||
NodeSet *nodeSet;
|
||||
|
||||
txListIterator iter(&mKeys);
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIDOMText.h"
|
||||
#include "nsIDocumentTransformer.h"
|
||||
#include "TxString.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIDOMNSDocument.h"
|
||||
|
||||
|
@ -64,7 +63,7 @@ txMozillaTextOutput::txMozillaTextOutput(nsIDOMDocumentFragment* aDest)
|
|||
aDest->GetOwnerDocument(getter_AddRefs(doc));
|
||||
NS_ASSERTION(doc, "unable to get ownerdocument");
|
||||
nsCOMPtr<nsIDOMText> textNode;
|
||||
nsresult rv = doc->CreateTextNode(NS_LITERAL_STRING(""),
|
||||
nsresult rv = doc->CreateTextNode(nsString(),
|
||||
getter_AddRefs(textNode));
|
||||
if (NS_FAILED(rv)) {
|
||||
return;
|
||||
|
@ -85,19 +84,19 @@ txMozillaTextOutput::~txMozillaTextOutput()
|
|||
|
||||
NS_IMPL_ISUPPORTS1(txMozillaTextOutput, txIOutputXMLEventHandler);
|
||||
|
||||
void txMozillaTextOutput::attribute(const String& aName,
|
||||
void txMozillaTextOutput::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::characters(const String& aData)
|
||||
void txMozillaTextOutput::characters(const nsAString& aData)
|
||||
{
|
||||
if (mTextNode)
|
||||
mTextNode->AppendData(aData);
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::comment(const String& aData)
|
||||
void txMozillaTextOutput::comment(const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -109,13 +108,13 @@ void txMozillaTextOutput::endDocument()
|
|||
}
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::endElement(const String& aName,
|
||||
void txMozillaTextOutput::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txMozillaTextOutput::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -165,7 +164,7 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
|
|||
|
||||
nsCOMPtr<nsIDOMNSDocument> nsDoc = do_QueryInterface(mDocument);
|
||||
if (nsDoc) {
|
||||
nsDoc->SetTitle(NS_LITERAL_STRING(""));
|
||||
nsDoc->SetTitle(nsString());
|
||||
}
|
||||
|
||||
// Reset and set up document
|
||||
|
@ -294,7 +293,7 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIDOMText> textNode;
|
||||
mDocument->CreateTextNode(NS_LITERAL_STRING(""),
|
||||
mDocument->CreateTextNode(nsString(),
|
||||
getter_AddRefs(textNode));
|
||||
NS_ASSERTION(textNode, "Failed to create the text node");
|
||||
if (!textNode) {
|
||||
|
@ -311,7 +310,7 @@ void txMozillaTextOutput::createResultDocument(nsIDOMDocument* aSourceDocument,
|
|||
mTextNode = textNode;
|
||||
}
|
||||
|
||||
void txMozillaTextOutput::startElement(const String& aName,
|
||||
void txMozillaTextOutput::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -68,23 +68,23 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/**
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals to receive characters that don't need output escaping.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void charactersNoOutputEscaping(const String& aData)
|
||||
void charactersNoOutputEscaping(const nsAString& aData)
|
||||
{
|
||||
NS_ASSERTION(0, "Don't call this in module, we don't do d-o-e");
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -108,7 +108,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget, const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the start of a document.
|
||||
|
@ -142,7 +143,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
|
|
@ -115,7 +115,8 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
|||
|
||||
case eHTMLOutput:
|
||||
{
|
||||
*aHandler = new txMozillaXMLOutput(String(), kNameSpaceID_None,
|
||||
*aHandler = new txMozillaXMLOutput(nsString(),
|
||||
kNameSpaceID_None,
|
||||
aFormat, mSourceDocument,
|
||||
mResultDocument, mObserver);
|
||||
break;
|
||||
|
@ -135,7 +136,7 @@ txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
|||
|
||||
nsresult
|
||||
txToDocHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
PRInt32 aNsID,
|
||||
txIOutputXMLEventHandler** aHandler)
|
||||
{
|
||||
|
@ -209,7 +210,7 @@ txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
|||
|
||||
nsresult
|
||||
txToFragmentHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
PRInt32 aNsID,
|
||||
txIOutputXMLEventHandler** aHandler)
|
||||
{
|
||||
|
@ -722,7 +723,7 @@ txVariable::Convert(nsIVariant *aValue, ExprResult** aResult)
|
|||
case nsIDataType::VTYPE_CSTRING:
|
||||
case nsIDataType::VTYPE_ASTRING:
|
||||
{
|
||||
String value;
|
||||
nsAutoString value;
|
||||
nsresult rv = aValue->GetAsAString(value);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -38,12 +38,11 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txNodeSorter.h"
|
||||
#include <string.h>
|
||||
#include "Names.h"
|
||||
#include "ProcessorState.h"
|
||||
#include "txXPathResultComparator.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txForwardContext.h"
|
||||
#include "txStringUtils.h"
|
||||
|
||||
/*
|
||||
* Sorts Nodes as specified by the W3C XSLT 1.0 Recommendation
|
||||
|
@ -77,7 +76,7 @@ MBool txNodeSorter::addSortElement(Element* aSortElement)
|
|||
}
|
||||
|
||||
// Get common attributes
|
||||
String attrValue;
|
||||
nsAutoString attrValue;
|
||||
|
||||
// Select
|
||||
if (aSortElement->hasAttr(txXSLTAtoms::select, kNameSpaceID_None))
|
||||
|
@ -99,10 +98,10 @@ MBool txNodeSorter::addSortElement(Element* aSortElement)
|
|||
// Order
|
||||
MBool ascending;
|
||||
MBool hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::order, attrValue);
|
||||
if (!hasAttr || attrValue.Equals(ASCENDING_VALUE)) {
|
||||
if (!hasAttr || TX_StringEqualsAtom(attrValue, txXSLTAtoms::ascending)) {
|
||||
ascending = MB_TRUE;
|
||||
}
|
||||
else if (attrValue.Equals(DESCENDING_VALUE)) {
|
||||
else if (TX_StringEqualsAtom(attrValue, txXSLTAtoms::descending)) {
|
||||
ascending = MB_FALSE;
|
||||
}
|
||||
else {
|
||||
|
@ -113,23 +112,24 @@ MBool txNodeSorter::addSortElement(Element* aSortElement)
|
|||
|
||||
|
||||
// Create comparator depending on datatype
|
||||
String dataType;
|
||||
nsAutoString dataType;
|
||||
hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::dataType, dataType);
|
||||
if (!hasAttr || dataType.Equals(TEXT_VALUE)) {
|
||||
if (!hasAttr || TX_StringEqualsAtom(dataType, txXSLTAtoms::text)) {
|
||||
// Text comparator
|
||||
|
||||
// Language
|
||||
String lang;
|
||||
nsAutoString lang;
|
||||
if (!getAttrAsAVT(aSortElement, txXSLTAtoms::lang, lang))
|
||||
lang.Append(DEFAULT_LANG);
|
||||
|
||||
// Case-order
|
||||
MBool upperFirst;
|
||||
hasAttr = getAttrAsAVT(aSortElement, txXSLTAtoms::caseOrder, attrValue);
|
||||
if (!hasAttr || attrValue.Equals(UPPER_FIRST_VALUE)) {
|
||||
if (!hasAttr || TX_StringEqualsAtom(attrValue,
|
||||
txXSLTAtoms::upperFirst)) {
|
||||
upperFirst = MB_TRUE;
|
||||
}
|
||||
else if (attrValue.Equals(LOWER_FIRST_VALUE)) {
|
||||
else if (TX_StringEqualsAtom(attrValue, txXSLTAtoms::lowerFirst)) {
|
||||
upperFirst = MB_FALSE;
|
||||
}
|
||||
else {
|
||||
|
@ -142,7 +142,7 @@ MBool txNodeSorter::addSortElement(Element* aSortElement)
|
|||
upperFirst,
|
||||
lang);
|
||||
}
|
||||
else if (dataType.Equals(NUMBER_VALUE)) {
|
||||
else if (TX_StringEqualsAtom(dataType, txXSLTAtoms::number)) {
|
||||
// Number comparator
|
||||
key->mComparator = new txResultNumberComparator(ascending);
|
||||
}
|
||||
|
@ -265,11 +265,11 @@ int txNodeSorter::compareNodes(SortableNode* aSNode1,
|
|||
|
||||
MBool txNodeSorter::getAttrAsAVT(Element* aSortElement,
|
||||
txAtom* aAttrName,
|
||||
String& aResult)
|
||||
nsAString& aResult)
|
||||
{
|
||||
aResult.Truncate();
|
||||
|
||||
String attValue;
|
||||
nsAutoString attValue;
|
||||
if (!aSortElement->getAttr(aAttrName, kNameSpaceID_None, attValue))
|
||||
return MB_FALSE;
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ class Expr;
|
|||
class Node;
|
||||
class NodeSet;
|
||||
class ProcessorState;
|
||||
class String;
|
||||
class TxObject;
|
||||
class txXPathResultComparator;
|
||||
|
||||
|
@ -87,7 +86,7 @@ private:
|
|||
|
||||
MBool getAttrAsAVT(Element* aSortElement,
|
||||
txAtom* aAttrName,
|
||||
String& aResult);
|
||||
nsAString& aResult);
|
||||
|
||||
txList mSortKeys;
|
||||
ProcessorState* mPs;
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
|
||||
#include "baseutils.h"
|
||||
#include "List.h"
|
||||
#include "TxString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
enum txOutputMethod {
|
||||
eMethodNotSet,
|
||||
|
@ -76,11 +76,11 @@ public:
|
|||
|
||||
// The xml version number that should be used when serializing
|
||||
// xml documents
|
||||
String mVersion;
|
||||
nsString mVersion;
|
||||
|
||||
// The XML character encoding that should be used when serializing
|
||||
// xml documents
|
||||
String mEncoding;
|
||||
nsString mEncoding;
|
||||
|
||||
// Signals if we should output an XML declaration
|
||||
txThreeState mOmitXMLDeclaration;
|
||||
|
@ -89,10 +89,10 @@ public:
|
|||
txThreeState mStandalone;
|
||||
|
||||
// The public Id for creating a DOCTYPE
|
||||
String mPublicId;
|
||||
nsString mPublicId;
|
||||
|
||||
// The System Id for creating a DOCTYPE
|
||||
String mSystemId;
|
||||
nsString mSystemId;
|
||||
|
||||
// The elements whose text node children should be output as CDATA
|
||||
txList mCDATASectionElements;
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
txThreeState mIndent;
|
||||
|
||||
// The media type of the output
|
||||
String mMediaType;
|
||||
nsString mMediaType;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,11 +38,11 @@
|
|||
|
||||
#include "txPatternParser.h"
|
||||
#include "ExprLexer.h"
|
||||
#include "Names.h"
|
||||
#include "txAtoms.h"
|
||||
#include "txStringUtils.h"
|
||||
#include "txXSLTPatterns.h"
|
||||
|
||||
txPattern* txPatternParser::createPattern(const String& aPattern,
|
||||
txPattern* txPatternParser::createPattern(const nsAFlatString& aPattern,
|
||||
txIParseContext* aContext,
|
||||
ProcessorState* aPs)
|
||||
{
|
||||
|
@ -151,15 +151,13 @@ nsresult txPatternParser::createLocPathPattern(ExprLexer& aLexer,
|
|||
case Token::FUNCTION_NAME:
|
||||
// id(Literal) or key(Literal, Literal)
|
||||
{
|
||||
String& name = aLexer.nextToken()->value;
|
||||
txAtom* nameAtom = TX_GET_ATOM(name);
|
||||
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLexer.nextToken()->value);
|
||||
if (nameAtom == txXPathAtoms::id) {
|
||||
rv = createIdPattern(aLexer, stepPattern);
|
||||
}
|
||||
else if (nameAtom == txXSLTAtoms::key) {
|
||||
rv = createKeyPattern(aLexer, aContext, aPs, stepPattern);
|
||||
}
|
||||
TX_IF_RELEASE_ATOM(nameAtom);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
@ -238,7 +236,7 @@ nsresult txPatternParser::createIdPattern(ExprLexer& aLexer,
|
|||
if (aLexer.nextToken()->type != Token::L_PAREN &&
|
||||
aLexer.peek()->type != Token::LITERAL)
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
const String& value = aLexer.nextToken()->value;
|
||||
const nsString& value = aLexer.nextToken()->value;
|
||||
if (aLexer.nextToken()->type != Token::R_PAREN)
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
aPattern = new txIdPattern(value);
|
||||
|
@ -254,11 +252,11 @@ nsresult txPatternParser::createKeyPattern(ExprLexer& aLexer,
|
|||
if (aLexer.nextToken()->type != Token::L_PAREN &&
|
||||
aLexer.peek()->type != Token::LITERAL)
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
const String& key = aLexer.nextToken()->value;
|
||||
const nsString& key = aLexer.nextToken()->value;
|
||||
if (aLexer.nextToken()->type != Token::COMMA &&
|
||||
aLexer.peek()->type != Token::LITERAL)
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
const String& value = aLexer.nextToken()->value;
|
||||
const nsString& value = aLexer.nextToken()->value;
|
||||
if (aLexer.nextToken()->type != Token::R_PAREN)
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
|
||||
|
@ -285,10 +283,10 @@ nsresult txPatternParser::createStepPattern(ExprLexer& aLexer,
|
|||
MBool isAttr = MB_FALSE;
|
||||
Token* tok = aLexer.peek();
|
||||
if (tok->type == Token::AXIS_IDENTIFIER) {
|
||||
if (ATTRIBUTE_AXIS.Equals(tok->value)) {
|
||||
if (TX_StringEqualsAtom(tok->value, txXPathAtoms::attribute)) {
|
||||
isAttr = MB_TRUE;
|
||||
}
|
||||
else if (!CHILD_AXIS.Equals(tok->value)) {
|
||||
else if (!TX_StringEqualsAtom(tok->value, txXPathAtoms::child)) {
|
||||
// all done already for CHILD_AXIS, for all others
|
||||
// XXX report unexpected axis error
|
||||
return NS_ERROR_XPATH_PARSE_FAILED;
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
class txPatternParser : public ExprParser
|
||||
{
|
||||
public:
|
||||
static txPattern* createPattern(const String& aPattern,
|
||||
static txPattern* createPattern(const nsAFlatString& aPattern,
|
||||
txIParseContext* aContext,
|
||||
ProcessorState* aPs);
|
||||
protected:
|
||||
|
|
|
@ -63,9 +63,9 @@ txRtfHandler::~txRtfHandler()
|
|||
{
|
||||
}
|
||||
|
||||
void txRtfHandler::attribute(const String& aName,
|
||||
void txRtfHandler::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
Element* element = (Element*)mCurrentNode;
|
||||
NS_ASSERTION(element, "We need an element");
|
||||
|
@ -77,12 +77,12 @@ void txRtfHandler::attribute(const String& aName,
|
|||
// XXX ErrorReport: Can't add attributes after adding children
|
||||
return;
|
||||
|
||||
String nsURI;
|
||||
nsAutoString nsURI;
|
||||
mDocument->namespaceIDToURI(aNsID, nsURI);
|
||||
element->setAttributeNS(nsURI, aName, aValue);
|
||||
}
|
||||
|
||||
void txRtfHandler::characters(const String& aData)
|
||||
void txRtfHandler::characters(const nsAString& aData)
|
||||
{
|
||||
NS_ASSERTION(mCurrentNode, "We need a node");
|
||||
if (!mCurrentNode)
|
||||
|
@ -92,7 +92,7 @@ void txRtfHandler::characters(const String& aData)
|
|||
mCurrentNode->appendChild(text);
|
||||
}
|
||||
|
||||
void txRtfHandler::comment(const String& aData)
|
||||
void txRtfHandler::comment(const nsAString& aData)
|
||||
{
|
||||
NS_ASSERTION(mCurrentNode, "We need a node");
|
||||
if (!mCurrentNode)
|
||||
|
@ -106,7 +106,7 @@ void txRtfHandler::endDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txRtfHandler::endElement(const String& aName,
|
||||
void txRtfHandler::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
NS_ASSERTION(mCurrentNode, "We need a node");
|
||||
|
@ -116,8 +116,8 @@ void txRtfHandler::endElement(const String& aName,
|
|||
mCurrentNode = mCurrentNode->getParentNode();
|
||||
}
|
||||
|
||||
void txRtfHandler::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txRtfHandler::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
NS_ASSERTION(mCurrentNode, "We need a node");
|
||||
if (!mCurrentNode)
|
||||
|
@ -132,14 +132,14 @@ void txRtfHandler::startDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txRtfHandler::startElement(const String& aName,
|
||||
void txRtfHandler::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
NS_ASSERTION(mCurrentNode, "We need a node");
|
||||
if (!mCurrentNode)
|
||||
return;
|
||||
|
||||
String nsURI;
|
||||
nsAutoString nsURI;
|
||||
mDocument->namespaceIDToURI(aNsID, nsURI);
|
||||
Element* element = mDocument->createElementNS(nsURI, aName);
|
||||
mCurrentNode->appendChild(element);
|
||||
|
|
|
@ -59,23 +59,23 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/**
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -89,7 +89,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -98,8 +98,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the start of a document.
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
private:
|
||||
|
|
|
@ -39,13 +39,14 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txStandaloneXSLTProcessor.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "txHTMLOutput.h"
|
||||
#include "txSingleNodeContext.h"
|
||||
#include "txTextOutput.h"
|
||||
#include "txUnknownHandler.h"
|
||||
#include "txURIUtils.h"
|
||||
#include "XMLParser.h"
|
||||
#include "txSingleNodeContext.h"
|
||||
#include "Names.h"
|
||||
#include "txUnknownHandler.h"
|
||||
#include "txHTMLOutput.h"
|
||||
#include "txTextOutput.h"
|
||||
|
||||
/**
|
||||
* Output Handler Factory
|
||||
|
@ -98,7 +99,7 @@ txStandaloneHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
|||
|
||||
nsresult
|
||||
txStandaloneHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
PRInt32 aNsID,
|
||||
txIOutputXMLEventHandler** aHandler)
|
||||
{
|
||||
|
@ -120,7 +121,7 @@ txStandaloneHandlerFactory::createHandlerWith(txOutputFormat* aFormat,
|
|||
* or an error is returned.
|
||||
*/
|
||||
nsresult
|
||||
txStandaloneXSLTProcessor::transform(String& aXMLPath, ostream& aOut,
|
||||
txStandaloneXSLTProcessor::transform(nsACString& aXMLPath, ostream& aOut,
|
||||
ErrorObserver& aErr)
|
||||
{
|
||||
Document* xmlDoc = parsePath(aXMLPath, aErr);
|
||||
|
@ -141,8 +142,9 @@ txStandaloneXSLTProcessor::transform(String& aXMLPath, ostream& aOut,
|
|||
* stylesheet.
|
||||
*/
|
||||
nsresult
|
||||
txStandaloneXSLTProcessor::transform(String& aXMLPath, String& aXSLPath,
|
||||
ostream& aOut, ErrorObserver& aErr)
|
||||
txStandaloneXSLTProcessor::transform(nsACString& aXMLPath,
|
||||
nsACString& aXSLPath, ostream& aOut,
|
||||
ErrorObserver& aErr)
|
||||
{
|
||||
Document* xmlDoc = parsePath(aXMLPath, aErr);
|
||||
if (!xmlDoc) {
|
||||
|
@ -176,10 +178,10 @@ txStandaloneXSLTProcessor::transform(Document* aXMLDoc, ostream& aOut,
|
|||
}
|
||||
|
||||
// get stylesheet path
|
||||
String stylePath;
|
||||
nsAutoString stylePath;
|
||||
getHrefFromStylesheetPI(*aXMLDoc, stylePath);
|
||||
|
||||
Document* xslDoc = parsePath(stylePath, aErr);
|
||||
Document* xslDoc = parsePath(NS_LossyConvertUCS2toASCII(stylePath), aErr);
|
||||
if (!xslDoc) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -251,110 +253,136 @@ txStandaloneXSLTProcessor::transform(Document* aSource, Node* aStylesheet,
|
|||
* are found, the one closest to the end of the document is used.
|
||||
*/
|
||||
void txStandaloneXSLTProcessor::getHrefFromStylesheetPI(Document& xmlDocument,
|
||||
String& href)
|
||||
nsAString& href)
|
||||
{
|
||||
Node* node = xmlDocument.getFirstChild();
|
||||
String type;
|
||||
String tmpHref;
|
||||
nsAutoString type;
|
||||
nsAutoString tmpHref;
|
||||
while (node) {
|
||||
if (node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
|
||||
String target = node->getNodeName();
|
||||
if (STYLESHEET_PI.Equals(target) ||
|
||||
STYLESHEET_PI_OLD.Equals(target)) {
|
||||
String data = node->getNodeValue();
|
||||
nsAutoString target;
|
||||
node->getNodeName(target);
|
||||
if (target.Equals(NS_LITERAL_STRING("xml-stylesheet"))) {
|
||||
nsAutoString data;
|
||||
node->getNodeValue(data);
|
||||
type.Truncate();
|
||||
tmpHref.Truncate();
|
||||
parseStylesheetPI(data, type, tmpHref);
|
||||
if (XSL_MIME_TYPE.Equals(type)) {
|
||||
if (type.Equals(NS_LITERAL_STRING("text/xsl"))) {
|
||||
href.Truncate();
|
||||
URIUtils::resolveHref(tmpHref, node->getBaseURI(), href);
|
||||
nsAutoString baseURI;
|
||||
node->getBaseURI(baseURI);
|
||||
URIUtils::resolveHref(tmpHref, baseURI, href);
|
||||
}
|
||||
}
|
||||
}
|
||||
node = node->getNextSibling();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the contents of data, and returns the type and href pseudo attributes
|
||||
* (Based on code copied from nsParserUtils)
|
||||
*/
|
||||
void txStandaloneXSLTProcessor::parseStylesheetPI(String& data,
|
||||
String& type,
|
||||
String& href)
|
||||
{
|
||||
PRUint32 size = data.Length();
|
||||
NamedMap bufferMap;
|
||||
bufferMap.put(String(NS_LITERAL_STRING("type")), &type);
|
||||
bufferMap.put(String(NS_LITERAL_STRING("href")), &href);
|
||||
PRUint32 ccount = 0;
|
||||
MBool inLiteral = MB_FALSE;
|
||||
PRUnichar matchQuote = '"';
|
||||
String sink;
|
||||
String* buffer = &sink;
|
||||
#define SKIP_WHITESPACE(iter, end_iter) \
|
||||
while ((iter) != (end_iter) && nsCRT::IsAsciiSpace(*(iter))) { \
|
||||
++(iter); \
|
||||
} \
|
||||
if ((iter) == (end_iter)) \
|
||||
break
|
||||
|
||||
for (ccount = 0; ccount < size; ccount++) {
|
||||
PRUnichar ch = data.CharAt(ccount);
|
||||
switch ( ch ) {
|
||||
case ' ':
|
||||
if (inLiteral) {
|
||||
buffer->Append(ch);
|
||||
}
|
||||
break;
|
||||
case '=':
|
||||
if (inLiteral) {
|
||||
buffer->Append(ch);
|
||||
}
|
||||
else if (!buffer->IsEmpty()) {
|
||||
buffer = (String*)bufferMap.get(*buffer);
|
||||
if (!buffer) {
|
||||
sink.Truncate();
|
||||
buffer = &sink;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '"':
|
||||
case '\'':
|
||||
if (inLiteral) {
|
||||
if (matchQuote == ch) {
|
||||
inLiteral = MB_FALSE;
|
||||
sink.Truncate();
|
||||
buffer = &sink;
|
||||
}
|
||||
else {
|
||||
buffer->Append(ch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
inLiteral = MB_TRUE;
|
||||
matchQuote = ch;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
buffer->Append(ch);
|
||||
break;
|
||||
}
|
||||
#define SKIP_ATTR_NAME(iter, end_iter) \
|
||||
while ((iter) != (end_iter) && !nsCRT::IsAsciiSpace(*(iter)) && \
|
||||
*(iter) != '=') { \
|
||||
++(iter); \
|
||||
} \
|
||||
if ((iter) == (end_iter)) \
|
||||
break
|
||||
|
||||
void txStandaloneXSLTProcessor::parseStylesheetPI(const nsAFlatString& aData,
|
||||
nsAString& aType,
|
||||
nsAString& aHref)
|
||||
{
|
||||
nsAFlatString::const_char_iterator start, end;
|
||||
aData.BeginReading(start);
|
||||
aData.EndReading(end);
|
||||
nsAFlatString::const_char_iterator iter;
|
||||
PRInt8 found = 0;
|
||||
|
||||
while (start != end) {
|
||||
SKIP_WHITESPACE(start, end);
|
||||
iter = start;
|
||||
SKIP_ATTR_NAME(iter, end);
|
||||
|
||||
// Remember the attr name.
|
||||
const nsAString & attrName = Substring(start, iter);
|
||||
|
||||
// Now check whether this is a valid name="value" pair.
|
||||
start = iter;
|
||||
SKIP_WHITESPACE(start, end);
|
||||
if (*start != '=') {
|
||||
// No '=', so this is not a name="value" pair. We don't know
|
||||
// what it is, and we have no way to handle it.
|
||||
break;
|
||||
}
|
||||
|
||||
// Have to skip the value.
|
||||
++start;
|
||||
SKIP_WHITESPACE(start, end);
|
||||
PRUnichar q = *start;
|
||||
if (q != QUOTE && q != APOSTROPHE) {
|
||||
// Not a valid quoted value, so bail.
|
||||
break;
|
||||
}
|
||||
|
||||
++start; // Point to the first char of the value.
|
||||
iter = start;
|
||||
while (iter != end && *iter != q) {
|
||||
++iter;
|
||||
}
|
||||
if (iter == end) {
|
||||
// Oops, unterminated quoted string.
|
||||
break;
|
||||
}
|
||||
|
||||
// At this point attrName holds the name of the "attribute" and
|
||||
// the value is between start and iter.
|
||||
if (attrName.Equals(NS_LITERAL_STRING("type"))) {
|
||||
aType = Substring(start, iter);
|
||||
++found;
|
||||
}
|
||||
else if (attrName.Equals(NS_LITERAL_STRING("href"))) {
|
||||
aHref = Substring(start, iter);
|
||||
++found;
|
||||
}
|
||||
|
||||
// Stop if we found both attributes
|
||||
if (found == 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Resume scanning after the end of the attribute value.
|
||||
start = iter;
|
||||
++start; // To move past the quote char.
|
||||
}
|
||||
}
|
||||
|
||||
Document*
|
||||
txStandaloneXSLTProcessor::parsePath(const String& aPath, ErrorObserver& aErr)
|
||||
txStandaloneXSLTProcessor::parsePath(const nsACString& aPath, ErrorObserver& aErr)
|
||||
{
|
||||
ifstream xmlInput(NS_LossyConvertUCS2toASCII(aPath).get(), ios::in);
|
||||
NS_ConvertASCIItoUCS2 path(aPath);
|
||||
|
||||
ifstream xmlInput(PromiseFlatCString(aPath).get(), ios::in);
|
||||
if (!xmlInput) {
|
||||
String err(NS_LITERAL_STRING("Couldn't open "));
|
||||
err.Append(aPath);
|
||||
aErr.receiveError(err);
|
||||
aErr.receiveError(NS_LITERAL_STRING("Couldn't open ") + path);
|
||||
return 0;
|
||||
}
|
||||
// parse source
|
||||
XMLParser xmlParser;
|
||||
Document* xmlDoc = xmlParser.parse(xmlInput, aPath);
|
||||
Document* xmlDoc = xmlParser.parse(xmlInput, path);
|
||||
xmlInput.close();
|
||||
if (!xmlDoc) {
|
||||
String err(NS_LITERAL_STRING("Parsing error in "));
|
||||
err.Append(aPath);
|
||||
aErr.receiveError(err);
|
||||
aErr.receiveError(NS_LITERAL_STRING("Parsing error in ") + path);
|
||||
}
|
||||
return xmlDoc;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,8 @@ public:
|
|||
* @param aErr error observer
|
||||
* @result NS_OK if transformation was successful
|
||||
*/
|
||||
nsresult transform(String& aXMLPath, ostream& aOut, ErrorObserver& aErr);
|
||||
nsresult transform(nsACString& aXMLPath, ostream& aOut,
|
||||
ErrorObserver& aErr);
|
||||
|
||||
/**
|
||||
* Transform a XML document given by path with the given
|
||||
|
@ -105,8 +106,8 @@ public:
|
|||
* @param aErr error observer
|
||||
* @result NS_OK if transformation was successful
|
||||
*/
|
||||
nsresult transform(String& aXMLPath, String& aXSLPath, ostream& aOut,
|
||||
ErrorObserver& aErr);
|
||||
nsresult transform(nsACString& aXMLPath, nsACString& aXSLPath,
|
||||
ostream& aOut, ErrorObserver& aErr);
|
||||
|
||||
/**
|
||||
* Transform a XML document.
|
||||
|
@ -140,14 +141,14 @@ protected:
|
|||
* added to the given href argument. If multiple text/xsl stylesheet PIs
|
||||
* are found, the one closest to the end of the document is used.
|
||||
*/
|
||||
static void getHrefFromStylesheetPI(Document& xmlDocument, String& href);
|
||||
static void getHrefFromStylesheetPI(Document& xmlDocument, nsAString& href);
|
||||
|
||||
/**
|
||||
* Parses the contents of data, returns the type and href psuedo attributes
|
||||
*/
|
||||
static void parseStylesheetPI(String& data,
|
||||
String& type,
|
||||
String& href);
|
||||
static void parseStylesheetPI(const nsAFlatString& data,
|
||||
nsAString& type,
|
||||
nsAString& href);
|
||||
|
||||
/**
|
||||
* Create a Document from a path.
|
||||
|
@ -156,7 +157,7 @@ protected:
|
|||
* @param aErr ErrorObserver
|
||||
* @result Document XML Document, or null on error
|
||||
*/
|
||||
static Document* parsePath(const String& aPath, ErrorObserver& aErr);
|
||||
static Document* parsePath(const nsACString& aPath, ErrorObserver& aErr);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,14 +27,14 @@ SystemPropertyFunctionCall::SystemPropertyFunctionCall(Node* aQNameResolveNode)
|
|||
**/
|
||||
ExprResult* SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext)
|
||||
{
|
||||
ExprResult* result = NULL;
|
||||
ExprResult* result = nsnull;
|
||||
|
||||
if (requireParams(1, 1, aContext)) {
|
||||
txListIterator iter(¶ms);
|
||||
Expr* param = (Expr*)iter.next();
|
||||
ExprResult* exprResult = param->evaluate(aContext);
|
||||
if (exprResult->getResultType() == ExprResult::STRING) {
|
||||
String property;
|
||||
nsAutoString property;
|
||||
exprResult->stringValue(property);
|
||||
txExpandedName qname;
|
||||
nsresult rv = qname.init(property, mQNameResolveNode, MB_TRUE);
|
||||
|
@ -52,7 +52,7 @@ ExprResult* SystemPropertyFunctionCall::evaluate(txIEvalContext* aContext)
|
|||
}
|
||||
}
|
||||
else {
|
||||
String err(NS_LITERAL_STRING("Invalid argument passed to system-property(), expecting String"));
|
||||
NS_NAMED_LITERAL_STRING(err, "Invalid argument passed to system-property(), expecting String");
|
||||
aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
|
||||
result = new StringResult(err);
|
||||
}
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txTextHandler.h"
|
||||
#include "TxString.h"
|
||||
#include "nsAString.h"
|
||||
|
||||
txTextHandler::txTextHandler(String& aValue, MBool aOnlyText) : mLevel(0),
|
||||
mValue(aValue),
|
||||
mOnlyText(aOnlyText)
|
||||
txTextHandler::txTextHandler(nsAString& aValue, MBool aOnlyText) : mLevel(0),
|
||||
mValue(aValue),
|
||||
mOnlyText(aOnlyText)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,19 +49,19 @@ txTextHandler::~txTextHandler()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextHandler::attribute(const String& aName,
|
||||
void txTextHandler::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
}
|
||||
|
||||
void txTextHandler::characters(const String& aData)
|
||||
void txTextHandler::characters(const nsAString& aData)
|
||||
{
|
||||
if (mLevel == 0)
|
||||
mValue.Append(aData);
|
||||
}
|
||||
|
||||
void txTextHandler::comment(const String& aData)
|
||||
void txTextHandler::comment(const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -69,15 +69,15 @@ void txTextHandler::endDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextHandler::endElement(const String& aName,
|
||||
void txTextHandler::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
if (mOnlyText)
|
||||
--mLevel;
|
||||
}
|
||||
|
||||
void txTextHandler::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txTextHandler::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ void txTextHandler::startDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextHandler::startElement(const String& aName,
|
||||
void txTextHandler::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
if (mOnlyText)
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
class txTextHandler : public txXMLEventHandler
|
||||
{
|
||||
public:
|
||||
txTextHandler(String& aValue, MBool aOnlyText);
|
||||
txTextHandler(nsAString& aValue, MBool aOnlyText);
|
||||
virtual ~txTextHandler();
|
||||
|
||||
/**
|
||||
|
@ -54,23 +54,23 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/**
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -93,8 +93,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/**
|
||||
* Signals the start of a document.
|
||||
|
@ -107,12 +107,12 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
private:
|
||||
PRUint32 mLevel;
|
||||
String& mValue;
|
||||
nsAString& mValue;
|
||||
MBool mOnlyText;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txTextOutput.h"
|
||||
#include "TxString.h"
|
||||
|
||||
txTextOutput::txTextOutput(ostream* aOut)
|
||||
: mOut(aOut)
|
||||
|
@ -48,23 +47,23 @@ txTextOutput::~txTextOutput()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextOutput::attribute(const String& aName,
|
||||
void txTextOutput::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
}
|
||||
|
||||
void txTextOutput::characters(const String& aData)
|
||||
void txTextOutput::characters(const nsAString& aData)
|
||||
{
|
||||
*mOut << aData;
|
||||
*mOut << NS_ConvertUCS2toUTF8(aData).get();
|
||||
}
|
||||
|
||||
void txTextOutput::charactersNoOutputEscaping(const String& aData)
|
||||
void txTextOutput::charactersNoOutputEscaping(const nsAString& aData)
|
||||
{
|
||||
characters(aData);
|
||||
}
|
||||
|
||||
void txTextOutput::comment(const String& aData)
|
||||
void txTextOutput::comment(const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -72,13 +71,13 @@ void txTextOutput::endDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextOutput::endElement(const String& aName,
|
||||
void txTextOutput::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
}
|
||||
|
||||
void txTextOutput::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txTextOutput::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -86,7 +85,7 @@ void txTextOutput::startDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txTextOutput::startElement(const String& aName,
|
||||
void txTextOutput::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -55,30 +55,30 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/*
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive characters that don't need output escaping.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
virtual void charactersNoOutputEscaping(const String& aData);
|
||||
virtual void charactersNoOutputEscaping(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -113,8 +113,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the start of a document.
|
||||
|
@ -127,7 +127,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
private:
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "txUnknownHandler.h"
|
||||
#include <string.h>
|
||||
#include "ProcessorState.h"
|
||||
#include "txStringUtils.h"
|
||||
|
||||
#ifndef TX_EXE
|
||||
NS_IMPL_ISUPPORTS1(txUnknownHandler, txIOutputXMLEventHandler);
|
||||
|
@ -62,16 +62,16 @@ txUnknownHandler::~txUnknownHandler()
|
|||
delete [] mArray;
|
||||
}
|
||||
|
||||
void txUnknownHandler::attribute(const String& aName,
|
||||
void txUnknownHandler::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
// If this is called then the stylesheet is trying to add an attribute
|
||||
// without adding an element first. So we'll just ignore it.
|
||||
// XXX ErrorReport: Signal this?
|
||||
}
|
||||
|
||||
void txUnknownHandler::characters(const String& aData)
|
||||
void txUnknownHandler::characters(const nsAString& aData)
|
||||
{
|
||||
txOneStringTransaction* transaction =
|
||||
new txOneStringTransaction(txOutputTransaction::eCharacterTransaction,
|
||||
|
@ -83,7 +83,7 @@ void txUnknownHandler::characters(const String& aData)
|
|||
addTransaction(transaction);
|
||||
}
|
||||
|
||||
void txUnknownHandler::charactersNoOutputEscaping(const String& aData)
|
||||
void txUnknownHandler::charactersNoOutputEscaping(const nsAString& aData)
|
||||
{
|
||||
txOneStringTransaction* transaction =
|
||||
new txOneStringTransaction(txOutputTransaction::eCharacterNoOETransaction,
|
||||
|
@ -95,7 +95,7 @@ void txUnknownHandler::charactersNoOutputEscaping(const String& aData)
|
|||
addTransaction(transaction);
|
||||
}
|
||||
|
||||
void txUnknownHandler::comment(const String& aData)
|
||||
void txUnknownHandler::comment(const nsAString& aData)
|
||||
{
|
||||
txOneStringTransaction* transaction =
|
||||
new txOneStringTransaction(txOutputTransaction::eCommentTransaction,
|
||||
|
@ -118,7 +118,7 @@ void txUnknownHandler::endDocument()
|
|||
// we set a new outputhandler
|
||||
nsCOMPtr<txIOutputXMLEventHandler> kungFuDeathGrip(this);
|
||||
#endif
|
||||
nsresult rv = createHandlerAndFlush(eXMLOutput, String(),
|
||||
nsresult rv = createHandlerAndFlush(eXMLOutput, nsString(),
|
||||
kNameSpaceID_None);
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
@ -131,14 +131,14 @@ void txUnknownHandler::endDocument()
|
|||
#endif
|
||||
}
|
||||
|
||||
void txUnknownHandler::endElement(const String& aName,
|
||||
void txUnknownHandler::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
NS_ASSERTION(0, "This shouldn't be called");
|
||||
}
|
||||
|
||||
void txUnknownHandler::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txUnknownHandler::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
txTwoStringTransaction* transaction =
|
||||
new txTwoStringTransaction(txOutputTransaction::ePITransaction,
|
||||
|
@ -161,7 +161,7 @@ void txUnknownHandler::startDocument()
|
|||
addTransaction(transaction);
|
||||
}
|
||||
|
||||
void txUnknownHandler::startElement(const String& aName,
|
||||
void txUnknownHandler::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
#ifndef TX_EXE
|
||||
|
@ -176,7 +176,7 @@ void txUnknownHandler::startElement(const String& aName,
|
|||
rv = createHandlerAndFlush(format->mMethod, aName, aNsID);
|
||||
}
|
||||
else if (aNsID == kNameSpaceID_None &&
|
||||
aName.isEqualIgnoreCase(String(NS_LITERAL_STRING("html")))) {
|
||||
aName.Equals(NS_LITERAL_STRING("html"), txCaseInsensitiveStringComparator())) {
|
||||
rv = createHandlerAndFlush(eHTMLOutput, aName, aNsID);
|
||||
}
|
||||
else {
|
||||
|
@ -201,7 +201,7 @@ void txUnknownHandler::getOutputDocument(nsIDOMDocument** aDocument)
|
|||
#endif
|
||||
|
||||
nsresult txUnknownHandler::createHandlerAndFlush(txOutputMethod aMethod,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#define TRANSFRMX_UNKNOWN_HANDLER_H
|
||||
|
||||
#include "txXMLEventHandler.h"
|
||||
#include "TxString.h"
|
||||
#include "txOutputFormat.h"
|
||||
|
||||
class ProcessorState;
|
||||
|
@ -69,27 +68,27 @@ class txOneStringTransaction : public txOutputTransaction
|
|||
{
|
||||
public:
|
||||
txOneStringTransaction(txTransactionType aType,
|
||||
String aString)
|
||||
const nsAString& aString)
|
||||
: txOutputTransaction(aType),
|
||||
mString(aString)
|
||||
{
|
||||
};
|
||||
String mString;
|
||||
nsString mString;
|
||||
};
|
||||
|
||||
class txTwoStringTransaction : public txOutputTransaction
|
||||
{
|
||||
public:
|
||||
txTwoStringTransaction(txTransactionType aType,
|
||||
String aStringOne,
|
||||
String aStringTwo)
|
||||
const nsAString& aStringOne,
|
||||
const nsAString& aStringTwo)
|
||||
: txOutputTransaction(aType),
|
||||
mStringOne(aStringOne),
|
||||
mStringTwo(aStringTwo)
|
||||
{
|
||||
};
|
||||
String mStringOne;
|
||||
String mStringTwo;
|
||||
nsString mStringOne;
|
||||
nsString mStringTwo;
|
||||
};
|
||||
|
||||
class txUnknownHandler : public txIOutputXMLEventHandler
|
||||
|
@ -109,30 +108,30 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
void attribute(const String& aName,
|
||||
void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/*
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void characters(const String& aData);
|
||||
void characters(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive characters that don't need output escaping.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
void charactersNoOutputEscaping(const String& aData);
|
||||
void charactersNoOutputEscaping(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -146,7 +145,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void endElement(const String& aName,
|
||||
void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -167,8 +166,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the start of a document.
|
||||
|
@ -181,7 +180,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
void startElement(const String& aName,
|
||||
void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
#ifndef TX_EXE
|
||||
|
@ -195,7 +194,7 @@ public:
|
|||
|
||||
private:
|
||||
nsresult createHandlerAndFlush(txOutputMethod aMethod,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
void addTransaction(txOutputTransaction* aTransaction);
|
||||
|
||||
|
|
|
@ -26,8 +26,10 @@
|
|||
|
||||
#include "baseutils.h"
|
||||
#include "txError.h"
|
||||
class String;
|
||||
|
||||
class nsAString;
|
||||
class txOutputFormat;
|
||||
|
||||
#ifdef TX_EXE
|
||||
#include <iostream.h>
|
||||
#else
|
||||
|
@ -58,23 +60,23 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
virtual void attribute(const String& aName,
|
||||
virtual void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue) = 0;
|
||||
const nsAString& aValue) = 0;
|
||||
|
||||
/**
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
virtual void characters(const String& aData) = 0;
|
||||
virtual void characters(const nsAString& aData) = 0;
|
||||
|
||||
/**
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
virtual void comment(const String& aData) = 0;
|
||||
virtual void comment(const nsAString& aData) = 0;
|
||||
|
||||
/**
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -88,7 +90,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
virtual void endElement(const String& aName,
|
||||
virtual void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID) = 0;
|
||||
|
||||
/**
|
||||
|
@ -97,8 +99,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
virtual void processingInstruction(const String& aTarget,
|
||||
const String& aData) = 0;
|
||||
virtual void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData) = 0;
|
||||
|
||||
/**
|
||||
* Signals the start of a document.
|
||||
|
@ -111,7 +113,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
virtual void startElement(const String& aName,
|
||||
virtual void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID) = 0;
|
||||
};
|
||||
|
||||
|
@ -132,7 +134,7 @@ public:
|
|||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
virtual void charactersNoOutputEscaping(const String& aData) = 0;
|
||||
virtual void charactersNoOutputEscaping(const nsAString& aData) = 0;
|
||||
|
||||
/**
|
||||
* Returns whether the output handler supports
|
||||
|
@ -182,7 +184,7 @@ public:
|
|||
*/
|
||||
virtual nsresult
|
||||
createHandlerWith(txOutputFormat* aFormat,
|
||||
const String& aName,
|
||||
const nsAString& aName,
|
||||
PRInt32 aNsID,
|
||||
txIOutputXMLEventHandler** aHandler) = 0;
|
||||
};
|
||||
|
@ -191,7 +193,7 @@ public:
|
|||
nsresult createHandlerWith(txOutputFormat* aFormat, \
|
||||
txIOutputXMLEventHandler** aHandler); \
|
||||
nsresult createHandlerWith(txOutputFormat* aFormat, \
|
||||
const String& aName, \
|
||||
const nsAString& aName, \
|
||||
PRInt32 aNsID, \
|
||||
txIOutputXMLEventHandler** aHandler) \
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
|
||||
const int txXMLOutput::DEFAULT_INDENT = 2;
|
||||
|
||||
txAttribute::txAttribute(PRInt32 aNsID, txAtom* aLocalName, const String& aValue) :
|
||||
txAttribute::txAttribute(PRInt32 aNsID, txAtom* aLocalName,
|
||||
const nsAString& aValue) :
|
||||
mName(aNsID, aLocalName),
|
||||
mValue(aValue),
|
||||
mShorthand(MB_FALSE)
|
||||
|
@ -64,18 +65,17 @@ txXMLOutput::~txXMLOutput()
|
|||
{
|
||||
}
|
||||
|
||||
void txXMLOutput::attribute(const String& aName,
|
||||
void txXMLOutput::attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue)
|
||||
const nsAString& aValue)
|
||||
{
|
||||
if (!mStartTagOpen)
|
||||
// XXX Signal this? (can't add attributes after element closed)
|
||||
return;
|
||||
|
||||
txListIterator iter(&mAttributes);
|
||||
String localPart;
|
||||
XMLUtils::getLocalPart(aName, localPart);
|
||||
txAtom* localName = TX_GET_ATOM(localPart);
|
||||
nsCOMPtr<nsIAtom> localName;
|
||||
XMLUtils::getLocalPart(aName, getter_AddRefs(localName));
|
||||
txExpandedName att(aNsID, localName);
|
||||
|
||||
txAttribute* setAtt = 0;
|
||||
|
@ -89,16 +89,13 @@ void txXMLOutput::attribute(const String& aName,
|
|||
setAtt = new txAttribute(aNsID, localName, aValue);
|
||||
mAttributes.add(setAtt);
|
||||
}
|
||||
TX_IF_RELEASE_ATOM(localName);
|
||||
}
|
||||
|
||||
void txXMLOutput::characters(const String& aData)
|
||||
void txXMLOutput::characters(const nsAString& aData)
|
||||
{
|
||||
closeStartTag(MB_FALSE);
|
||||
|
||||
if (mInCDATASection) {
|
||||
PRUint32 i = 0;
|
||||
PRUint32 j = 0;
|
||||
PRUint32 length = aData.Length();
|
||||
|
||||
*mOut << CDATA_START;
|
||||
|
@ -107,12 +104,17 @@ void txXMLOutput::characters(const String& aData)
|
|||
printUTF8Chars(aData);
|
||||
}
|
||||
else {
|
||||
mBuffer[j++] = aData.CharAt(i++);
|
||||
mBuffer[j++] = aData.CharAt(i++);
|
||||
mBuffer[j++] = aData.CharAt(i++);
|
||||
PRUint32 j = 0;
|
||||
nsAString::const_iterator iter;
|
||||
aData.BeginReading(iter);
|
||||
mBuffer[j++] = *(iter++);
|
||||
mBuffer[j++] = *(iter++);
|
||||
mBuffer[j++] = *(iter++);
|
||||
|
||||
while (i < length) {
|
||||
mBuffer[j++] = aData.CharAt(i++);
|
||||
nsAString::const_iterator end;
|
||||
aData.EndReading(end);
|
||||
while (iter != end) {
|
||||
mBuffer[j++] = *(iter++);
|
||||
if (mBuffer[(j - 1) % 4] == ']' &&
|
||||
mBuffer[j % 4] == ']' &&
|
||||
mBuffer[(j + 1) % 4] == '>') {
|
||||
|
@ -138,20 +140,17 @@ void txXMLOutput::characters(const String& aData)
|
|||
}
|
||||
}
|
||||
|
||||
void txXMLOutput::charactersNoOutputEscaping(const String& aData)
|
||||
void txXMLOutput::charactersNoOutputEscaping(const nsAString& aData)
|
||||
{
|
||||
closeStartTag(MB_FALSE);
|
||||
|
||||
printUTF8Chars(aData);
|
||||
}
|
||||
|
||||
void txXMLOutput::comment(const String& aData)
|
||||
void txXMLOutput::comment(const nsAString& aData)
|
||||
{
|
||||
closeStartTag(MB_FALSE);
|
||||
|
||||
if (&aData == &NULL_STRING)
|
||||
return;
|
||||
|
||||
if (mOutputFormat.mIndent == eTrue) {
|
||||
for (PRUint32 i = 0; i < mIndentLevel; i++)
|
||||
*mOut << ' ';
|
||||
|
@ -167,7 +166,7 @@ void txXMLOutput::endDocument()
|
|||
{
|
||||
}
|
||||
|
||||
void txXMLOutput::endElement(const String& aName,
|
||||
void txXMLOutput::endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
MBool newLine = (mOutputFormat.mIndent == eTrue) && mAfterEndTag;
|
||||
|
@ -183,7 +182,7 @@ void txXMLOutput::endElement(const String& aName,
|
|||
*mOut << ' ';
|
||||
}
|
||||
*mOut << L_ANGLE_BRACKET << FORWARD_SLASH;
|
||||
*mOut << aName;
|
||||
printUTF8Chars(aName);
|
||||
*mOut << R_ANGLE_BRACKET;
|
||||
}
|
||||
if (mOutputFormat.mIndent == eTrue)
|
||||
|
@ -192,15 +191,19 @@ void txXMLOutput::endElement(const String& aName,
|
|||
mInCDATASection = (MBool)mCDATASections.pop();
|
||||
}
|
||||
|
||||
void txXMLOutput::processingInstruction(const String& aTarget,
|
||||
const String& aData)
|
||||
void txXMLOutput::processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData)
|
||||
{
|
||||
closeStartTag(MB_FALSE);
|
||||
if (mOutputFormat.mIndent == eTrue) {
|
||||
for (PRUint32 i = 0; i < mIndentLevel; i++)
|
||||
*mOut << ' ';
|
||||
}
|
||||
*mOut << PI_START << aTarget << SPACE << aData << PI_END;
|
||||
*mOut << PI_START;
|
||||
printUTF8Chars(aTarget);
|
||||
*mOut << SPACE;
|
||||
printUTF8Chars(aData);
|
||||
*mOut << PI_END;
|
||||
if (mOutputFormat.mIndent == eTrue)
|
||||
*mOut << endl;
|
||||
}
|
||||
|
@ -216,7 +219,7 @@ void txXMLOutput::startDocument()
|
|||
*mOut << DOUBLE_QUOTE << PI_END << endl;
|
||||
}
|
||||
|
||||
void txXMLOutput::startElement(const String& aName,
|
||||
void txXMLOutput::startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID)
|
||||
{
|
||||
if (!mHaveDocumentElement) {
|
||||
|
@ -235,7 +238,7 @@ void txXMLOutput::startElement(const String& aName,
|
|||
}
|
||||
}
|
||||
*mOut << L_ANGLE_BRACKET;
|
||||
*mOut << aName;
|
||||
printUTF8Chars(aName);
|
||||
mStartTagOpen = MB_TRUE;
|
||||
if (mOutputFormat.mIndent == eTrue)
|
||||
mIndentLevel += DEFAULT_INDENT;
|
||||
|
@ -303,28 +306,19 @@ void txXMLOutput::printUTF8Char(PRUnichar& ch)
|
|||
}
|
||||
}
|
||||
|
||||
void txXMLOutput::printUTF8Chars(const String& aData)
|
||||
void txXMLOutput::printUTF8Chars(const nsAString& aData)
|
||||
{
|
||||
PRUnichar currChar;
|
||||
PRUint32 i = 0;
|
||||
|
||||
while (i < aData.Length()) {
|
||||
currChar = aData.CharAt(i++);
|
||||
printUTF8Char(currChar);
|
||||
}
|
||||
*mOut << NS_ConvertUCS2toUTF8(aData).get();
|
||||
}
|
||||
|
||||
void txXMLOutput::printWithXMLEntities(const String& aData,
|
||||
void txXMLOutput::printWithXMLEntities(const nsAString& aData,
|
||||
MBool aAttribute)
|
||||
{
|
||||
PRUnichar currChar;
|
||||
PRUint32 i;
|
||||
nsAString::const_iterator iter, end;
|
||||
aData.EndReading(end);
|
||||
|
||||
if (&aData == &NULL_STRING)
|
||||
return;
|
||||
|
||||
for (i = 0; i < aData.Length(); i++) {
|
||||
currChar = aData.CharAt(i);
|
||||
for (aData.BeginReading(iter); iter != end; ++iter) {
|
||||
PRUnichar currChar = *iter;
|
||||
switch (currChar) {
|
||||
case AMPERSAND:
|
||||
*mOut << AMP_ENTITY;
|
||||
|
|
|
@ -85,9 +85,9 @@
|
|||
|
||||
class txAttribute {
|
||||
public:
|
||||
txAttribute(PRInt32 aNsID, txAtom* aLocalName, const String& aValue);
|
||||
txAttribute(PRInt32 aNsID, txAtom* aLocalName, const nsAString& aValue);
|
||||
txExpandedName mName;
|
||||
String mValue;
|
||||
nsString mValue;
|
||||
MBool mShorthand;
|
||||
};
|
||||
|
||||
|
@ -106,30 +106,30 @@ public:
|
|||
* @param aNsID the namespace ID of the attribute
|
||||
* @param aValue the value of the attribute
|
||||
*/
|
||||
virtual void attribute(const String& aName,
|
||||
virtual void attribute(const nsAString& aName,
|
||||
const PRInt32 aNsID,
|
||||
const String& aValue);
|
||||
const nsAString& aValue);
|
||||
|
||||
/*
|
||||
* Signals to receive characters.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
virtual void characters(const String& aData);
|
||||
virtual void characters(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive characters that don't need output escaping.
|
||||
*
|
||||
* @param aData the characters to receive
|
||||
*/
|
||||
virtual void charactersNoOutputEscaping(const String& aData);
|
||||
virtual void charactersNoOutputEscaping(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals to receive data that should be treated as a comment.
|
||||
*
|
||||
* @param data the comment data to receive
|
||||
*/
|
||||
void comment(const String& aData);
|
||||
void comment(const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the end of a document. It is an error to call
|
||||
|
@ -143,7 +143,7 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
virtual void endElement(const String& aName,
|
||||
virtual void endElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
/**
|
||||
|
@ -164,8 +164,8 @@ public:
|
|||
* @param aTarget the target of the processing instruction
|
||||
* @param aData the data of the processing instruction
|
||||
*/
|
||||
virtual void processingInstruction(const String& aTarget,
|
||||
const String& aData);
|
||||
virtual void processingInstruction(const nsAString& aTarget,
|
||||
const nsAString& aData);
|
||||
|
||||
/*
|
||||
* Signals the start of a document.
|
||||
|
@ -178,14 +178,15 @@ public:
|
|||
* @param aName the name of the element
|
||||
* @param aNsID the namespace ID of the element
|
||||
*/
|
||||
virtual void startElement(const String& aName,
|
||||
virtual void startElement(const nsAString& aName,
|
||||
const PRInt32 aNsID);
|
||||
|
||||
protected:
|
||||
virtual void closeStartTag(MBool aUseEmptyElementShorthand);
|
||||
void printUTF8Char(PRUnichar& ch);
|
||||
void printUTF8Chars(const String& aData);
|
||||
void printWithXMLEntities(const String& aData, MBool aAttribute = MB_FALSE);
|
||||
void printUTF8Chars(const nsAString& aData);
|
||||
void printWithXMLEntities(const nsAString& aData,
|
||||
MBool aAttribute = MB_FALSE);
|
||||
|
||||
ostream* mOut;
|
||||
txOutputFormat mOutputFormat;
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
#include "prmem.h"
|
||||
|
||||
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
|
||||
#else
|
||||
#include "txStringUtils.h"
|
||||
#endif
|
||||
|
||||
#define kAscending (1<<0)
|
||||
|
@ -57,7 +59,7 @@ static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
|
|||
|
||||
txResultStringComparator::txResultStringComparator(MBool aAscending,
|
||||
MBool aUpperFirst,
|
||||
const String& aLanguage)
|
||||
const nsAFlatString& aLanguage)
|
||||
{
|
||||
mSorting = 0;
|
||||
if (aAscending)
|
||||
|
@ -76,7 +78,7 @@ txResultStringComparator::~txResultStringComparator()
|
|||
}
|
||||
|
||||
#ifndef TX_EXE
|
||||
nsresult txResultStringComparator::init(const String& aLanguage)
|
||||
nsresult txResultStringComparator::init(const nsAFlatString& aLanguage)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -85,7 +87,7 @@ nsresult txResultStringComparator::init(const String& aLanguage)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsILocale> locale;
|
||||
rv = localeService->NewLocale(aLanguage.getConstNSString().get(),
|
||||
rv = localeService->NewLocale(aLanguage.get(),
|
||||
getter_AddRefs(locale));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -110,19 +112,19 @@ TxObject* txResultStringComparator::createSortableValue(ExprResult* aExprRes)
|
|||
#ifdef TX_EXE
|
||||
aExprRes->stringValue(val->mStr);
|
||||
// We don't support case-order on standalone
|
||||
val->mStr.toLowerCase();
|
||||
TX_ToLowerCase(val->mStr);
|
||||
#else
|
||||
if (!mCollation)
|
||||
return 0;
|
||||
|
||||
val->mCaseKey = new String;
|
||||
val->mCaseKey = new nsString;
|
||||
if (!val->mCaseKey) {
|
||||
delete val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
aExprRes->stringValue(*(String *)val->mCaseKey);
|
||||
const nsString& nsCaseKey = ((String *)val->mCaseKey)->getConstNSString();
|
||||
nsString& nsCaseKey = *(nsString *)val->mCaseKey;
|
||||
aExprRes->stringValue(nsCaseKey);
|
||||
if (nsCaseKey.IsEmpty()) {
|
||||
return val;
|
||||
}
|
||||
|
@ -190,9 +192,9 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
|
|||
return ((mSorting & kAscending) ? 1 : -1) * result;
|
||||
|
||||
if ((strval1->mCaseLength == 0) && (strval1->mLength != 0)) {
|
||||
String* caseString = (String *)strval1->mCaseKey;
|
||||
nsString* caseString = (nsString *)strval1->mCaseKey;
|
||||
rv = createRawSortKey(kCollationCaseSensitive,
|
||||
caseString->getConstNSString(),
|
||||
*caseString,
|
||||
(PRUint8**)&strval1->mCaseKey,
|
||||
&strval1->mCaseLength);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -204,9 +206,9 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
|
|||
delete caseString;
|
||||
}
|
||||
if ((strval2->mCaseLength == 0) && (strval2->mLength != 0)) {
|
||||
String* caseString = (String *)strval2->mCaseKey;
|
||||
nsString* caseString = (nsString *)strval2->mCaseKey;
|
||||
rv = createRawSortKey(kCollationCaseSensitive,
|
||||
caseString->getConstNSString(),
|
||||
*caseString,
|
||||
(PRUint8**)&strval2->mCaseKey,
|
||||
&strval2->mCaseLength);
|
||||
if (NS_FAILED(rv)) {
|
||||
|
@ -225,7 +227,8 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
|
|||
return -1;
|
||||
}
|
||||
|
||||
return ((mSorting & kAscending) ? 1 : -1) * ((mSorting & kUpperFirst) ? 1 : -1) * result;
|
||||
return ((mSorting & kAscending) ? 1 : -1) *
|
||||
((mSorting & kUpperFirst) ? 1 : -1) * result;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -258,7 +261,7 @@ txResultStringComparator::StringValue::~StringValue()
|
|||
if (mCaseLength > 0)
|
||||
PR_Free((PRUint8*)mCaseKey);
|
||||
else
|
||||
delete (String*)mCaseKey;
|
||||
delete (nsString*)mCaseKey;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -41,10 +41,11 @@
|
|||
#define TRANSFRMX_XPATHRESULTCOMPARATOR_H
|
||||
|
||||
#include "TxObject.h"
|
||||
#include "TxString.h"
|
||||
#ifndef TX_EXE
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICollation.h"
|
||||
#else
|
||||
#include "nsString.h"
|
||||
#endif
|
||||
|
||||
class ExprResult;
|
||||
|
@ -55,6 +56,10 @@ class ExprResult;
|
|||
class txXPathResultComparator
|
||||
{
|
||||
public:
|
||||
virtual ~txXPathResultComparator()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Compares two XPath results. Returns -1 if val1 < val2,
|
||||
* 1 if val1 > val2 and 0 if val1 == val2.
|
||||
|
@ -74,7 +79,7 @@ class txResultStringComparator : public txXPathResultComparator
|
|||
{
|
||||
public:
|
||||
txResultStringComparator(MBool aAscending, MBool aUpperFirst,
|
||||
const String& aLanguage);
|
||||
const nsAFlatString& aLanguage);
|
||||
virtual ~txResultStringComparator();
|
||||
|
||||
int compareValues(TxObject* aVal1, TxObject* aVal2);
|
||||
|
@ -82,7 +87,7 @@ public:
|
|||
private:
|
||||
#ifndef TX_EXE
|
||||
nsCOMPtr<nsICollation> mCollation;
|
||||
nsresult init(const String& aLanguage);
|
||||
nsresult init(const nsAFlatString& aLanguage);
|
||||
nsresult createRawSortKey(const nsCollationStrength aStrength,
|
||||
const nsString& aString,
|
||||
PRUint8** aKey,
|
||||
|
@ -94,7 +99,7 @@ private:
|
|||
{
|
||||
public:
|
||||
#ifdef TX_EXE
|
||||
String mStr;
|
||||
nsString mStr;
|
||||
#else
|
||||
StringValue();
|
||||
~StringValue();
|
||||
|
|
|
@ -133,5 +133,10 @@ TX_ATOM(vendorUrl, "vendor-url");
|
|||
|
||||
// XSLT attribute values
|
||||
TX_ATOM(any, "any");
|
||||
TX_ATOM(ascending, "ascending");
|
||||
TX_ATOM(descending, "descending");
|
||||
TX_ATOM(lowerFirst, "lower-first");
|
||||
TX_ATOM(multiple, "multiple");
|
||||
TX_ATOM(single, "single");
|
||||
TX_ATOM(upperFirst, "upper-first");
|
||||
TX_ATOM(yes, "yes");
|
||||
|
|
|
@ -97,7 +97,7 @@ public:
|
|||
* @return a NodeSet* containing all nodes in doc matching with value
|
||||
* keyValue
|
||||
*/
|
||||
const NodeSet* getNodes(String& aKeyValue, Document* aDoc);
|
||||
const NodeSet* getNodes(const nsAString& aKeyValue, Document* aDoc);
|
||||
|
||||
/*
|
||||
* Adds a match/use pair. Returns MB_FALSE if matchString or useString
|
||||
|
@ -211,9 +211,9 @@ public:
|
|||
|
||||
PRUnichar mDecimalSeparator;
|
||||
PRUnichar mGroupingSeparator;
|
||||
String mInfinity;
|
||||
nsString mInfinity;
|
||||
PRUnichar mMinusSign;
|
||||
String mNaN;
|
||||
nsString mNaN;
|
||||
PRUnichar mPercent;
|
||||
PRUnichar mPerMille;
|
||||
PRUnichar mZeroDigit;
|
||||
|
|
|
@ -40,24 +40,23 @@
|
|||
#include "txAtoms.h"
|
||||
#include "primitives.h"
|
||||
#include <math.h>
|
||||
#include "Names.h"
|
||||
|
||||
nsresult txXSLTNumber::createNumber(Element* aNumberElement,
|
||||
ProcessorState* aPs,
|
||||
String& aResult)
|
||||
nsAString& aResult)
|
||||
{
|
||||
aResult.Truncate();
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Parse format
|
||||
txList counters;
|
||||
String head, tail;
|
||||
nsAutoString head, tail;
|
||||
rv = getCounters(aNumberElement, aPs, counters, head, tail);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Create list of values to format
|
||||
txList values;
|
||||
String valueString;
|
||||
nsAutoString valueString;
|
||||
rv = getValueList(aNumberElement, aPs, values, valueString);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -102,7 +101,7 @@ nsresult txXSLTNumber::createNumber(Element* aNumberElement,
|
|||
|
||||
nsresult txXSLTNumber::getValueList(Element* aNumberElement,
|
||||
ProcessorState* aPs, txList& aValues,
|
||||
String& aValueString)
|
||||
nsAString& aValueString)
|
||||
{
|
||||
aValueString.Truncate();
|
||||
|
||||
|
@ -169,8 +168,11 @@ nsresult txXSLTNumber::getValueList(Element* aNumberElement,
|
|||
{
|
||||
txNodeTypeTest* typeTest;
|
||||
typeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE);
|
||||
if (typeTest)
|
||||
typeTest->setNodeName(currNode->getNodeName());
|
||||
if (typeTest) {
|
||||
nsAutoString nodeName;
|
||||
currNode->getNodeName(nodeName);
|
||||
typeTest->setNodeName(nodeName);
|
||||
}
|
||||
nodeTest = typeTest;
|
||||
break;
|
||||
}
|
||||
|
@ -215,7 +217,7 @@ nsresult txXSLTNumber::getValueList(Element* aNumberElement,
|
|||
|
||||
// Generate list of values depending on the value of the level-attribute
|
||||
|
||||
String levelStr;
|
||||
nsAutoString levelStr;
|
||||
txAtom* level = 0;
|
||||
if (aNumberElement->getAttr(txXSLTAtoms::level, kNameSpaceID_None, levelStr)) {
|
||||
level = TX_GET_ATOM(levelStr);
|
||||
|
@ -316,7 +318,7 @@ nsresult txXSLTNumber::getValueList(Element* aNumberElement,
|
|||
}
|
||||
}
|
||||
else {
|
||||
aPs->receiveError(String(NS_LITERAL_STRING("unknown value for format attribute")),
|
||||
aPs->receiveError(NS_LITERAL_STRING("unknown value for format attribute"),
|
||||
NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -331,14 +333,14 @@ nsresult txXSLTNumber::getValueList(Element* aNumberElement,
|
|||
|
||||
nsresult
|
||||
txXSLTNumber::getCounters(Element* aNumberElement, ProcessorState* aPs,
|
||||
txList& aCounters, String& aHead, String& aTail)
|
||||
txList& aCounters, nsAString& aHead, nsAString& aTail)
|
||||
{
|
||||
aHead.Truncate();
|
||||
aTail.Truncate();
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
String groupSizeStrAVT, groupSeparatorAVT, groupSizeStr, groupSeparator;
|
||||
nsAutoString groupSizeStrAVT, groupSeparatorAVT, groupSizeStr, groupSeparator;
|
||||
PRInt32 groupSize = 0;
|
||||
if (aNumberElement->getAttr(txXSLTAtoms::groupingSeparator,
|
||||
kNameSpaceID_None, groupSeparatorAVT) &&
|
||||
|
@ -355,7 +357,7 @@ txXSLTNumber::getCounters(Element* aNumberElement, ProcessorState* aPs,
|
|||
}
|
||||
}
|
||||
|
||||
String formatAVT, format;
|
||||
nsAutoString formatAVT, format;
|
||||
if (aNumberElement->getAttr(txXSLTAtoms::format, kNameSpaceID_None,
|
||||
formatAVT)) {
|
||||
aPs->processAttrValueTemplate(formatAVT, aNumberElement, format);
|
||||
|
@ -374,11 +376,11 @@ txXSLTNumber::getCounters(Element* aNumberElement, ProcessorState* aPs,
|
|||
// If there are no formatting tokens we need to create a default one.
|
||||
if (formatPos == formatLen) {
|
||||
txFormattedCounter* defaultCounter;
|
||||
rv = txFormattedCounter::getCounterFor(String(NS_LITERAL_STRING("1")), groupSize,
|
||||
rv = txFormattedCounter::getCounterFor(NS_LITERAL_STRING("1"), groupSize,
|
||||
groupSeparator, defaultCounter);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
defaultCounter->mSeparator = String(NS_LITERAL_STRING("."));
|
||||
defaultCounter->mSeparator = NS_LITERAL_STRING(".");
|
||||
rv = aCounters.add(defaultCounter);
|
||||
if (NS_FAILED(rv)) {
|
||||
// XXX ErrorReport: out of memory
|
||||
|
@ -390,14 +392,14 @@ txXSLTNumber::getCounters(Element* aNumberElement, ProcessorState* aPs,
|
|||
}
|
||||
|
||||
while (formatPos < formatLen) {
|
||||
String sepToken;
|
||||
nsAutoString sepToken;
|
||||
// parse separator token
|
||||
if (!aCounters.getLength()) {
|
||||
// Set the first counters separator to default value so that if
|
||||
// there is only one formatting token and we're formatting a
|
||||
// value-list longer then one we use the default separator. This
|
||||
// won't be used when formatting the first value anyway.
|
||||
sepToken = String(NS_LITERAL_STRING("."));
|
||||
sepToken = NS_LITERAL_STRING(".");
|
||||
}
|
||||
else {
|
||||
while (formatPos < formatLen &&
|
||||
|
@ -414,7 +416,7 @@ txXSLTNumber::getCounters(Element* aNumberElement, ProcessorState* aPs,
|
|||
}
|
||||
|
||||
// parse formatting token
|
||||
String numToken;
|
||||
nsAutoString numToken;
|
||||
while (formatPos < formatLen &&
|
||||
isAlphaNumeric(ch = format.CharAt(formatPos))) {
|
||||
numToken.Append(ch);
|
||||
|
|
|
@ -46,14 +46,14 @@ class txXSLTNumber {
|
|||
|
||||
public:
|
||||
static nsresult createNumber(Element* aNumberElement, ProcessorState* aPs,
|
||||
String& aResult);
|
||||
nsAString& aResult);
|
||||
private:
|
||||
static nsresult getValueList(Element* aNumberElement, ProcessorState* aPs,
|
||||
txList& aValues, String& aValueString);
|
||||
txList& aValues, nsAString& aValueString);
|
||||
|
||||
static nsresult getCounters(Element* aNumberElement, ProcessorState* aPs,
|
||||
txList& aCounters,
|
||||
String& aHead, String& aTail);
|
||||
nsAString& aHead, nsAString& aTail);
|
||||
|
||||
static PRInt32 getSiblingCount(Node* aNode, txPattern* aCountPattern,
|
||||
txIMatchContext* aContext);
|
||||
|
@ -69,13 +69,13 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void appendNumber(PRInt32 aNumber, String& aDest) = 0;
|
||||
virtual void appendNumber(PRInt32 aNumber, nsAString& aDest) = 0;
|
||||
|
||||
static nsresult getCounterFor(const String& aToken, int aGroupSize,
|
||||
const String& aGroupSeparator,
|
||||
static nsresult getCounterFor(const nsAFlatString& aToken, int aGroupSize,
|
||||
const nsAString& aGroupSeparator,
|
||||
txFormattedCounter*& aCounter);
|
||||
|
||||
String mSeparator;
|
||||
nsString mSeparator;
|
||||
};
|
||||
|
||||
#endif //TRANSFRMX_TXXSLTNUMBER_H
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
#include "txXSLTNumber.h"
|
||||
#include "primitives.h"
|
||||
#include "Names.h"
|
||||
|
||||
class txDecimalCounter : public txFormattedCounter {
|
||||
public:
|
||||
|
@ -47,14 +46,14 @@ public:
|
|||
}
|
||||
|
||||
txDecimalCounter(PRInt32 aMinLength, PRInt32 aGroupSize,
|
||||
const String& mGroupSeparator);
|
||||
const nsAString& mGroupSeparator);
|
||||
|
||||
virtual void appendNumber(PRInt32 aNumber, String& aDest);
|
||||
virtual void appendNumber(PRInt32 aNumber, nsAString& aDest);
|
||||
|
||||
private:
|
||||
PRInt32 mMinLength;
|
||||
PRInt32 mGroupSize;
|
||||
String mGroupSeparator;
|
||||
nsString mGroupSeparator;
|
||||
};
|
||||
|
||||
class txAlphaCounter : public txFormattedCounter {
|
||||
|
@ -63,7 +62,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void appendNumber(PRInt32 aNumber, String& aDest);
|
||||
virtual void appendNumber(PRInt32 aNumber, nsAString& aDest);
|
||||
|
||||
private:
|
||||
PRUnichar mOffset;
|
||||
|
@ -75,7 +74,7 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
void appendNumber(PRInt32 aNumber, String& aDest);
|
||||
void appendNumber(PRInt32 aNumber, nsAString& aDest);
|
||||
|
||||
private:
|
||||
PRInt32 mTableOffset;
|
||||
|
@ -83,8 +82,9 @@ private:
|
|||
|
||||
|
||||
nsresult
|
||||
txFormattedCounter::getCounterFor(const String& aToken, PRInt32 aGroupSize,
|
||||
const String& aGroupSeparator,
|
||||
txFormattedCounter::getCounterFor(const nsAFlatString& aToken,
|
||||
PRInt32 aGroupSize,
|
||||
const nsAString& aGroupSeparator,
|
||||
txFormattedCounter*& aCounter)
|
||||
{
|
||||
PRInt32 length = aToken.Length();
|
||||
|
@ -108,7 +108,8 @@ txFormattedCounter::getCounterFor(const String& aToken, PRInt32 aGroupSize,
|
|||
case '1':
|
||||
default:
|
||||
// if we don't recognize the token then use "1"
|
||||
aCounter = new txDecimalCounter(1, aGroupSize, aGroupSeparator);
|
||||
aCounter = new txDecimalCounter(1, aGroupSize,
|
||||
aGroupSeparator);
|
||||
break;
|
||||
}
|
||||
return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -133,7 +134,7 @@ txFormattedCounter::getCounterFor(const String& aToken, PRInt32 aGroupSize,
|
|||
|
||||
|
||||
txDecimalCounter::txDecimalCounter(PRInt32 aMinLength, PRInt32 aGroupSize,
|
||||
const String& aGroupSeparator)
|
||||
const nsAString& aGroupSeparator)
|
||||
: mMinLength(aMinLength), mGroupSize(aGroupSize),
|
||||
mGroupSeparator(aGroupSeparator)
|
||||
{
|
||||
|
@ -142,7 +143,7 @@ txDecimalCounter::txDecimalCounter(PRInt32 aMinLength, PRInt32 aGroupSize,
|
|||
}
|
||||
}
|
||||
|
||||
void txDecimalCounter::appendNumber(PRInt32 aNumber, String& aDest)
|
||||
void txDecimalCounter::appendNumber(PRInt32 aNumber, nsAString& aDest)
|
||||
{
|
||||
const PRInt32 bufsize = 10; //must be able to fit an PRInt32
|
||||
PRUnichar buf[bufsize];
|
||||
|
@ -192,7 +193,7 @@ void txDecimalCounter::appendNumber(PRInt32 aNumber, String& aDest)
|
|||
}
|
||||
|
||||
|
||||
void txAlphaCounter::appendNumber(PRInt32 aNumber, String& aDest)
|
||||
void txAlphaCounter::appendNumber(PRInt32 aNumber, nsAString& aDest)
|
||||
{
|
||||
PRUnichar buf[11];
|
||||
buf[11] = 0;
|
||||
|
@ -216,7 +217,7 @@ const char* kTxRomanNumbers[] =
|
|||
"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC",
|
||||
"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
|
||||
|
||||
void txRomanCounter::appendNumber(PRInt32 aNumber, String& aDest)
|
||||
void txRomanCounter::appendNumber(PRInt32 aNumber, nsAString& aDest)
|
||||
{
|
||||
// Numbers bigger then 3999 can't be done in roman
|
||||
if (aNumber >= 4000) {
|
||||
|
|
|
@ -135,7 +135,7 @@ nsresult txUnionPattern::getSimplePatterns(txList& aList)
|
|||
* destination String, to allow cascading calls to other
|
||||
* toString() methods for mLocPathPatterns.
|
||||
*/
|
||||
void txUnionPattern::toString(String& aDest)
|
||||
void txUnionPattern::toString(nsAString& aDest)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
aDest.Append(NS_LITERAL_STRING("txUnionPattern{"));
|
||||
|
@ -255,7 +255,7 @@ double txLocPathPattern::getDefaultPriority()
|
|||
return ((Step*)mSteps.get(0))->pattern->getDefaultPriority();
|
||||
}
|
||||
|
||||
void txLocPathPattern::toString(String& aDest)
|
||||
void txLocPathPattern::toString(nsAString& aDest)
|
||||
{
|
||||
txListIterator iter(&mSteps);
|
||||
#ifdef DEBUG
|
||||
|
@ -298,7 +298,7 @@ double txRootPattern::getDefaultPriority()
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
void txRootPattern::toString(String& aDest)
|
||||
void txRootPattern::toString(nsAString& aDest)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
aDest.Append(NS_LITERAL_STRING("txRootPattern{"));
|
||||
|
@ -318,15 +318,14 @@ void txRootPattern::toString(String& aDest)
|
|||
* This looks like the id() function, but may only have LITERALs as
|
||||
* argument.
|
||||
*/
|
||||
txIdPattern::txIdPattern(const String& aString)
|
||||
txIdPattern::txIdPattern(const nsAString& aString)
|
||||
{
|
||||
#ifdef TX_EXE
|
||||
mIds = aString;
|
||||
#else
|
||||
const nsString& ids = aString.getConstNSString();
|
||||
nsAString::const_iterator pos, begin, end;
|
||||
ids.BeginReading(begin);
|
||||
ids.EndReading(end);
|
||||
aString.BeginReading(begin);
|
||||
aString.EndReading(end);
|
||||
pos = begin;
|
||||
while (pos != end) {
|
||||
while (pos != end && XMLUtils::isWhitespace(*pos))
|
||||
|
@ -403,17 +402,13 @@ double txIdPattern::getDefaultPriority()
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
void txIdPattern::toString(String& aDest)
|
||||
void txIdPattern::toString(nsAString& aDest)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
aDest.Append(NS_LITERAL_STRING("txIdPattern{"));
|
||||
#endif
|
||||
aDest.Append(NS_LITERAL_STRING("id('"));
|
||||
#ifdef TX_EXE
|
||||
aDest.Append(mIds);
|
||||
#else
|
||||
aDest.getNSString().Append(mIds);
|
||||
#endif
|
||||
aDest.Append(NS_LITERAL_STRING("')"));
|
||||
#ifdef DEBUG
|
||||
aDest.Append(PRUnichar('}'));
|
||||
|
@ -453,13 +448,13 @@ double txKeyPattern::getDefaultPriority()
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
void txKeyPattern::toString(String& aDest)
|
||||
void txKeyPattern::toString(nsAString& aDest)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
aDest.Append(NS_LITERAL_STRING("txKeyPattern{"));
|
||||
#endif
|
||||
aDest.Append(NS_LITERAL_STRING("key('"));
|
||||
String tmp;
|
||||
nsAutoString tmp;
|
||||
if (mPrefix) {
|
||||
TX_GET_ATOM_STRING(mPrefix, tmp);
|
||||
aDest.Append(tmp);
|
||||
|
@ -603,7 +598,7 @@ double txStepPattern::getDefaultPriority()
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
void txStepPattern::toString(String& aDest)
|
||||
void txStepPattern::toString(nsAString& aDest)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
aDest.Append(NS_LITERAL_STRING("txStepPattern{"));
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче