Fix for bug 88623 (Cleanup Transformiix code). Removing some warnings, fixing txResultStringComparator::compareValues, adding isEmpty to our string class. r=sicking, r=Pike, sr=jst.

This commit is contained in:
peterv%netscape.com 2001-10-16 09:26:59 +00:00
Родитель c67a9803a7
Коммит 853dfbd0cf
26 изменённых файлов: 161 добавлений и 462 удалений

Просмотреть файл

@ -34,10 +34,10 @@ void CommandLineUtils::getOptions
arg.clear();
arg.append(argv[i]);
if ((arg.length()>0) && (arg.charAt(0) == '-')) {
if (!arg.isEmpty() && (arg.charAt(0) == '-')) {
// clean up previous flag
if (flag.length()>0) {
if (!flag.isEmpty()) {
options.put(flag, new String(arg));
flag.clear();
}
@ -68,11 +68,13 @@ void CommandLineUtils::getOptions
}// if flag char '-'
else {
// Store both flag key and number key
if (flag.length() > 0) options.put(flag, new String(arg));
if (!flag.isEmpty())
options.put(flag, new String(arg));
flag.clear();
}
}// end for
if (flag.length()>0) options.put(flag, new String("no value"));
if (!flag.isEmpty())
options.put(flag, new String("no value"));
} //-- getOptions

Просмотреть файл

