From 8bf305a18f47d510a7e86919385f3f8fb25a5cad Mon Sep 17 00:00:00 2001 From: "peterv%netscape.com" Date: Tue, 2 Jul 2002 14:15:01 +0000 Subject: [PATCH] Fix for bug 146967 (Clean up Transformiix strings). r=Pike, sr=jst. --- extensions/transformiix/build/Makefile.in | 1 - extensions/transformiix/build/makefile.win | 1 - .../transformiix/macbuild/transformiix.xml | 30 - .../source/base/CommandLineUtils.cpp | 2 +- .../transformiix/source/base/Double.cpp | 19 +- .../transformiix/source/base/Makefile.in | 2 - .../source/base/MozillaString.cpp | 0 .../transformiix/source/base/NamedMap.cpp | 31 +- .../transformiix/source/base/NamedMap.h | 11 - .../transformiix/source/base/Tokenizer.cpp | 12 +- .../transformiix/source/base/Tokenizer.h | 4 +- .../transformiix/source/base/TxString.cpp | 1430 ++++------------- .../transformiix/source/base/TxString.h | 312 ++-- .../transformiix/source/base/baseutils.h | 4 + .../transformiix/source/base/makefile.win | 14 +- .../source/base/txMozillaString.h | 231 +++ .../transformiix/source/base/txURIUtils.cpp | 4 +- .../transformiix/source/main/transformiix.cpp | 37 +- .../transformiix/source/xml/XMLUtils.cpp | 128 +- extensions/transformiix/source/xml/XMLUtils.h | 19 +- .../xml/dom/mozImpl/MozillaCharacterData.cpp | 10 +- .../source/xml/dom/mozImpl/MozillaText.cpp | 64 - .../source/xml/dom/mozImpl/mozilladom.h | 12 +- .../source/xml/dom/standalone/Attr.cpp | 2 +- .../xml/dom/standalone/CDATASection.cpp | 2 +- .../xml/dom/standalone/CharacterData.cpp | 18 +- .../source/xml/dom/standalone/Comment.cpp | 2 +- .../xml/dom/standalone/DOMImplementation.cpp | 7 +- .../source/xml/dom/standalone/Document.cpp | 4 +- .../source/xml/dom/standalone/Element.cpp | 4 +- .../xml/dom/standalone/NodeDefinition.cpp | 2 +- .../source/xml/dom/standalone/Text.cpp | 6 +- .../source/xml/dom/standalone/dom.h | 12 +- .../source/xml/parser/XMLParser.cpp | 11 +- .../transformiix/source/xpath/ExprLexer.cpp | 42 +- .../transformiix/source/xpath/ExprLexer.h | 2 +- .../transformiix/source/xpath/ExprParser.cpp | 10 +- .../source/xpath/FunctionCall.cpp | 12 +- .../transformiix/source/xpath/FunctionLib.h | 7 - .../transformiix/source/xpath/PathExpr.cpp | 10 +- .../transformiix/source/xpath/StringExpr.cpp | 2 +- .../source/xpath/StringFunctionCall.cpp | 20 +- .../source/xpath/StringResult.cpp | 2 +- .../transformiix/source/xpath/XPathNames.cpp | 69 - .../source/xpath/nsXPathEvaluator.cpp | 2 +- extensions/transformiix/source/xslt/Names.cpp | 178 +- .../source/xslt/ProcessorState.cpp | 35 +- .../transformiix/source/xslt/ProcessorState.h | 2 +- .../source/xslt/XSLTProcessor.cpp | 20 +- .../functions/SystemPropertyFunctionCall.cpp | 6 +- .../functions/txFormatNumberFunctionCall.cpp | 39 +- .../transformiix/source/xslt/txHTMLOutput.cpp | 2 +- .../source/xslt/txOutputFormat.cpp | 16 +- .../transformiix/source/xslt/txXMLOutput.cpp | 10 +- .../source/xslt/txXSLTPatterns.cpp | 9 +- .../source/xslt/util/txNodeSorter.cpp | 2 +- .../xslt/util/txXPathResultComparator.cpp | 8 +- 57 files changed, 1119 insertions(+), 1834 deletions(-) delete mode 100644 extensions/transformiix/source/base/MozillaString.cpp create mode 100644 extensions/transformiix/source/base/txMozillaString.h diff --git a/extensions/transformiix/build/Makefile.in b/extensions/transformiix/build/Makefile.in index 678bdfeff49..d7f53d7401c 100644 --- a/extensions/transformiix/build/Makefile.in +++ b/extensions/transformiix/build/Makefile.in @@ -65,7 +65,6 @@ LOBJS =../source/base/ArrayList.$(OBJ_SUFFIX) \ ../source/base/Tokenizer.$(OBJ_SUFFIX) \ ../source/base/txAtoms.$(OBJ_SUFFIX) \ ../source/base/txExpandedNameMap.$(OBJ_SUFFIX) \ - ../source/base/MozillaString.$(OBJ_SUFFIX) \ ../source/base/txURIUtils.$(OBJ_SUFFIX) \ ../source/xml/dom/mozImpl/MozillaObjectWrapper.$(OBJ_SUFFIX) \ ../source/xml/dom/mozImpl/MozillaAttr.$(OBJ_SUFFIX) \ diff --git a/extensions/transformiix/build/makefile.win b/extensions/transformiix/build/makefile.win index 516a1147939..f55c4af8917 100644 --- a/extensions/transformiix/build/makefile.win +++ b/extensions/transformiix/build/makefile.win @@ -50,7 +50,6 @@ CPP_OBJS= \ ..\source\base\$(OBJDIR)\Tokenizer.obj \ ..\source\base\$(OBJDIR)\txAtoms.obj \ ..\source\base\$(OBJDIR)\txExpandedNameMap.obj \ - ..\source\base\$(OBJDIR)\MozillaString.obj \ ..\source\base\$(OBJDIR)\txURIUtils.obj \ ..\source\xml\dom\mozImpl\$(OBJDIR)\MozillaObjectWrapper.obj \ ..\source\xml\dom\mozImpl\$(OBJDIR)\MozillaAttr.obj \ diff --git a/extensions/transformiix/macbuild/transformiix.xml b/extensions/transformiix/macbuild/transformiix.xml index 0da898ee68c..65d9b719a6d 100644 --- a/extensions/transformiix/macbuild/transformiix.xml +++ b/extensions/transformiix/macbuild/transformiix.xml @@ -1121,13 +1121,6 @@ Text - - Name - MozillaString.cpp - MacOS - Text - - Name XMLUtils.cpp @@ -2045,11 +2038,6 @@ MozillaNotation.cpp MacOS - - Name - MozillaString.cpp - MacOS - Name XMLParser.cpp @@ -3219,13 +3207,6 @@ Text - - Name - MozillaString.cpp - MacOS - Text - - Name XMLUtils.cpp @@ -4159,11 +4140,6 @@ MozillaNotation.cpp MacOS - - Name - MozillaString.cpp - MacOS - Name NSPR20.shlb @@ -4395,12 +4371,6 @@ Map.cpp MacOS - - transformiixDebug.shlb - Name - MozillaString.cpp - MacOS - transformiixDebug.shlb Name diff --git a/extensions/transformiix/source/base/CommandLineUtils.cpp b/extensions/transformiix/source/base/CommandLineUtils.cpp index 77ff00c5b9b..d662c907728 100644 --- a/extensions/transformiix/source/base/CommandLineUtils.cpp +++ b/extensions/transformiix/source/base/CommandLineUtils.cpp @@ -47,7 +47,7 @@ void CommandLineUtils::getOptions //-- check full flag, otherwise try to find //-- flag within string if (!flags.contains(flag)) { - PRInt32 idx = 1; + PRUint32 idx = 1; String tmpFlag; while(idx <= flag.length()) { flag.subString(0,idx, tmpFlag); diff --git a/extensions/transformiix/source/base/Double.cpp b/extensions/transformiix/source/base/Double.cpp index be41d957f6a..919dfb108dd 100644 --- a/extensions/transformiix/source/base/Double.cpp +++ b/extensions/transformiix/source/base/Double.cpp @@ -35,6 +35,7 @@ */ #include "primitives.h" +#include "XMLUtils.h" #include #include #ifdef WIN32 @@ -130,17 +131,15 @@ MBool Double::isNeg(double aDbl) */ double Double::toDouble(const String& aSrc) { - PRInt32 idx = 0; - PRInt32 len = aSrc.length(); + PRUint32 idx = 0; + PRUint32 len = aSrc.length(); MBool digitFound = MB_FALSE; // leading whitespace while (idx < len && - (aSrc.charAt(idx) == ' ' || - aSrc.charAt(idx) == '\n' || - aSrc.charAt(idx) == '\r' || - aSrc.charAt(idx) == '\t')) + XMLUtils::isWhitespace(aSrc.charAt(idx))) { ++idx; + } // sign char if (idx < len && aSrc.charAt(idx) == '-') @@ -168,12 +167,10 @@ double Double::toDouble(const String& aSrc) } // ending whitespace - while ((aSrc.charAt(idx) == ' ' || - aSrc.charAt(idx) == '\n' || - aSrc.charAt(idx) == '\r' || - aSrc.charAt(idx) == '\t') && - idx < len) + while (idx < len && + XMLUtils::isWhitespace(aSrc.charAt(idx))) { ++idx; + } // "."==NaN, ".0"=="0."==0 if (digitFound && idx == len) { diff --git a/extensions/transformiix/source/base/Makefile.in b/extensions/transformiix/source/base/Makefile.in index c76f5af7754..605c67b31ed 100644 --- a/extensions/transformiix/source/base/Makefile.in +++ b/extensions/transformiix/source/base/Makefile.in @@ -54,8 +54,6 @@ CPPSRCS = ArrayList.cpp \ ifdef TX_EXE CPPSRCS += CommandLineUtils.cpp \ TxString.cpp -else - CPPSRCS += MozillaString.cpp endif include $(topsrcdir)/config/rules.mk diff --git a/extensions/transformiix/source/base/MozillaString.cpp b/extensions/transformiix/source/base/MozillaString.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/extensions/transformiix/source/base/NamedMap.cpp b/extensions/transformiix/source/base/NamedMap.cpp index a88ece6ddb0..d71bcea14d9 100644 --- a/extensions/transformiix/source/base/NamedMap.cpp +++ b/extensions/transformiix/source/base/NamedMap.cpp @@ -143,15 +143,6 @@ void NamedMap::dumpMap() { #endif } //-- dumpMap -/** - * Returns the object reference in this Map associated with the given name - * @return the object reference in this Map associated with the given name -**/ -TxObject* NamedMap::get(const char* key) { - String sKey = key; - return get(sKey); -} //-- get - /** * Returns the object reference in this Map associated with the given name * @return the object reference in this Map associated with the given name @@ -190,15 +181,6 @@ StringList* NamedMap::keys() { return list; } //-- keys -/** - * Adds the specified Node to the top of this Stack. - * @param node the Node to add to the top of the Stack -**/ -void NamedMap::put(const char* key, TxObject* obj) { - String sKey = key; - put(sKey, obj); -} //-- put - /** * Adds the specified Node to the top of this Stack. * @param node the Node to add to the top of the Stack @@ -333,17 +315,14 @@ NamedMap::BucketItem* NamedMap::getBucketItem(const String& key) { /** **/ -unsigned long NamedMap::hashKey(const String& key) { - - PRInt32 len = key.length(); - UNICODE_CHAR* chars = new UNICODE_CHAR[len]; - key.toUnicode(chars); +unsigned long NamedMap::hashKey(const String& key) +{ + PRUint32 len = key.length(); unsigned long hashCode = 0; - for (PRInt32 i = 0; i < len; i++) { - hashCode += ((PRInt32)chars[i]) << 3; + for (PRUint32 i = 0; i < len; ++i) { + hashCode += ((PRInt32)key.charAt(i)) << 3; } - delete [] chars; return hashCode; } //-- hashKey diff --git a/extensions/transformiix/source/base/NamedMap.h b/extensions/transformiix/source/base/NamedMap.h index 289faddf510..6e208472c43 100644 --- a/extensions/transformiix/source/base/NamedMap.h +++ b/extensions/transformiix/source/base/NamedMap.h @@ -73,22 +73,11 @@ public: **/ TxObject* get(const String& name); - /** - * Returns the object reference in this Map associated with the given name - * @return the object reference in this Map associated with the given name - **/ - TxObject* get(const char* name); - /** * Adds the Object reference to the map and associates it with the given name **/ void put(const String& name, TxObject* obj); - /** - * Adds the Object reference to the map and associates it with the given name - **/ - void put(const char* name, TxObject* obj); - /** * Removes all elements from the Map table **/ diff --git a/extensions/transformiix/source/base/Tokenizer.cpp b/extensions/transformiix/source/base/Tokenizer.cpp index b6f605771ad..959013c67d3 100644 --- a/extensions/transformiix/source/base/Tokenizer.cpp +++ b/extensions/transformiix/source/base/Tokenizer.cpp @@ -55,6 +55,7 @@ */ #include "Tokenizer.h" +#include "XMLUtils.h" /* * Creates a new Tokenizer using the given source string @@ -67,10 +68,8 @@ txTokenizer::txTokenizer(const String& aSource) // Advance to start pos while (mCurrentPos < mSize) { - UNICODE_CHAR ch = mSource.charAt(mCurrentPos); // If character is not a whitespace, we are at start of first token - if (ch != ' ' && ch != '\n' && - ch != '\r' && ch != '\t') + if (!XMLUtils::isWhitespace(mSource.charAt(mCurrentPos))) break; ++mCurrentPos; } @@ -87,18 +86,15 @@ void txTokenizer::nextToken(String& aBuffer) while (mCurrentPos < mSize) { UNICODE_CHAR ch = mSource.charAt(mCurrentPos++); // If character is not a delimiter we append it - if (ch == ' ' || ch == '\n' || - ch == '\r' || ch == '\t') + if (XMLUtils::isWhitespace(ch)) break; aBuffer.append(ch); } // Advance to next start pos while (mCurrentPos < mSize) { - UNICODE_CHAR ch = mSource.charAt(mCurrentPos); // If character is not a whitespace, we are at start of next token - if (ch != ' ' && ch != '\n' && - ch != '\r' && ch != '\t') + if (!XMLUtils::isWhitespace(mSource.charAt(mCurrentPos))) break; ++mCurrentPos; } diff --git a/extensions/transformiix/source/base/Tokenizer.h b/extensions/transformiix/source/base/Tokenizer.h index 27bfce1ca35..67cfef6b8f4 100644 --- a/extensions/transformiix/source/base/Tokenizer.h +++ b/extensions/transformiix/source/base/Tokenizer.h @@ -61,8 +61,8 @@ public: private: - PRInt32 mCurrentPos; - PRInt32 mSize; + PRUint32 mCurrentPos; + PRUint32 mSize; String mSource; }; diff --git a/extensions/transformiix/source/base/TxString.cpp b/extensions/transformiix/source/base/TxString.cpp index 7e1afb1cedd..92e62a718b9 100644 --- a/extensions/transformiix/source/base/TxString.cpp +++ b/extensions/transformiix/source/base/TxString.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * (C) Copyright The MITRE Corporation 1999 All rights reserved. * @@ -26,1188 +26,428 @@ * */ - +#include "TxString.h" #include #include -#include "TxString.h" -#include -// -//Default Constructor, create an empty String -// -String::String() +String::String() : mBuffer(0), + mBufferLength(0), + mLength(0) { - strBuffer = NULL; - bufferLength = 0; - strLength = 0; } -// -//Create an empty String of a specific size -// -String::String(PRInt32 initSize) +String::String(const String& aSource) : mBuffer(aSource.toUnicode()), + mBufferLength(aSource.mLength), + mLength(aSource.mLength) { - strBuffer = new UNICODE_CHAR[initSize]; - bufferLength = initSize; - strLength = 0; } -// -//Create a copy of the source String -//TK 12/09/1999 - To ensure compatibility with sub classes of String, this -// constructor has been modified to use String's public -// interface only. -// -String::String(const String& source) +String::String(const UNICODE_CHAR* aSource, + PRUint32 aLength) : mBuffer(0), + mBufferLength(0), + mLength(0) { - PRInt32 copyLoop; - - //Allocate space for the source string - strLength = source.length(); - - //-- modified by kvisco to only use necessay amount of space - //-- was: bufferLength = source.bufferLength; - bufferLength = strLength; - - strBuffer = new UNICODE_CHAR[bufferLength]; - - //Copy the new string data after the old data - for (copyLoop=0;copyLoop mLength) { + if (!ensureCapacity(finalLength - mBufferLength)) { + return; + } + mLength = finalLength; } - else - clear(); - - return *this; + memcpy(&mBuffer[aOffset], aSource.mBuffer, + aSource.mLength * sizeof(UNICODE_CHAR)); + } + else { + append(aSource); + } } -// -//Overloaded '=' operator to assign the value of a UNICODE_CHAR string to this -//string. Note: The soucre is "NULL" terminated. -// -String& String::operator=(const UNICODE_CHAR* source) +void String::deleteChars(PRUint32 aOffset, PRUint32 aCount) { - PRInt32 copyLoop; - PRInt32 sourceLength; + PRUint32 cutEnd = aOffset + aCount; - if (source) - { - sourceLength = UnicodeLength(source); - ensureCapacity(sourceLength); - - for (copyLoop=0; copyLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop strLength) - { - ensureCapacity(totalOffset - strLength); - strLength += totalOffset - strLength; - } - - for (replaceLoop=0;replaceLoop current length, the string will be extended - * and padded with '\0' null characters. Otherwise the String - * will be truncated -**/ -void String::setLength(PRInt32 length) { - setLength(length, '\0'); -} //-- setLength - -/** - * Sets the Length of this String, if length is less than 0, it will - * be set to 0; if length > current length, the string will be extended - * and padded with given pad character. Otherwise the String - * will be truncated -**/ -void String::setLength(PRInt32 length, UNICODE_CHAR padChar) { - if ( length < 0 ) strLength = 0; - else if ( length > strLength ) { - PRInt32 diff = length-strLength; - ensureCapacity(diff); - for ( PRInt32 i = strLength; i < length; i++ ) - strBuffer[i] = padChar; - strLength = length; - } - else strLength = length; -} //-- setLength - -// -//Delete the "substring" starting at "offset" and proceeding for "count" number -//of characters (or until the end of the string, whichever comes first). -// -void String::deleteChars(PRInt32 offset, PRInt32 count) -{ - PRInt32 deleteLoop; - PRInt32 offsetCount; - - offset = offset < 0 ? 0 : offset; - offsetCount = offset + count; - - if (offsetCount < strLength) - { - for (deleteLoop=0;deleteLoop= 0)) - return strBuffer[index]; - else - return (UNICODE_CHAR)-1; -} - -// -//Clear out the string by simply setting the length to zero. The buffer is -//left intact. -// void String::clear() { - strLength = 0; + mLength = 0; } -// -//Make sure the buffer has room for 'capacity' UNICODE_CHARS. -// -void String::ensureCapacity(PRInt32 capacity) +PRInt32 String::indexOf(UNICODE_CHAR aData, + PRInt32 aOffset) const { - UNICODE_CHAR* tempStrBuffer = NULL; - - //Check for the desired capacity - PRInt32 freeSpace = bufferLength - strLength; //(added by kvisco) - - if (freeSpace < capacity) { - - //-- modified by kvisco to only add needed capacity, - //-- not extra bytes as before - //-- old : bufferLength += capacity; - bufferLength += capacity - freeSpace; - - tempStrBuffer = new UNICODE_CHAR[bufferLength]; - copyString(tempStrBuffer); - - //If the old string contained any data, delete it, and save the new. - if (strBuffer) - delete strBuffer; - - strBuffer = tempStrBuffer; - } -} - -/** - * Performs a CASE SENSITIVE search of the string for the first occurence - * of 'data'. If found return the index, else return NOT_FOUND. - * -- changed by kvisco to call indexOf(UNICODE_CHAR, PRInt32) -**/ -PRInt32 String::indexOf(UNICODE_CHAR data) const -{ - return indexOf(data, 0); -} //-- indexOf - -// -//Starting at 'offset' perform a CASE SENSITIVE search of the string looking -//for the first occurence of 'data'. If found return the index, else return -//NOT_FOUND. If the offset is less than zero, then start at zero. -// -PRInt32 String::indexOf(UNICODE_CHAR data, PRInt32 offset) const -{ - PRInt32 searchIndex = offset < 0 ? searchIndex = 0 : searchIndex = offset; - - while (1) - { - if (searchIndex >= strLength) - return NOT_FOUND; - else if (strBuffer[searchIndex] == data) - return searchIndex; - else - ++searchIndex; - } -} //-- indexOf - -// -//Returns the index of the first occurence of data -//TK 12/09/1999 - Modified to simply use indexOf(const String&, PRInt32). -// -PRInt32 String::indexOf(const String& data) const -{ - return indexOf(data, 0); -} - -// -//Returns the index of the first occurrence of data starting at offset -//TK 12/09/1999 - Modified to use the "data" String's public interface to -// retreive the Unicode Char buffer when calling isEqual. -// This ensures compatibility with classes derrived from String. -// -PRInt32 String::indexOf(const String& data, PRInt32 offset) const -{ - PRInt32 searchIndex = offset < 0 ? 0 : offset; - - while (1) - { - if (searchIndex <= (strLength - data.length())) - { - if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) - return searchIndex; - } - else - return NOT_FOUND; - - searchIndex++; + NS_ASSERTION(aOffset >= 0, "Passed negative offset to indexOf."); + if (aOffset < 0) { + return kNotFound; } + + PRInt32 searchIndex = aOffset; + + while (searchIndex < mLength) { + if (mBuffer[searchIndex] == aData) { + return searchIndex; + } + ++searchIndex; + } + return kNotFound; } -// -//Check for equality between this string, and data -//TK 12/09/1999 - Modified to use data.toUnicode() public member function -// when working with data's unicode buffer. This ensures -// compatibility with derrived classes. -// -MBool String::isEqual(const String& data) const +PRInt32 String::indexOf(const String& aData, PRInt32 aOffset) const { - if (strLength != data.length()) - return MB_FALSE; - return isEqual(strBuffer, data.toUnicode(), data.length()); + NS_ASSERTION(aOffset >= 0, "Passed negative offset to indexOf."); + if (aOffset < 0) { + return kNotFound; + } + + PRInt32 searchIndex = aOffset; + PRInt32 searchLimit = mLength - aData.mLength; + + while (searchIndex <= searchLimit) { + if (memcmp(&mBuffer[searchIndex], aData.mBuffer, + aData.mLength * sizeof(UNICODE_CHAR)) == 0) { + return searchIndex; + } + ++searchIndex; + } + return kNotFound; } -MBool String::isEqualIgnoreCase(const String& data) const +PRInt32 String::lastIndexOf(UNICODE_CHAR aData, + PRInt32 aOffset) const { - if (strLength != data.length()) - return MB_FALSE; + NS_ASSERTION(aOffset >= 0, "Passed negative offset to lastIndexOf."); + if (aOffset < 0) { + return kNotFound; + } + + PRUint32 searchIndex = mLength - aOffset; + while (--searchIndex >= 0) { + if (mBuffer[searchIndex] == aData) { + return searchIndex; + } + } + return kNotFound; +} + +MBool String::isEqual(const String& aData) const +{ + if (mLength != aData.mLength) { + return MB_FALSE; + } + return (memcmp(mBuffer, aData.mBuffer, mLength * sizeof(UNICODE_CHAR)) == 0); +} + +MBool String::isEqualIgnoreCase(const String& aData) const +{ + if (mLength != aData.mLength) { + return MB_FALSE; + } - const UNICODE_CHAR* otherBuffer = data.strBuffer; UNICODE_CHAR thisChar, otherChar; - PRInt32 compLoop = 0; - while (compLoop < strLength) { - thisChar = strBuffer[compLoop]; - if ((thisChar >= 'A') && (thisChar <= 'Z')) + PRUint32 compLoop = 0; + while (compLoop < mLength) { + thisChar = mBuffer[compLoop]; + if ((thisChar >= 'A') && (thisChar <= 'Z')) { thisChar += 32; - otherChar = otherBuffer[compLoop]; - if ((otherChar >= 'A') && (otherChar <= 'Z')) + } + otherChar = aData.mBuffer[compLoop]; + if ((otherChar >= 'A') && (otherChar <= 'Z')) { otherChar += 32; - if (thisChar != otherChar) + } + if (thisChar != otherChar) { return MB_FALSE; + } ++compLoop; } return MB_TRUE; } -/** - * Returns index of last occurrence of data -**/ -PRInt32 String::lastIndexOf(UNICODE_CHAR data) const +void String::truncate(PRUint32 aLength) { - return lastIndexOf(data, strLength-1); -} //-- lastIndexOf + NS_ASSERTION(aLength <= mBufferLength, "truncate can't increase buffer"); + mLength = (aLength > mBufferLength) ? mBufferLength : aLength; +} -/** - * Returns the index of the last occurrence of data starting at offset -**/ -PRInt32 String::lastIndexOf(UNICODE_CHAR data, PRInt32 offset) const +String& String::subString(PRUint32 aStart, String& aDest) const { - if ((offset < 0) || (offset >= strLength)) return NOT_FOUND; + return subString(aStart, mLength, aDest); +} - PRInt32 searchIndex = offset; - while (searchIndex >= 0) { - if (strBuffer[searchIndex] == data) return searchIndex; - --searchIndex; - } - return NOT_FOUND; - -} //-- lastIndexOf - -/** - * Returns the index of the last occurrence of data -**/ -PRInt32 String::lastIndexOf(const String& data) const +String& String::subString(PRUint32 aStart, PRUint32 aEnd, + String& aDest) const { - return lastIndexOf(data, strLength-1); -} //-- lastIndexOf + PRUint32 end = (aEnd > mLength) ? mLength : aEnd; -/** - * Returns the index of the last occurrence of data starting at offset -**/ -PRInt32 String::lastIndexOf(const String& data, PRInt32 offset) const -{ - PRInt32 searchIndex; - const UNICODE_CHAR* dataStrBuffer = NULL; - - if ((offset < 0) || (offset >= strLength)) - return NOT_FOUND; - else - { - searchIndex = offset; - - //If there is not enough space between searchIndex and the length of the of - //the string for "data" to appear, then there is no reason to search it. - if ((strLength - searchIndex) < data.length()) - searchIndex = strLength - data.length(); - - dataStrBuffer = data.toUnicode(); - while (searchIndex >= 0) - { - if (isEqual(&strBuffer[searchIndex], data.toUnicode(), data.length())) - return searchIndex; - --searchIndex; - } + aDest.clear(); + if (aStart >= end) { + return aDest; } - return NOT_FOUND; + PRUint32 substrLength = end - aStart; + + if (!aDest.ensureCapacity(substrLength)) { + return aDest; + } + memcpy(aDest.mBuffer, &mBuffer[aStart], + substrLength * sizeof(UNICODE_CHAR)); + aDest.mLength = substrLength; + + return aDest; } -// -//Checks whether the string is empty -// -MBool String::isEmpty() const -{ - return (strLength == 0); -} - -// -//Returns the length of the String -// -PRInt32 String::length() const -{ - return strLength; -} - -// -//Returns a subString starting at start -//TK 12/09/1999 - Modified to simply use subString(PRInt32, PRInt32, String&) -// -String& String::subString(PRInt32 start, String& dest) const -{ - return subString(start, strLength, dest); -} - -/** - * Returns the subString starting at start and ending at end - * Note: the dest String is cleared before use - * TK 12/09/1999 - Modified to use the "dest" String's public interface to - * ensure compatibility wtih derrived classes. -**/ -String& String::subString(PRInt32 start, PRInt32 end, String& dest) const -{ - PRInt32 srcLoop; - - start = start < 0 ? 0 : start; - end = end > strLength ? strLength : end; - - dest.clear(); - if (start < end) - { - dest.ensureCapacity(end - start); - for (srcLoop=start;srcLoop= 'A') && - (strBuffer[conversionLoop] <= 'Z')) - strBuffer[conversionLoop] += 32; - } + for (conversionLoop = 0; conversionLoop < mLength; ++conversionLoop) { + if ((mBuffer[conversionLoop] >= 'A') && + (mBuffer[conversionLoop] <= 'Z')) + mBuffer[conversionLoop] += 32; + } } -// -//Convert String to uppercase -// void String::toUpperCase() { - PRInt32 conversionLoop; + PRUint32 conversionLoop; - for (conversionLoop=0;conversionLoop= 'a') && - (strBuffer[conversionLoop] <= 'z')) - strBuffer[conversionLoop] -= 32; - } -} - -// -//Trim whitespace from both ends of String -// -void String::trim() -{ - PRInt32 trimLoop = strLength - 1; - PRInt32 cutLoop; - MBool done = MB_FALSE; - - //As long as we are not working on an emtpy string, trim from the right - //first, so we don't have to move useless spaces when we trim from the left. - if (strLength > 0) - { - while (!done) - { - switch (strBuffer[trimLoop]) - { - case ' ' : - case '\t' : - case '\n' : - case '\r' : - --strLength; - --trimLoop; - break; - - default : - done = MB_TRUE; - break; - } - } - } - - //Now, if there are any characters left to the string, Trim to the left. - //First count the number of "left" spaces. Then move all characters to the - //left by that ammount. - if (strLength > 0) - { - done = MB_FALSE; - trimLoop = 0; - while (!done) - { - switch (strBuffer[trimLoop]) - { - case ' ' : - case '\t' : - case '\n' : - case '\r' : - ++trimLoop; - break; - - default : - done = MB_TRUE; - break; - } - } - - if (trimLoop < strLength) - { - for (cutLoop=trimLoop;cutLoop= 'a') && + (mBuffer[conversionLoop] <= 'z')) + mBuffer[conversionLoop] -= 32; } } -// -//Cause the string to reverse itself -// -void String::reverse() +String& String::operator = (const String& aSource) { - PRInt32 reverseLoop; - UNICODE_CHAR tempChar; - - for (reverseLoop=0;reverseLoop<(strLength/2); reverseLoop++) - { - tempChar = strBuffer[reverseLoop]; - strBuffer[reverseLoop] = strBuffer[strLength - reverseLoop - 1]; - strBuffer[strLength - reverseLoop - 1] = tempChar; - } + delete [] mBuffer; + mBuffer = aSource.toUnicode(); + mBufferLength = aSource.mLength; + mLength = aSource.mLength; + return *this; } -// -//String copies itself to the destination -// -void String::copyString(UNICODE_CHAR* dest) +MBool String::ensureCapacity(PRUint32 aCapacity) { - PRInt32 copyLoop; + PRUint32 needed = aCapacity + mLength; + if (needed >= 0x8000) { + NS_ASSERTION(0, "Asked for too large a buffer."); + return MB_FALSE; + } - for (copyLoop=0;copyLoop 0) { + memcpy(tempBuffer, mBuffer, mLength * sizeof(UNICODE_CHAR)); + } + delete [] mBuffer; + mBuffer = tempBuffer; + mBufferLength = needed; return MB_TRUE; } -// -//Convert an PRInt32 into a String by storing it in target -// -String& String::ConvertInt(PRInt32 value, String& target) +UNICODE_CHAR* String::toUnicode() const { - UNICODE_CHAR charDigit; - - target.clear(); - - while (value) - { - charDigit = (value % 10) + 48; - target.append(charDigit); - value /=10; - } - - target.reverse(); - - return target; + if (mLength == 0) { + return 0; + } + UNICODE_CHAR* tmpBuffer = new UNICODE_CHAR[mLength]; + NS_ASSERTION(tmpBuffer, "out of memory"); + if (tmpBuffer) { + memcpy(tmpBuffer, mBuffer, mLength * sizeof(UNICODE_CHAR)); + } + return tmpBuffer; } -// -//Calculate the length of a null terminated UNICODE_CHAR string -// -PRInt32 String::UnicodeLength(const UNICODE_CHAR* data) +PRUint32 String::unicodeLength(const UNICODE_CHAR* aData) { - PRInt32 index = 0; - - //Count UNICODE_CHARs Until a Unicode "NULL" is found. - while (data[index] != 0x0000) - index++; + PRUint32 index = 0; + // Count UNICODE_CHARs Until a Unicode "NULL" is found. + while (aData[index] != 0x0000) { + ++index; + } return index; } + +ostream& operator<<(ostream& aOutput, const String& aSource) +{ + PRUint32 outputLoop; + + for (outputLoop = 0; outputLoop < aSource.mLength; ++outputLoop) { + aOutput << (char)aSource.charAt(outputLoop); + } + return aOutput; +} + +// XXX DEPRECATED +String::String(PRUint32 aSize) : mBuffer(0), + mBufferLength(0), + mLength(0) +{ + ensureCapacity(aSize); +} + +String::String(const char* aSource) : mBuffer(0), + mBufferLength(0), + mLength(0) +{ + if (!aSource) { + return; + } + + PRUint32 length = strlen(aSource); + if (!ensureCapacity(length)) { + return; + } + PRUint32 counter; + for (counter = 0; counter < length; ++counter) { + mBuffer[counter] = (UNICODE_CHAR)aSource[counter]; + } + mLength = length; +} + +void String::append(const char* aSource) +{ + if (!aSource) { + return; + } + + PRUint32 length = strlen(aSource); + if (!ensureCapacity(length)) { + return; + } + PRUint32 counter; + for (counter = 0; counter < length; ++counter) { + mBuffer[mLength + counter] = (UNICODE_CHAR)aSource[counter]; + } + mLength += length; +} + +MBool String::isEqual(const char* aData) const +{ + if (!aData) { + return MB_FALSE; + } + + PRUint32 length = strlen(aData); + if (length != mLength) { + return MB_FALSE; + } + + PRUint32 counter; + for (counter = 0; counter < length; ++counter) { + if (mBuffer[counter] != (UNICODE_CHAR)aData[counter]) { + return MB_FALSE; + } + } + return MB_TRUE; +} + +char* String::toCharArray() const +{ + char* tmpBuffer = new char[mLength + 1]; + NS_ASSERTION(tmpBuffer, "out of memory"); + if (tmpBuffer) { + PRUint32 conversionLoop; + + for (conversionLoop = 0; conversionLoop < mLength; ++conversionLoop) { + tmpBuffer[conversionLoop] = (char)mBuffer[conversionLoop]; + } + tmpBuffer[mLength] = 0; + } + return tmpBuffer; +} diff --git a/extensions/transformiix/source/base/TxString.h b/extensions/transformiix/source/base/TxString.h index 85ea2d02154..70560e36c55 100644 --- a/extensions/transformiix/source/base/TxString.h +++ b/extensions/transformiix/source/base/TxString.h @@ -25,186 +25,224 @@ * */ -#ifndef MITRE_STRING -#define MITRE_STRING +#ifndef txString_h__ +#define txString_h__ #include "TxObject.h" #include "baseutils.h" -#include #ifdef TX_EXE +#include typedef unsigned short UNICODE_CHAR; +const PRInt32 kNotFound = -1; #else #include "nsString.h" typedef PRUnichar UNICODE_CHAR; #endif -#ifndef NULL - #define NULL 0 +class String +#ifdef TX_EXE +: public TxObject #endif - -#define NOT_FOUND -1 - -class String : public TxObject { - //Translate UNICODE_CHARs to Chars and output to the provided stream - friend ostream& operator<<(ostream& output, const String& source); +public: + /* + * Default constructor. + */ + String(); - public: - String(); //Default Constructor, create an empty string - String(PRInt32 initSize); //Create an empty string of a specific size - String(const String& source); //Create a copy of the source string - String(const char* source); //Create a string from the characters - String(const UNICODE_CHAR* source); - String(const UNICODE_CHAR* source, PRInt32 length); -#ifndef TX_EXE - String(nsString* theNSString); +#ifdef TX_EXE + /* + * Copying constructor. + */ + String(const String& aSource); + + /* + * Constructor, allocates a buffer and copies the supplied string buffer. + * If aLength is zero it computes the length from the supplied string. + */ + explicit String(const UNICODE_CHAR* aSource, PRUint32 aLength = 0); +#else + explicit String(const nsAString& aSource); #endif + ~String(); - ~String(); //Destroy the string, and free memory + /* + * Append aSource to this string. + */ + void append(UNICODE_CHAR aSource); + void append(const String& aSource); + /* + * Insert aSource at aOffset in this string. + */ + void insert(PRUint32 aOffset, UNICODE_CHAR aSource); + void insert(PRUint32 aOffset, const String& aSource); - //Assign source to this string - virtual String& operator=(const String& source); - virtual String& operator=(const char* source); - virtual String& operator=(const UNICODE_CHAR* source); - virtual String& operator=(PRInt32 source); + /* + * Replace characters starting at aOffset with aSource. + */ + void replace(PRUint32 aOffset, UNICODE_CHAR aSource); + void replace(PRUint32 aOffset, const String& aSource); - //Grow buffer if necessary and append the source - virtual void append(UNICODE_CHAR source); - virtual void append(char source); - virtual void append(const String& source); - virtual void append(const char* source); - virtual void append(const UNICODE_CHAR* source); - virtual void append(const UNICODE_CHAR* source, PRInt32 length); - virtual void append(PRInt32 source); + /* + * Delete aCount characters starting at aOffset. + */ + void deleteChars(PRUint32 aOffset, PRUint32 aCount); - //Provide the ability to insert data into the middle of a string - virtual void insert(PRInt32 offset, const UNICODE_CHAR source); - virtual void insert(PRInt32 offset, const char source); - virtual void insert(PRInt32 offset, const String& source); - virtual void insert(PRInt32 offset, const char* source); - virtual void insert(PRInt32 offset, const UNICODE_CHAR* source); - virtual void insert(PRInt32 offset, const UNICODE_CHAR* source, - PRInt32 sourceLength); - virtual void insert(PRInt32 offset, PRInt32 source); + /* + * Returns the character at aIndex. Caller needs to check the + * index for out-of-bounds errors. + */ + UNICODE_CHAR charAt(PRUint32 aIndex) const; - //Provide the ability to replace one or more characters - virtual void replace(PRInt32 offset, const UNICODE_CHAR source); - virtual void replace(PRInt32 offset, const char source); - virtual void replace(PRInt32 offset, const String& source); - virtual void replace(PRInt32 offset, const char* source); - virtual void replace(PRInt32 offset, const UNICODE_CHAR* source); - virtual void replace(PRInt32 offset, const UNICODE_CHAR* source, - PRInt32 srcLength); - virtual void replace(PRInt32 offset, PRInt32 source); + /* + * Clear the string. + */ + void clear(); - //Provide the ability to delete a range of charactes - virtual void deleteChars(PRInt32 offset, PRInt32 count); + /* + * Returns index of first occurrence of aData. + */ + PRInt32 indexOf(UNICODE_CHAR aData, + PRInt32 aOffset = 0) const; + PRInt32 indexOf(const String& aData, PRInt32 aOffset = 0) const; - /** - * Returns the character at index. - * If the index is out of bounds, -1 will be returned. - **/ - virtual UNICODE_CHAR charAt(PRInt32 index) const; + /* + * Returns index of last occurrence of aData. + */ + PRInt32 lastIndexOf(UNICODE_CHAR aData, + PRInt32 aOffset = 0) const; - virtual void clear(); //Clear string + /* + * Check equality between strings. + */ + MBool isEqual(const String& aData) const; - virtual void ensureCapacity(PRInt32 capacity); //Make sure buffer is at least - //'size' + /* + * Check equality (ignoring case) between strings. + */ + MBool isEqualIgnoreCase(const String& aData) const; - //Returns index of first occurrence of data - virtual PRInt32 indexOf(UNICODE_CHAR data) const; - virtual PRInt32 indexOf(UNICODE_CHAR data, PRInt32 offset) const; - virtual PRInt32 indexOf(const String& data) const; - virtual PRInt32 indexOf(const String& data, PRInt32 offset) const; + /* + * Check whether the string is empty. + */ + MBool isEmpty() const; - virtual MBool isEqual(const String& data) const; //Check equality between - //strings - virtual MBool isEqualIgnoreCase(const String& data) const; + /* + * Return the length of the string. + */ + PRUint32 length() const; - //Returns index of last occurrence of data - virtual PRInt32 lastIndexOf(UNICODE_CHAR data) const; - virtual PRInt32 lastIndexOf(UNICODE_CHAR data, PRInt32 offset) const; - 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 - - /** - * Sets the Length of this String, if length is less than 0, it will - * be set to 0; if length > current length, the string will be extended - * and padded with '\0' null characters. Otherwise the String - * will be truncated - **/ - virtual void setLength(PRInt32 length); - - /** - * Sets the Length of this String, if length is less than 0, it will - * be set to 0; if length > current length, the string will be extended - * and padded with given pad character. Otherwise the String - * will be truncated - **/ - virtual void setLength(PRInt32 length, UNICODE_CHAR padChar); - - /** + /* * Returns a substring starting at start * Note: the dest String is cleared before use - **/ - virtual String& subString(PRInt32 start, String& dest) const; + */ + String& subString(PRUint32 aStart, String& aDest) const; - /** + /* * Returns the subString starting at start and ending at end * Note: the dest String is cleared before use - **/ - virtual String& subString(PRInt32 start, PRInt32 end, String& dest) const; + */ + String& subString(PRUint32 aStart, PRUint32 aEnd, + String& aDest) const; - //Convert the internal rep. to a char buffer - virtual char* toCharArray() const; - virtual char* toCharArray(char* dest) const; - virtual UNICODE_CHAR* toUnicode(UNICODE_CHAR* dest) const; - virtual const UNICODE_CHAR* toUnicode() const; + /* + * Convert string to lowercase. + */ + void toLowerCase(); - virtual void toLowerCase(); //Convert string to lowercase - virtual void toUpperCase(); //Convert string to uppercase - virtual void trim(); //Trim whitespace from both ends + /* + * Convert string to uppercase. + */ + void toUpperCase(); - virtual void reverse(); //Reverse the string + /* + * Shorten the string to aLength. + */ + void truncate(PRUint32 aLength); -#ifndef TX_EXE - virtual nsString& getNSString(); - virtual const nsString& getConstNSString() const; -#endif - - protected: - //Convert an Int into a String - //TK 12/09/1999 - Make this function available to Derrived classes - String& ConvertInt(PRInt32 value, String& target); - - //Calculates the length of a null terminated UNICODE_CHAR array - PRInt32 UnicodeLength(const UNICODE_CHAR* data); - - private: -#ifndef TX_EXE - nsString* ptrNSString; +#ifdef TX_EXE + /* + * Assignment operator. Override default assignment operator + * only on standalone, the default will do the right thing for + * module. + */ + String& operator = (const String& aSource); #else - PRInt32 strLength; - PRInt32 bufferLength; - UNICODE_CHAR* strBuffer; + /* + * Return a reference to this string's nsString. + */ + nsString& getNSString(); + + /* + * Return a const reference to this string's nsString. + */ + const nsString& getConstNSString() const; #endif - //String copies itself to the destination - void copyString(UNICODE_CHAR* dest); +private: +#ifndef TX_EXE + nsString mString; +#else + /* + * Make sure the string buffer can hold aCapacity characters. + */ + MBool ensureCapacity(PRUint32 aCapacity); - //Compare the two string representations for equality - MBool isEqual(const UNICODE_CHAR* data, const UNICODE_CHAR* search, - PRInt32 length) const; + /* + * Allocate a new UNICODE_CHAR buffer and copy this string's + * buffer into it. Caller needs to free the buffer. + */ + UNICODE_CHAR* toUnicode() const; + + /* + * Compute the unicode length of aData. + */ + static PRUint32 unicodeLength(const UNICODE_CHAR* aData); + + /* + * Translate UNICODE_CHARs to Chars and output to the provided stream. + */ + friend ostream& operator << (ostream& aOutput, const String& aSource); + + UNICODE_CHAR* mBuffer; + PRUint32 mBufferLength; + PRUint32 mLength; +#endif + +// XXX DEPRECATED +public: + explicit String(PRUint32 aSize); + explicit String(const char* aSource); // XXX Used for literal strings + void append(const char* aSource); + MBool isEqual(const char* aData) const; + char* toCharArray() const; +// XXX DEPRECATED }; -ostream& operator<<(ostream& output, const String& source); +#ifdef TX_EXE +ostream& operator << (ostream& aOutput, const String& aSource); +inline UNICODE_CHAR String::charAt(PRUint32 aIndex) const +{ + NS_ASSERTION(aIndex < mLength, "|charAt| out-of-range"); + return mBuffer[aIndex]; +} + +inline MBool String::isEmpty() const +{ + return (mLength == 0); +} + +inline PRUint32 String::length() const +{ + return mLength; +} +#else +// txMozillaString.h contains all inline implementations for the +// Mozilla module. +#include "txMozillaString.h" #endif +#endif // txString_h__ diff --git a/extensions/transformiix/source/base/baseutils.h b/extensions/transformiix/source/base/baseutils.h index 2c80d1dcf68..8b1b661862b 100644 --- a/extensions/transformiix/source/base/baseutils.h +++ b/extensions/transformiix/source/base/baseutils.h @@ -66,5 +66,9 @@ #define MB_FALSE PR_FALSE #endif +#ifndef NULL + #define NULL 0 +#endif + #endif diff --git a/extensions/transformiix/source/base/makefile.win b/extensions/transformiix/source/base/makefile.win index fc568a02c24..1f57a4659d7 100644 --- a/extensions/transformiix/source/base/makefile.win +++ b/extensions/transformiix/source/base/makefile.win @@ -48,17 +48,13 @@ CPP_OBJS= \ .\$(OBJDIR)\Tokenizer.obj \ .\$(OBJDIR)\txAtoms.obj \ .\$(OBJDIR)\txExpandedNameMap.obj \ - .\$(OBJDIR)\txURIUtils.obj + $(NULL) -!ifndef TX_EXE -CPP_OBJS = $(CPP_OBJS) \ - .\$(OBJDIR)\MozillaString.obj \ - $(NULL) -!else -CPP_OBJS = $(CPP_OBJS) \ +!ifdef TX_EXE +CPP_OBJS = \ .\$(OBJDIR)\CommandLineUtils.obj \ - .\$(OBJDIR)\TxString.obj \ - $(NULL) + .\$(OBJDIR)\TxString.obj \ + $(CPP_OBJS) !endif EXPORTS = \ diff --git a/extensions/transformiix/source/base/txMozillaString.h b/extensions/transformiix/source/base/txMozillaString.h new file mode 100644 index 00000000000..da990eb9942 --- /dev/null +++ b/extensions/transformiix/source/base/txMozillaString.h @@ -0,0 +1,231 @@ +/* -*- Mode: C++; 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): + * Peter Van der Beken + * + * + * 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 txMozillaString_h__ +#define txMozillaString_h__ + +#include "nsReadableUtils.h" +#include "nsUnicharUtils.h" + +MOZ_DECL_CTOR_COUNTER(String) + +inline String::String() +{ + MOZ_COUNT_CTOR(String); +} + +inline String::String(const nsAString& aSource) : mString(aSource) +{ + MOZ_COUNT_CTOR(String); +} + +inline String::~String() +{ + MOZ_COUNT_DTOR(String); +} + +inline void String::append(UNICODE_CHAR aSource) +{ + mString.Append(aSource); +} + +inline void String::append(const String& aSource) +{ + mString.Append(aSource.mString); +} + +inline void String::insert(PRUint32 aOffset, + UNICODE_CHAR aSource) +{ + mString.Insert(aSource, aOffset); +} + +inline void String::insert(PRUint32 aOffset, const String& aSource) +{ + mString.Insert(aSource.mString, aOffset); +} + +inline void String::replace(PRUint32 aOffset, + UNICODE_CHAR aSource) +{ + mString.SetCharAt(aSource, aOffset); +} + +inline void String::replace(PRUint32 aOffset, const String& aSource) +{ + mString.Replace(aOffset, mString.Length() - aOffset, aSource.mString); +} + +inline void String::deleteChars(PRUint32 aOffset, + PRUint32 aCount) +{ + mString.Cut(aOffset, aCount); +} + +inline UNICODE_CHAR String::charAt(PRUint32 aIndex) const +{ + return mString.CharAt(aIndex); +} + +inline void String::clear() +{ + mString.Truncate(); +} + +inline PRInt32 String::indexOf(UNICODE_CHAR aData, + PRInt32 aOffset) const +{ + return mString.FindChar(aData, (PRUint32)aOffset); +} + +inline PRInt32 String::indexOf(const String& aData, + PRInt32 aOffset) const +{ + return mString.Find(aData.mString, aOffset); +} + +inline PRInt32 String::lastIndexOf(UNICODE_CHAR aData, + PRInt32 aOffset) const +{ + return mString.RFindChar(aData, aOffset); +} + +inline MBool String::isEqual(const String& aData) const +{ + if (this == &aData) + return MB_TRUE; + return mString.Equals(aData.mString); +} + +inline MBool String::isEqualIgnoreCase(const String& aData) const +{ + if (this == &aData) + return MB_TRUE; + return mString.Equals(aData.mString, nsCaseInsensitiveStringComparator()); +} + +inline MBool String::isEmpty() const +{ + return mString.IsEmpty(); +} + +inline PRUint32 String::length() const +{ + return mString.Length(); +} + +inline void String::truncate(PRUint32 aLength) +{ + mString.Truncate(aLength); +} + +inline String& String::subString(PRUint32 aStart, String& aDest) const +{ + PRUint32 length = mString.Length() - aStart; + if (length < 0) { + aDest.clear(); + } + else { + aDest.mString.Assign(Substring(mString, aStart, length)); + } + return aDest; +} + +inline String& String::subString(PRUint32 aStart, PRUint32 aEnd, + String& aDest) const +{ + PRUint32 length = aEnd - aStart; + if (length < 0) { + aDest.clear(); + } + else { + aDest.mString.Assign(Substring(mString, aStart, length)); + } + return aDest; +} + +inline void String::toLowerCase() +{ + ToLowerCase(mString); +} + +inline void String::toUpperCase() +{ + ToUpperCase(mString); +} + +inline nsString& String::getNSString() +{ + return mString; +} + +inline const nsString& String::getConstNSString() const +{ + return mString; +} + +// XXX DEPRECATED +inline String::String(PRUint32 aSize) +{ + MOZ_COUNT_CTOR(String); + mString.SetCapacity(aSize); +} + +inline String::String(const char* aSource) +{ + MOZ_COUNT_CTOR(String); + mString.AssignWithConversion(aSource); +} + +inline void String::append(const char* aSource) +{ + mString.AppendWithConversion(aSource); +} + +inline MBool String::isEqual(const char* aData) const +{ + return mString.EqualsWithConversion(aData); +} + +inline char* String::toCharArray() const +{ + return ToNewCString(mString); +} + +#endif // txMozillaString_h__ diff --git a/extensions/transformiix/source/base/txURIUtils.cpp b/extensions/transformiix/source/base/txURIUtils.cpp index dfc054e0d07..da82abf8f42 100644 --- a/extensions/transformiix/source/base/txURIUtils.cpp +++ b/extensions/transformiix/source/base/txURIUtils.cpp @@ -186,7 +186,7 @@ void URIUtils::resolveHref(const String& href, const String& base, void URIUtils::getFragmentIdentifier(const String& href, String& frag) { PRInt32 pos; pos = href.lastIndexOf('#'); - if(pos != NOT_FOUND) + if(pos != kNotFound) href.subString(pos+1, frag); else frag.clear(); @@ -195,7 +195,7 @@ void URIUtils::getFragmentIdentifier(const String& href, String& frag) { void URIUtils::getDocumentURI(const String& href, String& docUri) { PRInt32 pos; pos = href.lastIndexOf('#'); - if(pos != NOT_FOUND) + if(pos != kNotFound) href.subString(0,pos,docUri); else docUri = href; diff --git a/extensions/transformiix/source/main/transformiix.cpp b/extensions/transformiix/source/main/transformiix.cpp index f99ffc38679..a051ab0c7cb 100644 --- a/extensions/transformiix/source/main/transformiix.cpp +++ b/extensions/transformiix/source/main/transformiix.cpp @@ -77,42 +77,43 @@ int main(int argc, char** argv) { options.setObjectDeletion(MB_TRUE); CommandLineUtils::getOptions(options, argc, argv, flags); - if (!options.get("q")) { + if (!options.get(String("q"))) { String copyright("(C) 1999 The MITRE Corporation, Keith Visco, and contributors"); cerr << xsltProcessor.getAppName() << " "; cerr << xsltProcessor.getAppVersion() << endl; cerr << copyright << endl; //-- print banner line - PRInt32 fillSize = copyright.length() + 1; - String fill; - fill.setLength(fillSize, '-'); - cerr << fill << endl << endl; + PRUint32 fillSize = copyright.length() + 1; + PRUint32 counter; + for (counter = 0; counter < fillSize; ++counter) + cerr << '-'; + cerr << endl << endl; } - if (options.get("h")) { + if (options.get(String("h"))) { printHelp(); return 0; } - String* xmlFilename = (String*)options.get("i"); - String* xsltFilename = (String*)options.get("s"); - String* outFilename = (String*)options.get("o"); + String* xmlFilename = (String*)options.get(String("i")); + String* xsltFilename = (String*)options.get(String("s")); + String* outFilename = (String*)options.get(String("o")); //-- open XML file istream* xmlInput = &cin; if (xmlFilename && ! xmlFilename->isEqual("-")) { - char* chars = new char[xmlFilename->length()+1]; - xmlInput = new ifstream(xmlFilename->toCharArray(chars), ios::in); - delete chars; + char* chars = xmlFilename->toCharArray(); + xmlInput = new ifstream(chars, ios::in); + delete [] chars; } //-- handle output stream ostream* resultOutput = &cout; ofstream resultFileStream; if ( outFilename && ! outFilename->isEqual("-")) { - char* chars = new char[outFilename->length()+1]; - resultFileStream.open(outFilename->toCharArray(chars), ios::out); - delete chars; + char* chars = outFilename->toCharArray(); + resultFileStream.open(chars, ios::out); + delete [] chars; if ( !resultFileStream ) { cerr << "error opening output file: " << *xmlFilename << endl; return -1; @@ -132,9 +133,9 @@ int main(int argc, char** argv) { } else { //-- open XSLT file - char* chars = new char[xsltFilename->length()+1]; - ifstream xsltInput(xsltFilename->toCharArray(chars), ios::in); - delete chars; + char* chars = xsltFilename->toCharArray(); + ifstream xsltInput(chars, ios::in); + delete [] chars; xsltProcessor.process(*xmlInput, *xmlFilename, xsltInput, *xsltFilename, *resultOutput); } resultFileStream.close(); diff --git a/extensions/transformiix/source/xml/XMLUtils.cpp b/extensions/transformiix/source/xml/XMLUtils.cpp index c2a59bda434..56ed1f8c285 100644 --- a/extensions/transformiix/source/xml/XMLUtils.cpp +++ b/extensions/transformiix/source/xml/XMLUtils.cpp @@ -39,17 +39,17 @@ nsresult txExpandedName::init(const String& aQName, if (!XMLUtils::isValidQName(aQName)) return NS_ERROR_FAILURE; - int idx = aQName.indexOf(':'); - if (idx >= 0) { + PRInt32 idx = aQName.indexOf(':'); + if (idx != kNotFound) { String localName, prefixStr; - aQName.subString(0, idx, prefixStr); + aQName.subString(0, (PRUint32)idx, prefixStr); txAtom* prefix = TX_GET_ATOM(prefixStr); PRInt32 namespaceID = aResolver->lookupNamespaceID(prefix); if (namespaceID == kNameSpaceID_Unknown) return NS_ERROR_FAILURE; mNamespaceID = namespaceID; - aQName.subString(idx+1, localName); + aQName.subString((PRUint32)idx + 1, localName); TX_IF_RELEASE_ATOM(mLocalName); mLocalName = TX_GET_ATOM(localName); } @@ -68,33 +68,36 @@ nsresult txExpandedName::init(const String& aQName, //- Implementation of XMLUtils -/ //------------------------------/ -void XMLUtils::getPrefix(const String& src, String& dest) { - - //-- anything preceding ':' is the namespace part of the name - int idx = src.indexOf(':'); - if ( idx > 0 ) { - //-- create new String to prevent any chars in dest from being - //-- lost - String tmp; - src.subString(0,idx, tmp); - dest.append(tmp); +void XMLUtils::getPrefix(const String& src, String& dest) +{ + // Anything preceding ':' is the namespace part of the name + PRInt32 idx = src.indexOf(':'); + if (idx == kNotFound) { + return; } - else dest.append(""); - + // 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); } -void XMLUtils::getLocalPart(const String& src, String& dest) { - - //-- anything after ':' is the local part of the name - int idx = src.indexOf(':'); - if ( idx < -1 ) idx = -1; - //-- create new String to prevent any chars in dest from being - //-- lost +void XMLUtils::getLocalPart(const String& src, String& dest) +{ + // Anything after ':' is the local part of the name + PRInt32 idx = src.indexOf(':'); + if (idx == kNotFound) { + dest.append(src); + 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(idx+1, tmp); + src.subString((PRUint32)idx + 1, tmp); dest.append(tmp); - -} //-- getLocalPart +} MBool XMLUtils::isValidQName(const String& aName) { @@ -139,74 +142,49 @@ MBool XMLUtils::isValidQName(const String& aName) /** * Returns true if the given string has only whitespace characters **/ -MBool XMLUtils::isWhitespace(const String& text) { - for ( int i = 0; i < text.length(); i++ ) { - PRInt32 ch = text.charAt(i); - switch ( ch ) { - case ' ' : - case '\n' : - case '\r' : - case '\t' : - break; - default: - return MB_FALSE; +MBool XMLUtils::isWhitespace(const String& aText) +{ + PRUint32 size = aText.length(); + PRUint32 i; + for (i = 0; i < size; ++i) { + if (!isWhitespace(aText.charAt(i))) { + return MB_FALSE; } } return MB_TRUE; -} //-- isWhitespace +} /** * Normalizes the value of a XML processing instruction **/ -void XMLUtils::normalizePIValue(String& piValue) { - PRInt32 size = piValue.length(); - //-- make copy of chars - UNICODE_CHAR* chars = new UNICODE_CHAR[size]; - piValue.toUnicode(chars); - //-- clear attValue +void XMLUtils::normalizePIValue(String& piValue) +{ + String origValue(piValue); + PRUint32 origLength = origValue.length(); + PRUint32 conversionLoop = 0; + UNICODE_CHAR prevCh = 0; piValue.clear(); - PRInt32 cc = 0; - UNICODE_CHAR prevCh = 0x0000; - while ( cc < size) { - UNICODE_CHAR ch = chars[cc++]; + while (conversionLoop < origLength) { + UNICODE_CHAR ch = origValue.charAt(conversionLoop); switch (ch) { case '>': - if ( prevCh == '?' ) { + { + if (prevCh == '?') { piValue.append(' '); } - piValue.append(ch); break; + } default: - piValue.append(ch); + { break; + } } + piValue.append(ch); prevCh = ch; + ++conversionLoop; } - delete chars; -} //-- noramlizePIValue - -/** - * Is this a whitespace string to be stripped? - * Newlines (#xD), tabs (#x9), spaces (#x20), CRs (#xA) only? - * @param data the String to test for whitespace -**/ -MBool XMLUtils::shouldStripTextnode (const String& data){ - MBool toStrip = MB_TRUE; - for (PRInt32 i=0;toStrip && i - * - */ - -/* Implementation of the wrapper class to convert the Mozilla nsIDOMText - interface into a TransforMIIX Text interface. -*/ - -#include "mozilladom.h" - -/** - * Construct a wrapper with the specified Mozilla object and document owner. - * - * @param aText the nsIDOMCharacterData you want to wrap - * @param aOwner the document that owns this object - */ -Text::Text(nsIDOMText* aText, Document* aOwner) : CharacterData(aText, aOwner) -{ -} - -/** - * Destructor - */ -Text::~Text() -{ -} - -/** - * Call nsIDOMText::SplitText to split the text. - * - * @param aOffset the offset at which you want to split - * - * @return the resulting Text object - */ -Text* Text::splitText(PRInt32 aOffset) -{ - NSI_FROM_TX_NULL_CHECK(Text) - nsCOMPtr split; - - if (NS_SUCCEEDED(nsText->SplitText(aOffset, getter_AddRefs(split)))) - return (Text*)ownerDocument->createWrapper(split); - else - return NULL; -} diff --git a/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h b/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h index 75e7d7495ee..c5108f35677 100644 --- a/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h +++ b/extensions/transformiix/source/xml/dom/mozImpl/mozilladom.h @@ -471,13 +471,13 @@ class CharacterData : public Node const String& getData(); void setData(const String& aSource); - PRInt32 getLength() const; + PRUint32 getLength() const; - String& substringData(PRInt32 aOffset, PRInt32 aCount, String& aDest); + String& substringData(PRUint32 aOffset, PRUint32 aCount, String& aDest); void appendData(const String& aSource); - void insertData(PRInt32 aOffset, const String& aSource); - void deleteData(PRInt32 aOffset, PRInt32 aCount); - void replaceData(PRInt32 aOffset, PRInt32 aCount, const String& aSource); + void insertData(PRUint32 aOffset, const String& aSource); + void deleteData(PRUint32 aOffset, PRUint32 aCount); + void replaceData(PRUint32 aOffset, PRUint32 aCount, const String& aSource); private: String nodeValue; @@ -492,7 +492,7 @@ class Text : public CharacterData Text(nsIDOMText* aText, Document* aOwner); ~Text(); - Text* splitText(PRInt32 aOffset); + Text* splitText(PRUint32 aOffset); }; /* diff --git a/extensions/transformiix/source/xml/dom/standalone/Attr.cpp b/extensions/transformiix/source/xml/dom/standalone/Attr.cpp index e4fc8580f14..d5b98eb80d2 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Attr.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Attr.cpp @@ -38,7 +38,7 @@ Attr::Attr(const String& name, Document* owner): specified = MB_FALSE; int idx = nodeName.indexOf(':'); - if (idx == NOT_FOUND) { + if (idx == kNotFound) { mLocalName = TX_GET_ATOM(nodeName); if (mLocalName == txXMLAtoms::xmlns) mNamespaceID = kNameSpaceID_XMLNS; diff --git a/extensions/transformiix/source/xml/dom/standalone/CDATASection.cpp b/extensions/transformiix/source/xml/dom/standalone/CDATASection.cpp index fa5589ea507..be0c73957ed 100644 --- a/extensions/transformiix/source/xml/dom/standalone/CDATASection.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/CDATASection.cpp @@ -34,7 +34,7 @@ //Construct a text object with the specified document owner and data // CDATASection::CDATASection(const String& theData, Document* owner) : - Text(Node::CDATA_SECTION_NODE, "#cdata-section", theData, owner) + Text(Node::CDATA_SECTION_NODE, String("#cdata-section"), theData, owner) { } diff --git a/extensions/transformiix/source/xml/dom/standalone/CharacterData.cpp b/extensions/transformiix/source/xml/dom/standalone/CharacterData.cpp index 243430eb206..52dd2810159 100644 --- a/extensions/transformiix/source/xml/dom/standalone/CharacterData.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/CharacterData.cpp @@ -58,7 +58,7 @@ void CharacterData::setData(const String& source) // //Returns the length of the data object. // -PRInt32 CharacterData::getLength() const +PRUint32 CharacterData::getLength() const { return nodeValue.length(); } @@ -68,9 +68,9 @@ PRInt32 CharacterData::getLength() const //characters away. // NOTE: An empty string will be returned in the event of an error. // -String& CharacterData::substringData(PRInt32 offset, PRInt32 count, String& dest) +String& CharacterData::substringData(PRUint32 offset, PRUint32 count, String& dest) { - if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0)) + if ((offset < nodeValue.length()) && (count > 0)) return nodeValue.subString(offset, offset+count, dest); else { @@ -84,23 +84,23 @@ void CharacterData::appendData(const String& arg) nodeValue.append(arg); } -void CharacterData::insertData(PRInt32 offset, const String& arg) +void CharacterData::insertData(PRUint32 offset, const String& arg) { - if ((offset >= 0) && (offset < nodeValue.length())) + if (offset < nodeValue.length()) nodeValue.insert(offset, arg); } -void CharacterData::deleteData(PRInt32 offset, PRInt32 count) +void CharacterData::deleteData(PRUint32 offset, PRUint32 count) { - if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0)) + if ((offset < nodeValue.length()) && (count > 0)) nodeValue.deleteChars(offset, count); } -void CharacterData::replaceData(PRInt32 offset, PRInt32 count, const String& arg) +void CharacterData::replaceData(PRUint32 offset, PRUint32 count, const String& arg) { String tempString; - if ((offset >= 0) && (offset < nodeValue.length()) && (count > 0)) + if ((offset < nodeValue.length()) && (count > 0)) { if (count < arg.length()) { diff --git a/extensions/transformiix/source/xml/dom/standalone/Comment.cpp b/extensions/transformiix/source/xml/dom/standalone/Comment.cpp index 9a5994bb51f..1d0fd67885b 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Comment.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Comment.cpp @@ -34,7 +34,7 @@ //Construct a text object with the specified document owner and data // Comment::Comment(const String& theData, Document* owner) : - CharacterData(Node::COMMENT_NODE, "#comment", theData, owner) + CharacterData(Node::COMMENT_NODE, String("#comment"), theData, owner) { } diff --git a/extensions/transformiix/source/xml/dom/standalone/DOMImplementation.cpp b/extensions/transformiix/source/xml/dom/standalone/DOMImplementation.cpp index bbef8c58e11..e887c764de4 100644 --- a/extensions/transformiix/source/xml/dom/standalone/DOMImplementation.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/DOMImplementation.cpp @@ -30,10 +30,9 @@ #include "dom.h" -DOMImplementation::DOMImplementation() +DOMImplementation::DOMImplementation() : implFeature("XML"), + implVersion("1.0") { - implFeature = "XML"; - implVersion = "1.0"; } DOMImplementation::~DOMImplementation() @@ -45,7 +44,7 @@ DOMImplementation::~DOMImplementation() //functionality of this DOM implementation/version. // MBool DOMImplementation::hasFeature(String feature, - const String& version) const + const String& version) const { feature.toUpperCase(); diff --git a/extensions/transformiix/source/xml/dom/standalone/Document.cpp b/extensions/transformiix/source/xml/dom/standalone/Document.cpp index 68ffd75f69a..678ee48fa23 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Document.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Document.cpp @@ -38,7 +38,7 @@ //node constructor is called to identify the node type. // Document::Document(DocumentType* theDoctype) : - NodeDefinition(Node::DOCUMENT_NODE, "#document", NULL_STRING, NULL) + NodeDefinition(Node::DOCUMENT_NODE, String("#document"), NULL_STRING, NULL) { documentElement = NULL; doctype = theDoctype; @@ -195,7 +195,7 @@ Node* Document::removeChild(Node* oldChild) // DocumentFragment* Document::createDocumentFragment() { - return new DocumentFragment("#document-fragment", NULL_STRING, this); + return new DocumentFragment(String("#document-fragment"), NULL_STRING, this); } // diff --git a/extensions/transformiix/source/xml/dom/standalone/Element.cpp b/extensions/transformiix/source/xml/dom/standalone/Element.cpp index 53819ab8e38..7beb0ba6f23 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Element.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Element.cpp @@ -41,7 +41,7 @@ Element::Element(const String& tagName, Document* owner) : mNamespaceID = kNameSpaceID_Unknown; int idx = nodeName.indexOf(':'); - if (idx == NOT_FOUND) { + if (idx == kNotFound) { mLocalName = TX_GET_ATOM(nodeName); } else { @@ -93,7 +93,7 @@ PRInt32 Element::getNamespaceID() if (mNamespaceID>=0) return mNamespaceID; int idx = nodeName.indexOf(':'); - if (idx == NOT_FOUND) { + if (idx == kNotFound) { Node* node = this; while (node && node->getNodeType() == Node::ELEMENT_NODE) { String nsURI; diff --git a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp b/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp index 0e32573ea8b..f7efba7a96f 100644 --- a/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/NodeDefinition.cpp @@ -399,7 +399,7 @@ PRInt32 NodeDefinition::lookupNamespaceID(txAtom* aPrefix) else { // No prefix, look up the default namespace by searching for xmlns // attributes. Remove the trailing :, set length to 5 (xmlns). - name.setLength(5); + name.truncate(5); } Attr* xmlns; while (node && node->getNodeType() == Node::ELEMENT_NODE) { diff --git a/extensions/transformiix/source/xml/dom/standalone/Text.cpp b/extensions/transformiix/source/xml/dom/standalone/Text.cpp index 3d22c06e8aa..617079e3f19 100644 --- a/extensions/transformiix/source/xml/dom/standalone/Text.cpp +++ b/extensions/transformiix/source/xml/dom/standalone/Text.cpp @@ -34,7 +34,7 @@ //Construct a text object with the specified document owner and data // Text::Text(const String& theData, Document* owner) : - CharacterData(Node::TEXT_NODE, "#text", theData, owner) + CharacterData(Node::TEXT_NODE, String("#text"), theData, owner) { } @@ -52,12 +52,12 @@ Text::Text(NodeType type, const String& name, const String& value, //Split the text node at Offset into two siblings. Return a pointer to the new //sibling. // -Text* Text::splitText(PRInt32 offset) +Text* Text::splitText(PRUint32 offset) { Text* newTextSibling = NULL; String newData; - if ((offset >= 0) && (offset < nodeValue.length())) + if (offset < nodeValue.length()) { newTextSibling = getOwnerDocument()->createTextNode(nodeValue.subString(offset, newData)); getParentNode()->insertBefore(newTextSibling, getNextSibling()); diff --git a/extensions/transformiix/source/xml/dom/standalone/dom.h b/extensions/transformiix/source/xml/dom/standalone/dom.h index 51b8a72f3a4..b524aff0e98 100644 --- a/extensions/transformiix/source/xml/dom/standalone/dom.h +++ b/extensions/transformiix/source/xml/dom/standalone/dom.h @@ -510,13 +510,13 @@ class CharacterData : public NodeDefinition public: const String& getData() const; void setData(const String& source); - PRInt32 getLength() const; + PRUint32 getLength() const; - String& substringData(PRInt32 offset, PRInt32 count, String& dest); + String& substringData(PRUint32 offset, PRUint32 count, String& dest); void appendData(const String& arg); - void insertData(PRInt32 offset, const String& arg); - void deleteData(PRInt32 offset, PRInt32 count); - void replaceData(PRInt32 offset, PRInt32 count, const String& arg); + void insertData(PRUint32 offset, const String& arg); + void deleteData(PRUint32 offset, PRUint32 count); + void replaceData(PRUint32 offset, PRUint32 count, const String& arg); protected: CharacterData(NodeType type, const String& name, @@ -532,7 +532,7 @@ class Text : public CharacterData public: Text(const String& theData, Document* owner); - Text* splitText(PRInt32 offset); + Text* splitText(PRUint32 offset); //Override "child manipulation" function since Text Nodes can not have //any children. diff --git a/extensions/transformiix/source/xml/parser/XMLParser.cpp b/extensions/transformiix/source/xml/parser/XMLParser.cpp index 345f1a1d9d7..6b9ae3a17f7 100644 --- a/extensions/transformiix/source/xml/parser/XMLParser.cpp +++ b/extensions/transformiix/source/xml/parser/XMLParser.cpp @@ -168,8 +168,6 @@ void startElement(void *userData, const XML_Char *name, const XML_Char **atts) { ParserState* ps = (ParserState*)userData; Element* newElement; - XML_Char* attName; - XML_Char* attValue; XML_Char** theAtts = (XML_Char**)atts; String nodeName((UNICODE_CHAR *)name); @@ -177,9 +175,9 @@ void startElement(void *userData, const XML_Char *name, const XML_Char **atts) while (*theAtts) { - attName = *theAtts++; - attValue = *theAtts++; - newElement->setAttribute((UNICODE_CHAR *)attName, (UNICODE_CHAR *)attValue); + String attName((UNICODE_CHAR *)*theAtts++); + String attValue((UNICODE_CHAR *)*theAtts++); + newElement->setAttribute(attName, attValue); } ps->currentNode->appendChild(newElement); @@ -197,8 +195,7 @@ void endElement(void *userData, const XML_Char* name) void charData(void* userData, const XML_Char* s, int len) { ParserState* ps = (ParserState*)userData; - String data; - data.append((UNICODE_CHAR*)s, len); + String data((UNICODE_CHAR*)s, len); Node* prevSib = ps->currentNode->getLastChild(); if (prevSib && prevSib->getNodeType()==Node::TEXT_NODE){ ((CharacterData*)prevSib)->appendData(data); diff --git a/extensions/transformiix/source/xpath/ExprLexer.cpp b/extensions/transformiix/source/xpath/ExprLexer.cpp index 318ef87a001..ba9c764d677 100644 --- a/extensions/transformiix/source/xpath/ExprLexer.cpp +++ b/extensions/transformiix/source/xpath/ExprLexer.cpp @@ -107,30 +107,30 @@ Token::~Token() * Complex Tokens */ //-- Nodetype tokens -const String ExprLexer::COMMENT = "comment"; -const String ExprLexer::NODE = "node"; -const String ExprLexer::PROC_INST = "processing-instruction"; -const String ExprLexer::TEXT = "text"; +const String ExprLexer::COMMENT("comment"); +const String ExprLexer::NODE("node"); +const String ExprLexer::PROC_INST("processing-instruction"); +const String ExprLexer::TEXT("text"); //-- boolean -const String ExprLexer::AND = "and"; -const String ExprLexer::OR = "or"; +const String ExprLexer::AND("and"); +const String ExprLexer::OR("or"); //-- multiplicative operators -const String ExprLexer::MODULUS = "mod"; -const String ExprLexer::DIVIDE = "div"; +const String ExprLexer::MODULUS("mod"); +const String ExprLexer::DIVIDE("div"); /** * The set of Lexer error messages **/ const String ExprLexer::error_message[] = { - "VariableReference expected", - "Operator expected", - "Literal is not closed", - ": not expected", - "! not expected, use != or not()", - "found a unkown character" + String("VariableReference expected"), + String("Operator expected"), + String("Literal is not closed"), + String(": not expected"), + String("! not expected, use != or not()"), + String("found a unkown character") }; //---------------/ @@ -238,8 +238,8 @@ void ExprLexer::parse(const String& pattern) return; String tokenBuffer; - PRInt32 iter = 0, start; - PRInt32 size = pattern.length(); + PRUint32 iter = 0, start; + PRUint32 size = pattern.length(); short defType; UNICODE_CHAR ch; @@ -278,8 +278,8 @@ void ExprLexer::parse(const String& pattern) start = iter; while (++iter < size && XMLUtils::isNCNameChar(pattern.charAt(iter))) /* just go */ ; - PRInt32 end = iter; - if (pattern.charAt(iter)==COLON) { + PRUint32 end = iter; + if (iter < size && pattern.charAt(iter)==COLON) { // try QName or wildcard, might need to step back for axis if (++iter < size) if (XMLUtils::isLetter(pattern.charAt(iter))) @@ -319,7 +319,7 @@ void ExprLexer::parse(const String& pattern) start = iter; while (++iter < size && isXPathDigit(pattern.charAt(iter))) /* just go */; - if (pattern.charAt(iter)=='.') + 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)); @@ -336,8 +336,8 @@ void ExprLexer::parse(const String& pattern) case S_QUOTE : case D_QUOTE : start=iter; - iter = pattern.indexOf(ch,start+1); - if (iter==NOT_FOUND) { + iter = pattern.indexOf(ch, (PRInt32)start + 1); + if (iter == kNotFound) { // XXX Error reporting "unclosed literal" errorPos = start; errorCode = ERROR_UNCLOSED_LITERAL; diff --git a/extensions/transformiix/source/xpath/ExprLexer.h b/extensions/transformiix/source/xpath/ExprLexer.h index 4e951a8ac60..10d5db81eed 100644 --- a/extensions/transformiix/source/xpath/ExprLexer.h +++ b/extensions/transformiix/source/xpath/ExprLexer.h @@ -182,7 +182,7 @@ public: ERROR_UNKNOWN_CHAR }; static const String error_message[]; - PRInt32 errorPos; + PRUint32 errorPos; short errorCode; /* diff --git a/extensions/transformiix/source/xpath/ExprParser.cpp b/extensions/transformiix/source/xpath/ExprParser.cpp index a3949738d6d..8bf2c8a8729 100644 --- a/extensions/transformiix/source/xpath/ExprParser.cpp +++ b/extensions/transformiix/source/xpath/ExprParser.cpp @@ -56,8 +56,8 @@ AttributeValueTemplate* ExprParser::createAttributeValueTemplate if (attValue.isEmpty()) return avt; //XXX should return 0, but that causes crash in lre12 - PRInt32 size = attValue.length(); - int cc = 0; + PRUint32 size = attValue.length(); + PRUint32 cc = 0; UNICODE_CHAR nextCh; UNICODE_CHAR ch; String buffer; @@ -956,14 +956,14 @@ nsresult ExprParser::resolveQName(const String& aQName, { aNamespace = kNameSpaceID_None; String prefix, lName; - int idx = aQName.indexOf(':'); + PRInt32 idx = aQName.indexOf(':'); if (idx > 0) { - aQName.subString(0, idx, prefix); + aQName.subString(0, (PRUint32)idx, prefix); aPrefix = TX_GET_ATOM(prefix); if (!aPrefix) { return NS_ERROR_OUT_OF_MEMORY; } - aQName.subString(idx + 1, lName); + aQName.subString((PRUint32)idx + 1, lName); aLocalName = TX_GET_ATOM(lName); if (!aLocalName) { TX_RELEASE_ATOM(aPrefix); diff --git a/extensions/transformiix/source/xpath/FunctionCall.cpp b/extensions/transformiix/source/xpath/FunctionCall.cpp index 30eb1280f71..aea6e4c8c86 100644 --- a/extensions/transformiix/source/xpath/FunctionCall.cpp +++ b/extensions/transformiix/source/xpath/FunctionCall.cpp @@ -30,19 +30,19 @@ * This class represents a FunctionCall as defined by the XSL Working Draft **/ -const String FunctionCall::INVALID_PARAM_COUNT = - "invalid number of parameters for function: "; +const String FunctionCall::INVALID_PARAM_COUNT( + "invalid number of parameters for function: "); -const String FunctionCall::INVALID_PARAM_VALUE = - "invalid parameter value for function: "; +const String FunctionCall::INVALID_PARAM_VALUE( + "invalid parameter value for function: "); //- Constructors -/ /** * Creates a new FunctionCall **/ -FunctionCall::FunctionCall() { - this->name = "void"; +FunctionCall::FunctionCall() : name("void") +{ } //-- FunctionCall /** diff --git a/extensions/transformiix/source/xpath/FunctionLib.h b/extensions/transformiix/source/xpath/FunctionLib.h index 580863ee0ec..54c631e5f34 100644 --- a/extensions/transformiix/source/xpath/FunctionLib.h +++ b/extensions/transformiix/source/xpath/FunctionLib.h @@ -72,13 +72,6 @@ static const String NUMBER_FN; static const String ROUND_FN; static const String CEILING_FN; static const String FLOOR_FN; -// OG- - - -//-- internal XSL processor functions -static const String ERROR_FN; - - }; //-- XPathNames diff --git a/extensions/transformiix/source/xpath/PathExpr.cpp b/extensions/transformiix/source/xpath/PathExpr.cpp index 79a5781dda4..fe907eedf59 100644 --- a/extensions/transformiix/source/xpath/PathExpr.cpp +++ b/extensions/transformiix/source/xpath/PathExpr.cpp @@ -40,10 +40,10 @@ //- PathExpr -/ //------------/ -const String PathExpr::RTF_INVALID_OP = - "Result tree fragments don't allow location steps"; -const String PathExpr::NODESET_EXPECTED = - "Filter expression must evaluate to a NodeSet"; +const String PathExpr::RTF_INVALID_OP( + "Result tree fragments don't allow location steps"); +const String PathExpr::NODESET_EXPECTED( + "Filter expression must evaluate to a NodeSet"); /** * Creates a new PathExpr @@ -177,7 +177,7 @@ void PathExpr::evalDescendants (Expr* aStep, Node* aNode, if (!(filterWS && (child->getNodeType() == Node::TEXT_NODE || child->getNodeType() == Node::CDATA_SECTION_NODE) && - XMLUtils::shouldStripTextnode(child->getNodeValue()))) + XMLUtils::isWhitespace(child->getNodeValue()))) evalDescendants(aStep, child, aContext, resNodes); child = child->getNextSibling(); } diff --git a/extensions/transformiix/source/xpath/StringExpr.cpp b/extensions/transformiix/source/xpath/StringExpr.cpp index 522c13c147e..e7096ee3dc3 100644 --- a/extensions/transformiix/source/xpath/StringExpr.cpp +++ b/extensions/transformiix/source/xpath/StringExpr.cpp @@ -59,7 +59,7 @@ ExprResult* StringExpr::evaluate(txIEvalContext* aContext) **/ void StringExpr::toString(String& str) { UNICODE_CHAR ch = '\''; - if (value.indexOf(ch) != NOT_FOUND) + if (value.indexOf(ch) != kNotFound) ch = '\"'; str.append(ch); str.append(value); diff --git a/extensions/transformiix/source/xpath/StringFunctionCall.cpp b/extensions/transformiix/source/xpath/StringFunctionCall.cpp index 1053b2eb22a..a1a5132a5f7 100644 --- a/extensions/transformiix/source/xpath/StringFunctionCall.cpp +++ b/extensions/transformiix/source/xpath/StringFunctionCall.cpp @@ -31,6 +31,7 @@ #include "FunctionLib.h" #include "XMLDOMUtils.h" +#include "XMLUtils.h" #include "txIXPathContext.h" #include @@ -118,11 +119,10 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) MBool first = MB_TRUE; String normed(resultStr.length()); UNICODE_CHAR c; - PRInt32 src; + PRUint32 src; for (src = 0; src < resultStr.length(); src++) { c = resultStr.charAt(src); - if (c == ' ' || c == '\n' || - c == '\t' || c == '\r') { + if (XMLUtils::isWhitespace(c)) { addSpace = MB_TRUE; } else { @@ -198,7 +198,7 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) return new StringResult(); String resultStr; - src.subString((PRInt32)start, (PRInt32)end, resultStr); + src.subString((PRUint32)start, (PRUint32)end, resultStr); return new StringResult(resultStr); } case SUBSTRING_AFTER: @@ -210,8 +210,8 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) evaluateToString((Expr*)iter.next(), aContext, arg1); evaluateToString((Expr*)iter.next(), aContext, arg2); PRInt32 idx = arg1.indexOf(arg2); - if (idx >= 0) { - PRInt32 len = arg2.length(); + if (idx != kNotFound) { + PRUint32 len = arg2.length(); arg1.subString(idx + len, arg2); return new StringResult(arg2); } @@ -226,7 +226,7 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) evaluateToString((Expr*)iter.next(), aContext, arg1); evaluateToString((Expr*)iter.next(), aContext, arg2); PRInt32 idx = arg1.indexOf(arg2); - if (idx >= 0) { + if (idx != kNotFound) { arg2.clear(); arg1.subString(0, idx, arg2); return new StringResult(arg2); @@ -246,12 +246,12 @@ ExprResult* StringFunctionCall::evaluate(txIEvalContext* aContext) String oldChars, newChars, dest; evaluateToString((Expr*)iter.next(), aContext, oldChars); evaluateToString((Expr*)iter.next(), aContext, newChars); - PRInt32 i; + PRUint32 i; for (i = 0; i < src.length(); i++) { PRInt32 idx = oldChars.indexOf(src.charAt(i)); - if (idx >= 0) { + if (idx != kNotFound) { if (idx < newChars.length()) - dest.append(newChars.charAt(idx)); + dest.append(newChars.charAt((PRUint32)idx)); } else { dest.append(src.charAt(i)); diff --git a/extensions/transformiix/source/xpath/StringResult.cpp b/extensions/transformiix/source/xpath/StringResult.cpp index 2edd0b120fb..43110fab469 100644 --- a/extensions/transformiix/source/xpath/StringResult.cpp +++ b/extensions/transformiix/source/xpath/StringResult.cpp @@ -51,7 +51,7 @@ StringResult::StringResult(const String& str) { **/ StringResult::StringResult(const char* str) { //-- copy str - this->value = str; + this->value.append(str); } //-- StringResult /* diff --git a/extensions/transformiix/source/xpath/XPathNames.cpp b/extensions/transformiix/source/xpath/XPathNames.cpp index 35f2ee08c10..e69de29bb2d 100644 --- a/extensions/transformiix/source/xpath/XPathNames.cpp +++ b/extensions/transformiix/source/xpath/XPathNames.cpp @@ -1,69 +0,0 @@ -/* - * 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. - * - * Marina Mechtcheriakova, mmarina@mindspring.com - * -- added LANG_FN - * - */ - -/** - * XPath names -**/ - -#include "FunctionLib.h" - -//-- Function Names -const String XPathNames::BOOLEAN_FN = "boolean"; -const String XPathNames::CONCAT_FN = "concat"; -const String XPathNames::CONTAINS_FN = "contains"; -const String XPathNames::COUNT_FN = "count"; -const String XPathNames::FALSE_FN = "false"; -const String XPathNames::ID_FN = "id"; -const String XPathNames::LAST_FN = "last"; -const String XPathNames::LOCAL_NAME_FN = "local-name"; -const String XPathNames::NAME_FN = "name"; -const String XPathNames::NAMESPACE_URI_FN = "namespace-uri"; -const String XPathNames::NORMALIZE_SPACE_FN = "normalize-space"; -const String XPathNames::NOT_FN = "not"; -const String XPathNames::POSITION_FN = "position"; -const String XPathNames::STARTS_WITH_FN = "starts-with"; -const String XPathNames::STRING_FN = "string"; -const String XPathNames::STRING_LENGTH_FN = "string-length"; -const String XPathNames::SUBSTRING_FN = "substring"; -const String XPathNames::SUBSTRING_AFTER_FN = "substring-after"; -const String XPathNames::SUBSTRING_BEFORE_FN = "substring-before"; -const String XPathNames::SUM_FN = "sum"; -const String XPathNames::TRANSLATE_FN = "translate"; -const String XPathNames::TRUE_FN = "true"; -// OG+ -const String XPathNames::NUMBER_FN = "number"; -const String XPathNames::ROUND_FN = "round"; -const String XPathNames::CEILING_FN = "ceiling"; -const String XPathNames::FLOOR_FN = "floor"; -// OG- -//Marina M. boolean function lang -const String XPathNames::LANG_FN = "lang"; - -//-- internal XSL processor functions -const String XPathNames::ERROR_FN = "error"; - diff --git a/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp b/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp index 7b34b1f4885..edbad45cd1a 100644 --- a/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp +++ b/extensions/transformiix/source/xpath/nsXPathEvaluator.cpp @@ -70,7 +70,7 @@ nsXPathEvaluator::CreateExpression(const nsAString & aExpression, nsIDOMXPathNSResolver *aResolver, nsIDOMXPathExpression **aResult) { - String expressionString(PromiseFlatString(aExpression).get()); + String expressionString(aExpression); ParseContextImpl pContext(aResolver); Expr* expression = ExprParser::createExpr(expressionString, &pContext); if (!expression) diff --git a/extensions/transformiix/source/xslt/Names.cpp b/extensions/transformiix/source/xslt/Names.cpp index 1b01039f154..06cefd8d3f1 100644 --- a/extensions/transformiix/source/xslt/Names.cpp +++ b/extensions/transformiix/source/xslt/Names.cpp @@ -37,107 +37,107 @@ #include "Names.h" //-- Global Strings -const String HTML = "html"; -const String HTML_NS = "http://www.w3.org/1999/xhtml"; -const String STYLESHEET_PI = "xml-stylesheet"; -const String STYLESHEET_PI_OLD = "xml:stylesheet"; -const String XML_SPACE = "xml:space"; -const String XSL_MIME_TYPE = "text/xsl"; -const String XSLT_NS = "http://www.w3.org/1999/XSL/Transform"; +const String HTML("html"); +const String HTML_NS("http://www.w3.org/1999/xhtml"); +const String STYLESHEET_PI("xml-stylesheet"); +const String STYLESHEET_PI_OLD("xml:stylesheet"); +const String XML_SPACE("xml:space"); +const String XSL_MIME_TYPE("text/xsl"); +const String XSLT_NS("http://www.w3.org/1999/XSL/Transform"); //-- Elements -const String APPLY_IMPORTS = "apply-imports"; -const String APPLY_TEMPLATES = "apply-templates"; -const String ATTRIBUTE = "attribute"; -const String ATTRIBUTE_SET = "attribute-set"; -const String CALL_TEMPLATE = "call-template"; -const String CHOOSE = "choose"; -const String COMMENT = "comment"; -const String COPY = "copy"; -const String COPY_OF = "copy-of"; -const String DECIMAL_FORMAT = "decimal-format"; -const String ELEMENT = "element"; -const String FOR_EACH = "for-each"; -const String IF = "if"; -const String IMPORT = "import"; -const String INCLUDE = "include"; -const String KEY = "key"; -const String MESSAGE = "message"; -const String NUMBER = "number"; -const String OTHERWISE = "otherwise"; -const String OUTPUT = "output"; -const String PARAM = "param"; -const String PROC_INST = "processing-instruction"; -const String PRESERVE_SPACE = "preserve-space"; -const String SORT = "sort"; -const String STRIP_SPACE = "strip-space"; -const String TEMPLATE = "template"; -const String TEXT = "text"; -const String VALUE_OF = "value-of"; -const String VARIABLE = "variable"; -const String WHEN = "when"; -const String WITH_PARAM = "with-param"; +const String APPLY_IMPORTS("apply-imports"); +const String APPLY_TEMPLATES("apply-templates"); +const String ATTRIBUTE("attribute"); +const String ATTRIBUTE_SET("attribute-set"); +const String CALL_TEMPLATE("call-template"); +const String CHOOSE("choose"); +const String COMMENT("comment"); +const String COPY("copy"); +const String COPY_OF("copy-of"); +const String DECIMAL_FORMAT("decimal-format"); +const String ELEMENT("element"); +const String FOR_EACH("for-each"); +const String IF("if"); +const String IMPORT("import"); +const String INCLUDE("include"); +const String KEY("key"); +const String MESSAGE("message"); +const String NUMBER("number"); +const String OTHERWISE("otherwise"); +const String OUTPUT("output"); +const String PARAM("param"); +const String PROC_INST("processing-instruction"); +const String PRESERVE_SPACE("preserve-space"); +const String SORT("sort"); +const String STRIP_SPACE("strip-space"); +const String TEMPLATE("template"); +const String TEXT("text"); +const String VALUE_OF("value-of"); +const String VARIABLE("variable"); +const String WHEN("when"); +const String WITH_PARAM("with-param"); //-- Attributes -const String ELEMENTS_ATTR = "elements"; -const String HREF_ATTR = "href"; -const String MATCH_ATTR = "match"; -const String MODE_ATTR = "mode"; -const String NAME_ATTR = "name"; -const String SELECT_ATTR = "select"; -const String TEST_ATTR = "test"; -const String USE_ATTR = "use"; +const String ELEMENTS_ATTR("elements"); +const String HREF_ATTR("href"); +const String MATCH_ATTR("match"); +const String MODE_ATTR("mode"); +const String NAME_ATTR("name"); +const String SELECT_ATTR("select"); +const String TEST_ATTR("test"); +const String USE_ATTR("use"); //-- Attribute Values -const String ANY_VALUE = "any"; -const String ASCENDING_VALUE = "ascending"; -const String DESCENDING_VALUE = "descending"; -const String LOWER_FIRST_VALUE = "lower-first"; -const String MULTIPLE_VALUE = "multiple"; -const String NO_VALUE = "no"; -const String NUMBER_VALUE = "number"; -const String PRESERVE_VALUE = "preserve"; -const String SINGLE_VALUE = "single"; -const String STRIP_VALUE = "strip"; -const String TEXT_VALUE = "text"; -const String UPPER_FIRST_VALUE = "upper-first"; -const String YES_VALUE = "yes"; +const String ANY_VALUE("any"); +const String ASCENDING_VALUE("ascending"); +const String DESCENDING_VALUE("descending"); +const String LOWER_FIRST_VALUE("lower-first"); +const String MULTIPLE_VALUE("multiple"); +const String NO_VALUE("no"); +const String NUMBER_VALUE("number"); +const String PRESERVE_VALUE("preserve"); +const String SINGLE_VALUE("single"); +const String STRIP_VALUE("strip"); +const String TEXT_VALUE("text"); +const String UPPER_FIRST_VALUE("upper-first"); +const String YES_VALUE("yes"); //-- Stylesheet attributes -const String ANCESTOR_AXIS = "ancestor"; -const String ANCESTOR_OR_SELF_AXIS = "ancestor-or-self"; -const String ATTRIBUTE_AXIS = "attribute"; -const String CHILD_AXIS = "child"; -const String DESCENDANT_AXIS = "descendant"; -const String DESCENDANT_OR_SELF_AXIS = "descendant-or-self"; -const String FOLLOWING_AXIS = "following"; -const String FOLLOWING_SIBLING_AXIS = "following-sibling"; -const String NAMESPACE_AXIS = "namespace"; -const String PARENT_AXIS = "parent"; -const String PRECEDING_AXIS = "preceding"; -const String PRECEDING_SIBLING_AXIS = "preceding-sibling"; -const String SELF_AXIS = "self"; +const String ANCESTOR_AXIS("ancestor"); +const String ANCESTOR_OR_SELF_AXIS("ancestor-or-self"); +const String ATTRIBUTE_AXIS("attribute"); +const String CHILD_AXIS("child"); +const String DESCENDANT_AXIS("descendant"); +const String DESCENDANT_OR_SELF_AXIS("descendant-or-self"); +const String FOLLOWING_AXIS("following"); +const String FOLLOWING_SIBLING_AXIS("following-sibling"); +const String NAMESPACE_AXIS("namespace"); +const String PARENT_AXIS("parent"); +const String PRECEDING_AXIS("preceding"); +const String PRECEDING_SIBLING_AXIS("preceding-sibling"); +const String SELF_AXIS("self"); //-- NodeTest Operators -const String ATTRIBUTE_FNAME = "@"; -const String COMMENT_FNAME = "comment"; -const String PI_FNAME = "processing-instruction"; -const String TEXT_FNAME = "text"; -const String NODE_FNAME = "node"; -const String IDENTITY_OP = "."; -const String PARENT_OP = ".."; +const String ATTRIBUTE_FNAME("@"); +const String COMMENT_FNAME("comment"); +const String PI_FNAME("processing-instruction"); +const String TEXT_FNAME("text"); +const String NODE_FNAME("node"); +const String IDENTITY_OP("."); +const String PARENT_OP(".."); //-- XSLT additional functions -const String DOCUMENT_FN = "document"; -const String KEY_FN = "key"; -const String FORMAT_NUMBER_FN = "format-number"; -const String CURRENT_FN = "current"; -const String UNPARSED_ENTITY_URI_FN = "unparsed-entity-uri"; -const String GENERATE_ID_FN = "generate-id"; -const String SYSTEM_PROPERTY_FN = "system-property"; -const String ELEMENT_AVAILABLE_FN = "element-available"; -const String FUNCTION_AVAILABLE_FN = "function-available"; +const String DOCUMENT_FN("document"); +const String KEY_FN("key"); +const String FORMAT_NUMBER_FN("format-number"); +const String CURRENT_FN("current"); +const String UNPARSED_ENTITY_URI_FN("unparsed-entity-uri"); +const String GENERATE_ID_FN("generate-id"); +const String SYSTEM_PROPERTY_FN("system-property"); +const String ELEMENT_AVAILABLE_FN("element-available"); +const String FUNCTION_AVAILABLE_FN("function-available"); //-- MISC -const String WILD_CARD = "*"; +const String WILD_CARD("*"); diff --git a/extensions/transformiix/source/xslt/ProcessorState.cpp b/extensions/transformiix/source/xslt/ProcessorState.cpp index dfcc1146e64..fef4bc467f0 100644 --- a/extensions/transformiix/source/xslt/ProcessorState.cpp +++ b/extensions/transformiix/source/xslt/ProcessorState.cpp @@ -90,7 +90,7 @@ ProcessorState::ProcessorState(Document* aSourceDocument, // add predefined default decimal format defaultDecimalFormatSet = MB_FALSE; - decimalFormats.put("", new txDecimalFormat); + decimalFormats.put(String(), new txDecimalFormat); decimalFormats.setObjectDeletion(MB_TRUE); } @@ -461,19 +461,24 @@ Node* ProcessorState::findTemplate(Node* aNode, } } - #ifdef PR_LOGGING +#ifdef PR_LOGGING char *nodeBuf = 0, *modeBuf = 0; if (matchTemplate) { char *matchBuf = 0, *uriBuf = 0; PR_LOG(txLog::xslt, PR_LOG_DEBUG, ("MatchTemplate, Pattern %s, Mode %s, Stylesheet %s, " \ "Node %s\n", - (matchBuf = ((Element*)matchTemplate)->getAttribute("match").toCharArray()), + (matchBuf = ((Element*)matchTemplate)->getAttribute(String("match")).toCharArray()), (modeBuf = aMode.toCharArray()), (uriBuf = matchTemplate->getBaseURI().toCharArray()), (nodeBuf = aNode->getNodeName().toCharArray()))); - delete matchBuf; - delete uriBuf; +#ifdef TX_EXE + delete [] matchBuf; + delete [] uriBuf; +#else + nsMemory::Free(matchBuf); + nsMemory::Free(uriBuf); +#endif } else { PR_LOG(txLog::xslt, PR_LOG_DEBUG, @@ -481,9 +486,14 @@ Node* ProcessorState::findTemplate(Node* aNode, (nodeBuf = aNode->getNodeName().toCharArray()), (modeBuf = aMode.toCharArray()))); } - delete nodeBuf; - delete modeBuf; - #endif +#ifdef TX_EXE + delete [] nodeBuf; + delete [] modeBuf; +#else + nsMemory::Free(nodeBuf); + nsMemory::Free(modeBuf); +#endif +#endif return matchTemplate; } @@ -557,7 +567,7 @@ Expr* ProcessorState::getExpr(Element* aElem, ExprAttr aAttr) expr = ExprParser::createExpr(attr, &pContext); if (!expr) { - String err = "Error in parsing XPath expression: "; + String err("Error in parsing XPath expression: "); err.append(attr); receiveError(err, NS_ERROR_XPATH_PARSE_FAILED); } @@ -596,7 +606,7 @@ txPattern* ProcessorState::getPattern(Element* aElem, PatternAttr aAttr) pattern = txPatternParser::createPattern(attr, &pContext, this); if (!pattern) { - String err = "Error in parsing pattern: "; + String err("Error in parsing pattern: "); err.append(attr); receiveError(err, NS_ERROR_XPATH_PARSE_FAILED); } @@ -929,7 +939,6 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) ImportFrame* frame; txListIterator frameIter(&mImportFrames); - String name = node->getNodeName(); while ((frame = (ImportFrame*)frameIter.next())) { txListIterator iter(&frame->mWhiteNameTests); while (iter.hasNext()) { @@ -939,7 +948,7 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) } } if (mOutputFormat.mMethod == eHTMLOutput) { - String ucName = name; + String ucName = node->getNodeName(); ucName.toUpperCase(); if (ucName.isEqual("SCRIPT")) return MB_FALSE; @@ -949,7 +958,7 @@ MBool ProcessorState::isStripSpaceAllowed(Node* node) case Node::TEXT_NODE: case Node::CDATA_SECTION_NODE: { - if (!XMLUtils::shouldStripTextnode(node->getNodeValue())) + if (!XMLUtils::isWhitespace(node->getNodeValue())) return MB_FALSE; return isStripSpaceAllowed(node->getParentNode()); } diff --git a/extensions/transformiix/source/xslt/ProcessorState.h b/extensions/transformiix/source/xslt/ProcessorState.h index 0b1177d6930..03bffd09032 100644 --- a/extensions/transformiix/source/xslt/ProcessorState.h +++ b/extensions/transformiix/source/xslt/ProcessorState.h @@ -425,7 +425,7 @@ private: **/ class txNameTestItem { public: - txNameTestItem(txAtom* aPrefix, txAtom* aLocalName, PRUint32 aNSID, + txNameTestItem(txAtom* aPrefix, txAtom* aLocalName, PRInt32 aNSID, MBool stripSpace) : mNameTest(aPrefix, aLocalName, aNSID, Node::ELEMENT_NODE), mStrips(stripSpace) diff --git a/extensions/transformiix/source/xslt/XSLTProcessor.cpp b/extensions/transformiix/source/xslt/XSLTProcessor.cpp index 1ae9cc816f5..b9723b7dfbb 100644 --- a/extensions/transformiix/source/xslt/XSLTProcessor.cpp +++ b/extensions/transformiix/source/xslt/XSLTProcessor.cpp @@ -86,8 +86,8 @@ * A warning message used by all templates that do not allow non character * data to be generated **/ -const String XSLTProcessor::NON_TEXT_TEMPLATE_WARNING = -"templates for the following element are not allowed to generate non character data: "; +const String XSLTProcessor::NON_TEXT_TEMPLATE_WARNING( +"templates for the following element are not allowed to generate non character data: "); /* * Implement static variables for atomservice and dom. @@ -239,11 +239,11 @@ void XSLTProcessor::getHrefFromStylesheetPI(Document& xmlDocument, String& href) **/ void XSLTProcessor::parseStylesheetPI(String& data, String& type, String& href) { - PRInt32 size = data.length(); + PRUint32 size = data.length(); NamedMap bufferMap; - bufferMap.put("type", &type); - bufferMap.put("href", &href); - int ccount = 0; + bufferMap.put(String("type"), &type); + bufferMap.put(String("href"), &href); + PRUint32 ccount = 0; MBool inLiteral = MB_FALSE; UNICODE_CHAR matchQuote = '"'; String sink; @@ -1039,7 +1039,7 @@ void XSLTProcessor::processAction(Node* aNode, nodeType == Node::CDATA_SECTION_NODE) { const String& textValue = aXSLTAction->getNodeValue(); if (!aPs->isXSLStripSpaceAllowed(aXSLTAction) || - !XMLUtils::shouldStripTextnode(textValue)) { + !XMLUtils::isWhitespace(textValue)) { NS_ASSERTION(mResultHandler, "mResultHandler must not be NULL!"); mResultHandler->characters(textValue); } @@ -1323,8 +1323,8 @@ void XSLTProcessor::processAction(Node* aNode, String value; processChildrenAsValue(aNode, actionElement, aPs, MB_TRUE, value); PRInt32 pos = 0; - PRInt32 length = value.length(); - while ((pos = value.indexOf('-', pos)) != NOT_FOUND) { + PRUint32 length = value.length(); + while ((pos = value.indexOf('-', pos)) != kNotFound) { ++pos; if ((pos == length) || (value.charAt(pos) == '-')) value.insert(pos++, ' '); @@ -2258,7 +2258,7 @@ XSLTProcessor::startElement(ProcessorState* aPs, const String& aName, const PRIn if (format->mMethod == eMethodNotSet) { // XXX Should check for whitespace-only sibling text nodes if ((aNsID == kNameSpaceID_None) && - aName.isEqualIgnoreCase("html")) { + aName.isEqualIgnoreCase(String("html"))) { // Switch to html output mode according to the XSLT spec. format->mMethod = eHTMLOutput; #ifndef TX_EXE diff --git a/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp index 50ab9847880..659dabc7191 100644 --- a/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp +++ b/extensions/transformiix/source/xslt/functions/SystemPropertyFunctionCall.cpp @@ -3,9 +3,9 @@ #include "Names.h" #include "txIXPathContext.h" -const String XSL_VERSION_PROPERTY = "version"; -const String XSL_VENDOR_PROPERTY = "vendor"; -const String XSL_VENDOR_URL_PROPERTY = "vendor-url"; +const String XSL_VERSION_PROPERTY("version"); +const String XSL_VENDOR_PROPERTY("vendor"); +const String XSL_VENDOR_URL_PROPERTY("vendor-url"); /* Implementation of XSLT 1.0 extension function: system-property diff --git a/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp b/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp index c8a3e313152..efae7aa06ce 100644 --- a/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp +++ b/extensions/transformiix/source/xslt/functions/txFormatNumberFunctionCall.cpp @@ -119,8 +119,8 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) int multiplier=1; int groupSize=-1; - int pos=0; - int formatLen = formatStr.length(); + PRUint32 pos = 0; + PRUint32 formatLen = formatStr.length(); MBool inQuote; // Get right subexpression @@ -366,17 +366,18 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) if (groupSize < 0) groupSize = intDigits * 2; //to simplify grouping - res.setLength(res.length() + - intDigits + // integer digits - 1 + // decimal separator - maxFractionSize + // fractions - (intDigits-1)/groupSize); // group separators + // XXX We shouldn't use SetLength. + res.getNSString().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'); MBool hasFraction = MB_FALSE; - PRInt32 resPos = res.length()-1; + PRUint32 resPos = res.length()-1; // Fractions for (; i >= bufIntDigits; --i) { @@ -391,22 +392,23 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) else { digit = buf[i] - '0'; } - if (hasFraction || digit != 0 || i < bufIntDigits+minFractionSize) { hasFraction = MB_TRUE; res.replace(resPos--, (UNICODE_CHAR)(digit + format->mZeroDigit)); } else { - res.setLength(resPos--); + res.truncate(resPos--); } } // Decimal separator - if (hasFraction) + if (hasFraction) { res.replace(resPos--, format->mDecimalSeparator); - else - res.setLength(resPos--); + } + else { + res.truncate(resPos--); + } // Integer digits for (i = 0; i < intDigits; ++i) { @@ -423,15 +425,17 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) carry = digit == 0; } - if (i != 0 && i%groupSize == 0) + if (i != 0 && i%groupSize == 0) { res.replace(resPos--, format->mGroupingSeparator); + } res.replace(resPos--, (UNICODE_CHAR)(digit + format->mZeroDigit)); } if (carry) { - if (i%groupSize == 0) + if (i%groupSize == 0) { res.insert(resPos + 1, format->mGroupingSeparator); + } res.insert(resPos + 1, (UNICODE_CHAR)(1 + format->mZeroDigit)); } @@ -451,13 +455,12 @@ ExprResult* txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext) * A representation of the XSLT element */ -txDecimalFormat::txDecimalFormat() +txDecimalFormat::txDecimalFormat() : mInfinity("Infinity"), + mNaN("NaN") { mDecimalSeparator = '.'; mGroupingSeparator = ','; - mInfinity = "Infinity"; mMinusSign = '-'; - mNaN = "NaN"; mPercent = '%'; mPerMille = 0x2030; mZeroDigit = '0'; diff --git a/extensions/transformiix/source/xslt/txHTMLOutput.cpp b/extensions/transformiix/source/xslt/txHTMLOutput.cpp index 76c4b7a77af..a59b27dc47b 100644 --- a/extensions/transformiix/source/xslt/txHTMLOutput.cpp +++ b/extensions/transformiix/source/xslt/txHTMLOutput.cpp @@ -188,7 +188,7 @@ void txHTMLOutput::attribute(const String& aName, } } if (!setAtt) { - setAtt = new txAttribute(aNsID, localName, ""); + setAtt = new txAttribute(aNsID, localName, String()); setAtt->mShorthand = MB_TRUE; mAttributes.add(setAtt); } diff --git a/extensions/transformiix/source/xslt/txOutputFormat.cpp b/extensions/transformiix/source/xslt/txOutputFormat.cpp index f7e09ebae26..439369961e4 100644 --- a/extensions/transformiix/source/xslt/txOutputFormat.cpp +++ b/extensions/transformiix/source/xslt/txOutputFormat.cpp @@ -116,10 +116,10 @@ void txOutputFormat::setFromDefaults() case eXMLOutput: { if (mVersion.isEmpty()) - mVersion = "1.0"; + mVersion.append("1.0"); if (mEncoding.isEmpty()) - mEncoding = "UTF-8"; + mEncoding.append("UTF-8"); if (mOmitXMLDeclaration == eNotSet) mOmitXMLDeclaration = eFalse; @@ -128,33 +128,33 @@ void txOutputFormat::setFromDefaults() mIndent = eFalse; if (mMediaType.isEmpty()) - mMediaType = "text/xml"; + mMediaType.append("text/xml"); break; } case eHTMLOutput: { if (mVersion.isEmpty()) - mVersion = "4.0"; + mVersion.append("4.0"); if (mEncoding.isEmpty()) - mEncoding = "UTF-8"; + mEncoding.append("UTF-8"); if (mIndent == eNotSet) mIndent = eTrue; if (mMediaType.isEmpty()) - mMediaType = "text/html"; + mMediaType.append("text/html"); break; } case eTextOutput: { if (mEncoding.isEmpty()) - mEncoding = "UTF-8"; + mEncoding.append("UTF-8"); if (mMediaType.isEmpty()) - mMediaType = "text/plain"; + mMediaType.append("text/plain"); break; } diff --git a/extensions/transformiix/source/xslt/txXMLOutput.cpp b/extensions/transformiix/source/xslt/txXMLOutput.cpp index 3ad0fb6a9d4..9d4dd494a21 100644 --- a/extensions/transformiix/source/xslt/txXMLOutput.cpp +++ b/extensions/transformiix/source/xslt/txXMLOutput.cpp @@ -93,9 +93,9 @@ void txXMLOutput::characters(const String& aData) closeStartTag(MB_FALSE); if (mInCDATASection) { - PRInt32 i = 0; - PRInt32 j = 0; - PRInt32 length = aData.length(); + PRUint32 i = 0; + PRUint32 j = 0; + PRUint32 length = aData.length(); *mOut << CDATA_START; @@ -317,7 +317,7 @@ void txXMLOutput::printUTF8Char(DOM_CHAR& ch) void txXMLOutput::printUTF8Chars(const String& aData) { DOM_CHAR currChar; - PRInt32 i = 0; + PRUint32 i = 0; while (i < aData.length()) { currChar = aData.charAt(i++); @@ -329,7 +329,7 @@ void txXMLOutput::printWithXMLEntities(const String& aData, MBool aAttribute) { DOM_CHAR currChar; - PRInt32 i; + PRUint32 i; if (&aData == &NULL_STRING) return; diff --git a/extensions/transformiix/source/xslt/txXSLTPatterns.cpp b/extensions/transformiix/source/xslt/txXSLTPatterns.cpp index a5bce198cc5..0ce5f65bd2b 100644 --- a/extensions/transformiix/source/xslt/txXSLTPatterns.cpp +++ b/extensions/transformiix/source/xslt/txXSLTPatterns.cpp @@ -44,6 +44,7 @@ #include "nsReadableUtils.h" #include "nsIContent.h" #include "nsINodeInfo.h" +#include "XMLUtils.h" #endif /* @@ -317,8 +318,6 @@ void txRootPattern::toString(String& aDest) * argument. */ -#define TX_IS_WHITE(c) (c == ' ' || c == '\r' || c == '\n'|| c == '\t') - txIdPattern::txIdPattern(const String aString) { #ifdef TX_EXE @@ -330,12 +329,12 @@ txIdPattern::txIdPattern(const String aString) ids.EndReading(end); pos = begin; while (pos != end) { - while (pos != end && TX_IS_WHITE(*pos)) + while (pos != end && XMLUtils::isWhitespace(*pos)) ++pos; begin = pos; if (!mIds.IsEmpty()) mIds += PRUnichar(' '); - while (pos != end && !TX_IS_WHITE(*pos)) + while (pos != end && !XMLUtils::isWhitespace(*pos)) ++pos; mIds += Substring(begin, pos); } @@ -413,7 +412,7 @@ void txIdPattern::toString(String& aDest) #ifdef TX_EXE aDest.append(mIds); #else - aDest.append(mIds.get()); + aDest.getNSString().Append(mIds); #endif aDest.append("')"); #ifdef DEBUG diff --git a/extensions/transformiix/source/xslt/util/txNodeSorter.cpp b/extensions/transformiix/source/xslt/util/txNodeSorter.cpp index ef1167fc145..f853f11c98e 100644 --- a/extensions/transformiix/source/xslt/util/txNodeSorter.cpp +++ b/extensions/transformiix/source/xslt/util/txNodeSorter.cpp @@ -122,7 +122,7 @@ MBool txNodeSorter::addSortElement(Element* aSortElement, // Language String lang; if (!getAttrAsAVT(aSortElement, txXSLTAtoms::lang, aContext, lang)) - lang = DEFAULT_LANG; + lang.append(DEFAULT_LANG); // Case-order MBool upperFirst; diff --git a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp b/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp index ec9b3cab142..cb2632fe721 100644 --- a/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp +++ b/extensions/transformiix/source/xslt/util/txXPathResultComparator.cpp @@ -143,11 +143,11 @@ int txResultStringComparator::compareValues(TxObject* aVal1, TxObject* aVal2) StringValue* strval1 = (StringValue*)aVal1; StringValue* strval2 = (StringValue*)aVal2; #ifdef TX_EXE - PRInt32 len1 = strval1->mStr.length(); - PRInt32 len2 = strval2->mStr.length(); - PRInt32 minLength = (len1 < len2) ? len1 : len2; + PRUint32 len1 = strval1->mStr.length(); + PRUint32 len2 = strval2->mStr.length(); + PRUint32 minLength = (len1 < len2) ? len1 : len2; - PRInt32 c = 0; + PRUint32 c = 0; while (c < minLength) { UNICODE_CHAR ch1 = strval1->mStr.charAt(c); UNICODE_CHAR ch2 = strval2->mStr.charAt(c);