mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-07 12:15:51 +00:00
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:
parent
558132da05
commit
6dbe002cae
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user