@ -222,7 +222,7 @@ void String::append(const char* source)
//
void String::append(const UNICODE_CHAR* source)
{
ptrNSString->Append((PRUnichar *)source, UnicodeLength(source));
ptrNSString->Append(source);
}
//
@ -296,7 +296,7 @@ void String::insert(PRInt32 offset, const char* source)
//
void String::insert(PRInt32 offset, const UNICODE_CHAR* source)
{
ptrNSString->Insert((PRUnichar *)source, offset, UnicodeLength(source));
ptrNSString->Insert((PRUnichar *)source, offset);
}
//
@ -599,7 +599,17 @@ PRInt32 String::lastIndexOf(const String& data, PRInt32 offset) const
return ptrNSString->RFind(nsData, PR_FALSE, offset);
}
//
//Checks whether the string is empty
//
MBool String::isEmpty() const
{
return ptrNSString->IsEmpty();
}
//
//Return the length of this string ( PRInt32 nsString::Length() )
//
PRInt32 String::length() const
{
if (ptrNSString){
@ -815,10 +825,3 @@ const nsString& String::getConstNSString() const
{
return *ptrNSString;
}
//
//String copies itself to the destination
//
//void String::copyString(SPECIAL_CHAR* dest)
//{
//}

Просмотреть файл

@ -143,18 +143,6 @@ void NamedMap::dumpMap() {
#endif
} //-- dumpMap
/**
* Compares the specified object with this NamedMap for equality.
* Returns true if and only if the specified Object is a NamedMap
* that hashes to the same value as this NamedMap
* @return true if and only if the specified Object is a NamedMap
* that hashes to the same value as this NamedMap
**/
MBool NamedMap::equals(NamedMap* namedMap) {
//-- currently does nothing
return MB_FALSE;
} //-- equals
/**
* Returns the object reference in this Map associated with the given name
* @return the object reference in this Map associated with the given name

Просмотреть файл

@ -96,24 +96,6 @@ public:
void clear(MBool doObjectDeletion);
/**
* Returns true if the specified Node is contained in the set.
* if the specfied Node is null, then if the NodeSet contains a null
* value, true will be returned.
* @param node the element to search the NodeSet for
* @return true if specified Node is contained in the NodeSet
**/
//MBool contains(Node* node);
/**
* Compares the specified object with this NamedMap for equality.
* Returns true if and only if the specified Object is a NamedMap
* that hashes to the same value as this NamedMap
* @return true if and only if the specified Object is a NamedMap
* that hashes to the same value as this NamedMap
**/
MBool equals(NamedMap* namedMap);
/**
* Returns true if there are no Nodes in the NodeSet.
* @return true if there are no Nodes in the NodeSet.

Просмотреть файл

@ -15,12 +15,12 @@
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Axel Hecht. Portions.
* Axel Hecht.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Axel Hecht <axel@pike.org> (Original Author)
* Axel Hecht <axel@pike.org>
*
*
* Alternatively, the contents of this file may be used under the terms of

Просмотреть файл

@ -905,6 +905,14 @@ PRInt32 String::lastIndexOf(const String& data, PRInt32 offset) const
return NOT_FOUND;
}
//
//Checks whether the string is empty
//
MBool String::isEmpty() const
{
return (strLength == 0);
}
//
//Returns the length of the String
//

Просмотреть файл

@ -131,6 +131,9 @@ class String : public TxObject
virtual PRInt32 lastIndexOf(const String& data) const;
virtual PRInt32 lastIndexOf(const String& data, PRInt32 offset) const;
//Checks whether the string is empty
virtual MBool isEmpty() const;
virtual PRInt32 length() const; //Returns the length
/**

Просмотреть файл

@ -1,314 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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 TransforMiiX XSLT processor.
*
* The Initial Developer of the Original Code is The MITRE Corporation.
* Portions created by MITRE are Copyright (C) 1999 The MITRE Corporation.
*
* Portions created by Keith Visco as a Non MITRE employee,
* (C) 1999 Keith Visco. All Rights Reserved.
*
* Contributor(s):
* Keith Visco, kvisco@ziplink.net
* -- original author.
* Larry Fitzpatrick, OpenText, lef@opentext.com
* -- 19990806
* -- moved initialization of constant shorts and chars from
* URIUtils.cpp to here
*
* Peter Van der Beken
*
*/
#include "URIUtils.h"
#ifndef TX_EXE
#include "nsNetUtil.h"
#endif
/**
* URIUtils
* A set of utilities for handling URIs
**/
#ifdef TX_EXE
//- Constants -/
const String URIUtils::HTTP_PROTOCOL = "http";
const String URIUtils::FILE_PROTOCOL = "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;
/**
* Returns an InputStream for the file represented by the href
* argument
* @param href the href of the file to get the input stream for.
* @return an InputStream to the desired resource
* @exception java.io.FileNotFoundException when the file could not be
* found
**/
istream* URIUtils::getInputStream
(const String& href, String& errMsg)
{
istream* inStream = 0;
ParsedURI* uri = parseURI(href);
if ( !uri->isMalformed ) {
inStream = openStream(uri);
}
else {
// Try local files
char* fchars = new char[href.length()+1];
inStream = new ifstream(href.toCharArray(fchars), ios::in);
delete fchars;
}
delete uri;
return inStream;
} //-- 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.length() != 0) {
int idx = -1;
//-- check for URL
ParsedURI* uri = parseURI(href);
if ( !uri->isMalformed ) {
idx = href.lastIndexOf(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.lastIndexOf(HREF_PATH_SEP);
//idx = href.lastIndexOf(File.separator);
idx = -1; //-- hack change later
if (idx2 > idx) idx = idx2;
}
if (idx >= 0) href.subString(0,idx, docBase);
delete uri;
}
dest.append(docBase);
} //-- getDocumentBase
#endif
/**
* Resolves the given href argument, using the given documentBase
* 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) {
if (base.length() == 0) {
dest.append(href);
return;
}
if (href.length() == 0) {
dest.append(base);
return;
}
#ifndef TX_EXE
nsCOMPtr<nsIURI> pURL;
String resultHref;
nsresult result = NS_NewURI(getter_AddRefs(pURL), base.getConstNSString());
if (NS_SUCCEEDED(result)) {
NS_MakeAbsoluteURI(resultHref.getNSString(), href.getConstNSString(), pURL);
dest.append(resultHref);
}
#else
String documentBase;
getDocumentBase(base, documentBase);
//-- check for URL
ParsedURI* uri = parseURI(href);
if ( !uri->isMalformed ) {
dest.append(href);
delete uri;
return;
}
//-- join document base + href
String xHref;
if (documentBase.length() > 0) {
xHref.append(documentBase);
if (documentBase.charAt(documentBase.length()-1) != HREF_PATH_SEP)
xHref.append(HREF_PATH_SEP);
}
xHref.append(href);
//-- check new href
ParsedURI* newUri = parseURI(xHref);
if ( !newUri->isMalformed ) {
dest.append(xHref);
}
else {
// Try local files
char* xHrefChars = new char[xHref.length()+1];
ifstream inFile(xHref.toCharArray(xHrefChars), ios::in);
if ( inFile ) dest.append(xHref);
else dest.append(href);
inFile.close();
delete xHrefChars;
}
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.lastIndexOf('#');
if(pos != NOT_FOUND)
href.subString(pos+1, frag);
else
frag.clear();
} //-- getFragmentIdentifier
void URIUtils::getDocumentURI(const String& href, String& docUri) {
PRInt32 pos;
pos = href.lastIndexOf('#');
if(pos != NOT_FOUND)
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.isEqual(uri->protocol) ) {
char* fchars = new char[uri->path.length()+1];
ifstream* inFile = new ifstream(uri->path.toCharArray(fchars), ios::in);
delete fchars;
inStream = inFile;
}
return inStream;
} //-- openStream
URIUtils::ParsedURI* URIUtils::parseURI(const String& uri) {
ParsedURI* uriTokens = new ParsedURI;
if (!uriTokens)
return NULL;
uriTokens->isMalformed = MB_FALSE;
short mode = PROTOCOL_MODE;
// look for protocol
int totalCount = uri.length();
int charCount = 0;
UNICODE_CHAR prevCh = '\0';
int fslash = 0;
String buffer(uri.length());
while ( charCount < totalCount ) {
UNICODE_CHAR ch = uri.charAt(charCount++);
switch(ch) {
case '.' :
if ( mode == PROTOCOL_MODE ) {
uriTokens->isMalformed = MB_TRUE;
mode = HOST_MODE;
}
buffer.append(ch);
break;
case ':' :
{
switch ( mode ) {
case PROTOCOL_MODE :
uriTokens->protocol = buffer;
buffer.clear();
mode = HOST_MODE;
break;
case HOST_MODE :
uriTokens->host = buffer;
buffer.clear();
mode = PORT_MODE;
break;
default:
break;
}
break;
}
case '/' :
switch ( mode ) {
case HOST_MODE :
if ( buffer.length() != 0 ) {
mode = PATH_MODE;
buffer.append(ch);
}
else if ( fslash == 2 ) mode = PATH_MODE;
else ++fslash;
break;
case PORT_MODE :
mode = PATH_MODE;
uriTokens->port.append(buffer);
buffer.clear();
break;
default:
buffer.append(ch);
break;
}
break;
default:
buffer.append(ch);
}
prevCh = ch;
}
if ( mode == PROTOCOL_MODE ) {
uriTokens->isMalformed = MB_TRUE;
}
//-- finish remaining mode
if ( buffer.length() > 0 ) {
switch ( mode ) {
case PROTOCOL_MODE :
uriTokens->protocol.append(buffer);
break;
case HOST_MODE :
uriTokens->host.append(buffer);
break;
case PORT_MODE :
uriTokens->port.append(buffer);
break;
case PATH_MODE :
uriTokens->path.append(buffer);
break;
default:
break;
}
}
return uriTokens;
} //-- parseURI
#endif

Просмотреть файл

@ -187,7 +187,7 @@ MBool XMLDOMUtils::getNameSpace
(const String& prefix, Element* element, String& dest)
{
String attName("xmlns");
if (prefix.length() > 0) {
if (!prefix.isEmpty()) {
attName.append(':');
attName.append(prefix);
}

Просмотреть файл

@ -102,13 +102,16 @@ MBool XMLUtils::isQNameChar(PRInt32 ch) {
**/
MBool XMLUtils::isValidQName(String& name) {
if (name.isEmpty())
return MB_FALSE;
if (!isAlphaChar(name.charAt(0)))
return MB_FALSE;
int size = name.length();
if ( size == 0 ) return MB_FALSE;
else if ( !isAlphaChar(name.charAt(0))) return MB_FALSE;
else {
for ( int i = 1; i < size; i++) {
if ( ! isQNameChar(name.charAt(i))) return MB_FALSE;
}
for (int i = 1; i < size; i++) {
if (!isQNameChar(name.charAt(i)))
return MB_FALSE;
}
return MB_TRUE;
} //-- isValidQName
@ -149,7 +152,8 @@ void XMLUtils::normalizeAttributeValue(String& attValue) {
UNICODE_CHAR ch = chars[cc++];
switch (ch) {
case ' ':
if ( attValue.length() > 0) addSpace = MB_TRUE;
if (!attValue.isEmpty())
addSpace = MB_TRUE;
break;
case '\r':
break;
@ -214,14 +218,14 @@ MBool XMLUtils::shouldStripTextnode (const String& data){
MBool toStrip = MB_TRUE;
for (PRInt32 i=0;toStrip && i<data.length();i++){
switch(data.charAt(i)) {
case 0x0020: // space
case 0x0009: // tab
case 0x000A: // LF
case 0x000D: // CR
break;
default:
toStrip = MB_FALSE;
break;
case 0x0020: // space
case 0x0009: // tab
case 0x000A: // LF
case 0x000D: // CR
break;
default:
toStrip = MB_FALSE;
break;
}
}
return toStrip;

Просмотреть файл

@ -71,11 +71,10 @@ const String& Element::getTagName()
*/
const String& Element::getAttribute(const String& aName)
{
Node* tempNode = getAttributeNode(aName);
Node* tempNode = getAttributeNode(aName);
if (tempNode)
return tempNode->getNodeValue();
else
if (tempNode)
return tempNode->getNodeValue();
return NULL_STRING;
}
@ -156,10 +155,9 @@ Attr* Element::getAttributeNode(const String& aName)
nsCOMPtr<nsIDOMAttr> attr;
if (NS_SUCCEEDED(nsElement->GetAttributeNode(aName.getConstNSString(),
getter_AddRefs(attr))))
getter_AddRefs(attr))) && attr)
return (Attr*)ownerDocument->createWrapper(attr);
else
return NULL;
return NULL;
}
/**
@ -179,8 +177,7 @@ Attr* Element::setAttributeNode(Attr* aNewAttr)
if (NS_SUCCEEDED(nsElement->SetAttributeNode(newAttr,
getter_AddRefs(returnAttr))))
return (Attr*)ownerDocument->createWrapper(returnAttr);
else
return NULL;
return NULL;
}
/**
@ -207,8 +204,7 @@ Attr* Element::removeAttributeNode(Attr* aOldAttr)
attrWrapper = new Attr(removedAttr, ownerDocument);
return attrWrapper;
}
else
return NULL;
return NULL;
}
/**
@ -227,8 +223,7 @@ NodeList* Element::getElementsByTagName(const String& aName)
if (NS_SUCCEEDED(nsElement->GetElementsByTagName(aName.getConstNSString(),
getter_AddRefs(list))))
return ownerDocument->createNodeList(list);
else
return NULL;
return NULL;
}
/**

Просмотреть файл

@ -135,7 +135,7 @@ MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
XMLDOMUtils::getNameSpace(prefixForNode, (Element*)parent,
nsForNode);
String nsForTest;
if (prefix.length())
if (!prefix.isEmpty())
cs->getNameSpaceURIFromPrefix(prefix, nsForTest);
if (!nsForTest.isEqual(nsForNode)) return MB_FALSE;
return localName.isEqual(this->name);
@ -143,9 +143,10 @@ MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
else {
if (isNamespaceWild) return nodeName.isEqual(this->name);
String nsForTest;
if (prefix.length())
if (!prefix.isEmpty())
cs->getNameSpaceURIFromPrefix(prefix, nsForTest);
if (nsForTest.length() > 0) return MB_FALSE;
if (!nsForTest.isEmpty())
return MB_FALSE;
return nodeName.isEqual(this->name);
}
return MB_FALSE;

Просмотреть файл

@ -48,7 +48,7 @@ ElementExpr::ElementExpr(String& name)
//-- set flags
isNameWild = this->name.isEqual(WILD_CARD);
isNamespaceWild = (isNameWild && (prefix.length() == 0));
isNamespaceWild = (isNameWild && prefix.isEmpty());
} //-- ElementExpr
//------------------/
@ -112,7 +112,7 @@ MBool ElementExpr::matches(Node* node, Node* context, ContextState* cs) {
//-- compare namespaces
String nsURI;
// use context to get namespace for testing against
if (prefix.length())
if (!prefix.isEmpty())
cs->getNameSpaceURIFromPrefix(prefix, nsURI);
String nsURI2;

Просмотреть файл

@ -233,13 +233,14 @@ MBool ExprLexer::nextIsOperatorToken(Token* token)
**/
void ExprLexer::parse(const String& pattern)
{
if (pattern.isEmpty())
return;
String tokenBuffer;
PRInt32 iter = 0, start;
PRInt32 size = pattern.length();
short defType;
UNICODE_CHAR ch;
if (size==0)
return;
//-- initialize previous token, this will automatically get
//-- deleted when it goes out of scope

Просмотреть файл

@ -62,10 +62,10 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate
AttributeValueTemplate* avt = new AttributeValueTemplate();
PRInt32 size = attValue.length();
if (size == 0)
if (attValue.isEmpty())
return avt; //XXX should return 0, but that causes crash in lre12
PRInt32 size = attValue.length();
int cc = 0;
UNICODE_CHAR nextCh;
UNICODE_CHAR ch;
@ -104,7 +104,7 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate
nextCh = cc != size ? attValue.charAt(cc) : 0;
}
else {
if (buffer.length() > 0)
if (!buffer.isEmpty())
avt->addExpr(new StringExpr(buffer));
buffer.clear();
inExpr = MB_TRUE;
@ -147,7 +147,7 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate
return 0;
}
if (buffer.length() > 0)
if (!buffer.isEmpty())
avt->addExpr(new StringExpr(buffer));
return avt;

Просмотреть файл

@ -234,8 +234,15 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
break;
case TRANSLATE:
if ( requireParams(3, 3, cs) ) {
String src, oldChars, newChars;
String src;
evaluateToString((Expr*)iter->next(),context, cs, src);
if (src.isEmpty()) {
result = new StringResult("");
break;
}
String oldChars, newChars;
evaluateToString((Expr*)iter->next(),context, cs, oldChars);
evaluateToString((Expr*)iter->next(),context, cs, newChars);
PRInt32 size = src.length();
@ -245,10 +252,12 @@ ExprResult* StringFunctionCall::evaluate(Node* context, ContextState* cs) {
for (i = 0; i < size; i++) {
PRInt32 idx = oldChars.indexOf(chars[i]);
if (idx >= 0) {
if (idx<newChars.length())
if (idx < newChars.length())
src.append(newChars.charAt(idx));
}
else src.append(chars[i]);
else {
src.append(chars[i]);
}
}
delete chars;
result = new StringResult(src);

Просмотреть файл

@ -66,7 +66,7 @@ void StringResult::stringValue(String& str) {
} //-- stringValue
MBool StringResult::booleanValue() {
return value.length() > 0;
return !value.isEmpty();
} //-- booleanValue
double StringResult::numberValue() {

Просмотреть файл

@ -95,7 +95,8 @@ ExprResult* UnionExpr::evaluate(Node* context, ContextState* cs) {
* context Node, and ContextState.
**/
double UnionExpr::getDefaultPriority(Node* node, Node* context,
ContextState* cs) {
ContextState* cs)
{
//-- find highest priority
double priority = Double::NEGATIVE_INFINITY;
ListIterator iter(&expressions);

Просмотреть файл

@ -41,7 +41,7 @@ void Numbering::doNumbering
String valueAttr = xslNumber->getAttribute(VALUE_ATTR);
//-- check for expr
if (valueAttr.length() > 0) {
if (!valueAttr.isEmpty()) {
Expr* expr = ps->getExpr(valueAttr);
nbrOfCounts = 1;
counts = new int[1];
@ -57,7 +57,9 @@ void Numbering::doNumbering
String countAttr = xslNumber->getAttribute(COUNT_ATTR);
PatternExpr* countExpr = 0;
if (countAttr.length() > 0) countExpr = ps->getPatternExpr(countAttr);
if (!countAttr.isEmpty()) {
countExpr = ps->getPatternExpr(countAttr);
}
else {
switch(context->getNodeType()) {
case Node::ATTRIBUTE_NODE:

Просмотреть файл

@ -129,7 +129,7 @@ void ProcessorState::addAttributeSet(Element* aAttributeSet,
return;
const String& name = aAttributeSet->getAttribute(NAME_ATTR);
if (name.length() == 0) {
if (name.isEmpty()) {
String err("missing required name attribute for xsl:attribute-set");
recieveError(err);
return;
@ -176,7 +176,7 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
NS_ASSERTION(aXslTemplate, "missing template");
const String& name = aXslTemplate->getAttribute(NAME_ATTR);
if (name.length() > 0) {
if (!name.isEmpty()) {
// check for duplicates
Element* tmp = (Element*)aImportFrame->mNamedTemplates.get(name);
if (tmp) {
@ -189,7 +189,7 @@ void ProcessorState::addTemplate(Element* aXslTemplate,
}
const String& match = aXslTemplate->getAttribute(MATCH_ATTR);
if (match.length() > 0) {
if (!match.isEmpty()) {
// get the txList for the right mode
const String& mode = aXslTemplate->getAttribute(MODE_ATTR);
txList* templates =
@ -374,7 +374,7 @@ Node* ProcessorState::retrieveDocument(const String& uri, const String& baseUri)
}
// return element with supplied id if supplied
if (frag.length())
if (!frag.isEmpty())
return xmlDoc->getElementById(frag);
return xmlDoc;
@ -426,7 +426,7 @@ Element* ProcessorState::findTemplate(Node* aNode,
templ->mTemplate->getAttribute(PRIORITY_ATTR);
double tmpPriority;
if (priorityAttr.length() > 0) {
if (!priorityAttr.isEmpty()) {
Double dbl(priorityAttr);
tmpPriority = dbl.doubleValue();
}
@ -495,7 +495,7 @@ Expr* ProcessorState::getExpr(const String& pattern) {
if ( !expr ) {
expr = exprParser.createExpr(pattern);
if ( !expr ) {
String err = "invalid expression: ";
String err = "Error in parsing XPath expression: ";
err.append(pattern);
expr = new ErrorFunctionCall(err);
}
@ -592,7 +592,7 @@ Document* ProcessorState::getResultDocument() {
void ProcessorState::getResultNameSpaceURI(const String& name, String& nameSpaceURI) {
String prefix;
XMLUtils::getNameSpace(name, prefix);
if (prefix.length() == 0) {
if (prefix.isEmpty()) {
nameSpaceURI.clear();
nameSpaceURI.append(*(String*)defaultNameSpaceURIStack.peek());
}
@ -815,57 +815,57 @@ MBool ProcessorState::addDecimalFormat(Element* element)
attValue = element->getAttribute(DECIMAL_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mDecimalSeparator = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(GROUPING_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mGroupingSeparator = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(INFINITY_ATTR);
if (attValue.length() > 0)
if (!attValue.isEmpty())
format->mInfinity=attValue;
attValue = element->getAttribute(MINUS_SIGN_ATTR);
if (attValue.length() == 1)
format->mMinusSign = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(NAN_ATTR);
if (attValue.length() > 0)
if (!attValue.isEmpty())
format->mNaN=attValue;
attValue = element->getAttribute(PERCENT_ATTR);
if (attValue.length() == 1)
format->mPercent = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(PER_MILLE_ATTR);
if (attValue.length() == 1)
format->mPerMille = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(ZERO_DIGIT_ATTR);
if (attValue.length() == 1)
format->mZeroDigit = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(DIGIT_ATTR);
if (attValue.length() == 1)
format->mDigit = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
attValue = element->getAttribute(PATTERN_SEPARATOR_ATTR);
if (attValue.length() == 1)
format->mPatternSeparator = attValue.charAt(0);
else if (attValue.length() > 1)
else if (!attValue.isEmpty())
success = MB_FALSE;
if (!success) {
@ -878,7 +878,7 @@ MBool ProcessorState::addDecimalFormat(Element* element)
txDecimalFormat* existing = NULL;
if (defaultDecimalFormatSet || formatName.length() > 0) {
if (defaultDecimalFormatSet || !formatName.isEmpty()) {
existing = (txDecimalFormat*)decimalFormats.get(formatName);
}
else {
@ -1205,7 +1205,7 @@ void ProcessorState::initialize() {
}
}
else if ( attName.isEqual(RESULT_NS_ATTR) ) {
if (attValue.length() > 0) {
if (!attValue.isEmpty()) {
if ( attValue.indexOf(HTML_NS) == 0 ) {
setOutputMethod("html");
}
@ -1213,7 +1213,7 @@ void ProcessorState::initialize() {
}
}
else if ( attName.isEqual(INDENT_RESULT_ATTR) ) {
if ( attValue.length() > 0 ) {
if (!attValue.isEmpty()) {
format.setIndent(attValue.isEqual(YES_VALUE));
}
}

Просмотреть файл

@ -254,7 +254,7 @@ void XSLTProcessor::parseStylesheetPI(String& data, String& type, String& href)
bufferMap.put("href", &href);
int ccount = 0;
MBool inLiteral = MB_FALSE;
char matchQuote = '"';
UNICODE_CHAR matchQuote = '"';
String sink;
String* buffer = &sink;
@ -268,7 +268,7 @@ void XSLTProcessor::parseStylesheetPI(String& data, String& type, String& href)
break;
case '=':
if ( inLiteral ) buffer->append(ch);
else if ( buffer->length() > 0 ) {
else if (!buffer->isEmpty()) {
buffer = (String*)bufferMap.get(*buffer);
if ( !buffer ) {
sink.clear();
@ -478,7 +478,7 @@ void XSLTProcessor::processTopLevel(Document* aSource,
// Add error to ErrorObserver
String fName = element->getAttribute(NAME_ATTR);
String err("unable to add ");
if (fName.length() == 0)
if (fName.isEmpty())
err.append("default");
else {
err.append("\"");
@ -493,7 +493,7 @@ void XSLTProcessor::processTopLevel(Document* aSource,
case XSLType::PARAM :
{
String name = element->getAttribute(NAME_ATTR);
if ( name.length() == 0 ) {
if (name.isEmpty()) {
notifyError("missing required name attribute for xsl:param");
break;
}
@ -534,26 +534,26 @@ void XSLTProcessor::processTopLevel(Document* aSource,
OutputFormat* format = aPs->getOutputFormat();
String attValue = element->getAttribute(METHOD_ATTR);
if (attValue.length() > 0) aPs->setOutputMethod(attValue);
if (!attValue.isEmpty()) aPs->setOutputMethod(attValue);
attValue = element->getAttribute(VERSION_ATTR);
if (attValue.length() > 0) format->setVersion(attValue);
if (!attValue.isEmpty()) format->setVersion(attValue);
attValue = element->getAttribute(ENCODING_ATTR);
if (attValue.length() > 0) format->setEncoding(attValue);
if (!attValue.isEmpty()) format->setEncoding(attValue);
attValue = element->getAttribute(INDENT_ATTR);
if (attValue.length() > 0) {
if (!attValue.isEmpty()) {
MBool allowIndent = attValue.isEqual(YES_VALUE);
format->setIndent(allowIndent);
}
attValue = element->getAttribute(DOCTYPE_PUBLIC_ATTR);
if (attValue.length() > 0)
if (!attValue.isEmpty())
format->setDoctypePublic(attValue);
attValue = element->getAttribute(DOCTYPE_SYSTEM_ATTR);
if (attValue.length() > 0)
if (!attValue.isEmpty())
format->setDoctypeSystem(attValue);
break;
@ -564,7 +564,7 @@ void XSLTProcessor::processTopLevel(Document* aSource,
case XSLType::VARIABLE :
{
String name = element->getAttribute(NAME_ATTR);
if ( name.length() == 0 ) {
if (name.isEmpty()) {
notifyError("missing required name attribute for xsl:variable");
break;
}
@ -575,7 +575,7 @@ void XSLTProcessor::processTopLevel(Document* aSource,
case XSLType::PRESERVE_SPACE :
{
String elements = element->getAttribute(ELEMENTS_ATTR);
if ( elements.length() == 0 ) {
if (elements.isEmpty()) {
//-- add error to ErrorObserver
String err("missing required 'elements' attribute for ");
err.append("xsl:preserve-space");
@ -591,7 +591,7 @@ void XSLTProcessor::processTopLevel(Document* aSource,
case XSLType::STRIP_SPACE :
{
String elements = element->getAttribute(ELEMENTS_ATTR);
if ( elements.length() == 0 ) {
if (elements.isEmpty()) {
//-- add error to ErrorObserver
String err("missing required 'elements' attribute for ");
err.append("xsl:strip-space");
@ -1021,7 +1021,7 @@ void XSLTProcessor::processAction
}
//-- create new text node and add it to the result tree
//-- if necessary
if ( textValue.length() > 0)
if (!textValue.isEmpty())
ps->addToResultTree(resultDoc->createTextNode(textValue));
return;
}
@ -1043,9 +1043,14 @@ void XSLTProcessor::processAction
const String& mode =
actionElement->getAttribute(MODE_ATTR);
String selectAtt = actionElement->getAttribute(SELECT_ATTR);
if ( selectAtt.length() == 0 ) selectAtt = "node()";
pExpr = ps->getPatternExpr(selectAtt);
ExprResult* exprResult = pExpr->evaluate(node, ps);
if (selectAtt.isEmpty())
selectAtt = "node()";
expr = ps->getExpr(selectAtt);
if (!expr) {
// XXX ErrorReport: out of memory
break;
}
ExprResult* exprResult = expr->evaluate(node, ps);
NodeSet* nodeSet = 0;
if ( exprResult->getResultType() == ExprResult::NODESET ) {
nodeSet = (NodeSet*)exprResult;
@ -1138,7 +1143,7 @@ void XSLTProcessor::processAction
case XSLType::CALL_TEMPLATE :
{
String templateName = actionElement->getAttribute(NAME_ATTR);
if ( templateName.length() > 0 ) {
if (!templateName.isEmpty()) {
Element* xslTemplate = ps->getNamedTemplate(templateName);
if ( xslTemplate ) {
//-- new code from OG
@ -1281,7 +1286,7 @@ void XSLTProcessor::processAction
{
String selectAtt = actionElement->getAttribute(SELECT_ATTR);
if (selectAtt.length() == 0)
if (selectAtt.isEmpty())
{
notifyError("missing required select attribute for xsl:for-each");
break;
@ -1505,7 +1510,7 @@ void XSLTProcessor::processAction
break;
}
exprResult->stringValue(value);
if (value.length()>0)
if (!value.isEmpty())
ps->addToResultTree(resultDoc->createTextNode(value));
delete exprResult;
break;
@ -1513,7 +1518,7 @@ void XSLTProcessor::processAction
case XSLType::VARIABLE :
{
String name = actionElement->getAttribute(NAME_ATTR);
if ( name.length() == 0 ) {
if (name.isEmpty()) {
notifyError("missing required name attribute for xsl:variable");
break;
}
@ -1527,7 +1532,7 @@ void XSLTProcessor::processAction
// Find out if we have a new default namespace
MBool newDefaultNS = MB_FALSE;
String nsURI = actionElement->getAttribute(XMLUtils::XMLNS);
if ( nsURI.length() != 0 ) {
if (!nsURI.isEmpty()) {
// Set the default namespace
ps->setDefaultNameSpaceURIForResult(nsURI);
newDefaultNS = MB_TRUE;
@ -1602,7 +1607,7 @@ void XSLTProcessor::processAction
void XSLTProcessor::processAttributeSets
(const String& names, Node* node, ProcessorState* ps)
{
if (names.length() == 0) return;
if (names.isEmpty()) return;
//-- split names
Tokenizer tokenizer(names);
@ -1662,7 +1667,7 @@ NamedMap* XSLTProcessor::processParameters(Element* xslAction, Node* context, Pr
short xslType = getElementType(actionName, ps);
if ( xslType == XSLType::WITH_PARAM ) {
String name = action->getAttribute(NAME_ATTR);
if ( name.length() == 0 ) {
if (name.isEmpty()) {
notifyError("missing required name attribute for xsl:with-param");
}
else {
@ -1840,7 +1845,7 @@ void XSLTProcessor::processTemplateParams
short xslType = getElementType(actionName, ps);
if ( xslType == XSLType::PARAM ) {
String name = action->getAttribute(NAME_ATTR);
if ( name.length() == 0 ) {
if (name.isEmpty()) {
notifyError("missing required name attribute for xsl:param");
}
else {
@ -1932,7 +1937,7 @@ void XSLTProcessor::xslCopy(Node* node, Element* action, ProcessorState* ps) {
// Find out if we have a new default namespace
MBool newDefaultNS = MB_FALSE;
String nsURI = element->getAttribute(XMLUtils::XMLNS);
if ( nsURI.length() != 0 ) {
if (!nsURI.isEmpty()) {
// Set the default namespace
ps->setDefaultNameSpaceURIForResult(nsURI);
newDefaultNS = MB_TRUE;

Просмотреть файл

@ -75,7 +75,7 @@ ExprResult* ElementAvailableFunctionCall::evaluate(Node* context, ContextState*
if (XMLUtils::isValidQName(property)) {
String prefix, propertyNsURI;
XMLUtils::getNameSpace(property, prefix);
if (prefix.length() > 0) {
if (!prefix.isEmpty()) {
cs->getNameSpaceURIFromPrefix(property, propertyNsURI);
}
if (propertyNsURI.isEqual(XSLT_NS)) {

Просмотреть файл

@ -76,7 +76,7 @@ ExprResult* FunctionAvailableFunctionCall::evaluate(Node* context, ContextState*
if (XMLUtils::isValidQName(property)) {
String prefix;
XMLUtils::getNameSpace(property, prefix);
if ((prefix.length() == 0) &&
if (prefix.isEmpty() &&
(property.isEqual(XPathNames::BOOLEAN_FN) ||
property.isEqual(XPathNames::CONCAT_FN) ||
property.isEqual(XPathNames::CONTAINS_FN) ||

Просмотреть файл

@ -49,8 +49,8 @@
#define DEFAULT_LANG "en"
txNodeSorter::txNodeSorter(ProcessorState* aPs) : mNKeys(0),
mPs(aPs)
txNodeSorter::txNodeSorter(ProcessorState* aPs) : mPs(aPs),
mNKeys(0)
{
}

Просмотреть файл

@ -188,7 +188,7 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
if (result != 0)
return ((mSorting & kAscending) ? 1 : -1) * result;
if (strval1->mCaseLength < 0) {
if ((strval1->mCaseLength == 0) && (strval1->mLength != 0)) {
String* caseString = (String *)strval1->mCaseKey;
rv = createRawSortKey(kCollationCaseSensitive,
caseString->getConstNSString(),
@ -196,11 +196,13 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
&strval1->mCaseLength);
if (NS_FAILED(rv)) {
// XXX ErrorReport
strval1->mCaseKey = caseString;
strval1->mCaseLength = 0;
return -1;
}
delete caseString;
}
if (strval2->mCaseLength < 0) {
if ((strval2->mCaseLength == 0) && (strval2->mLength != 0)) {
String* caseString = (String *)strval2->mCaseKey;
rv = createRawSortKey(kCollationCaseSensitive,
caseString->getConstNSString(),
@ -208,6 +210,8 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2)
&strval2->mCaseLength);
if (NS_FAILED(rv)) {
// XXX ErrorReport
strval2->mCaseKey = caseString;
strval2->mCaseLength = 0;
return -1;
}
delete caseString;
@ -241,16 +245,16 @@ nsresult txResultStringComparator::createRawSortKey(const nsCollationStrength aS
}
txResultStringComparator::StringValue::StringValue() : mKey(0),
mLength(0),
mCaseKey(0),
mCaseLength(-1)
mLength(0),
mCaseLength(0)
{
}
txResultStringComparator::StringValue::~StringValue()
{
PR_Free(mKey);
if (mCaseLength >= 0)
if (mCaseLength > 0)
PR_Free((PRUint8*)mCaseKey);
else
delete (String*)mCaseKey;
@ -262,6 +266,10 @@ txResultNumberComparator::txResultNumberComparator(MBool aAscending)
mAscending = aAscending ? 1 : -1;
}
txResultNumberComparator::~txResultNumberComparator()
{
}
TxObject* txResultNumberComparator::createSortableValue(ExprResult* aExprRes)
{
NumberValue* numval = new NumberValue;

Просмотреть файл

@ -75,7 +75,7 @@ class txResultStringComparator : public txXPathResultComparator
public:
txResultStringComparator(MBool aAscending, MBool aUpperFirst,
const String& aLanguage);
~txResultStringComparator();
virtual ~txResultStringComparator();
int compareValues(TxObject* aVal1, TxObject* aVal2);
TxObject* createSortableValue(ExprResult* aExprRes);
@ -113,6 +113,7 @@ class txResultNumberComparator : public txXPathResultComparator
{
public:
txResultNumberComparator(MBool aAscending);
virtual ~txResultNumberComparator();
int compareValues(TxObject* aVal1, TxObject* aVal2);
TxObject* createSortableValue(ExprResult* aExprRes);