You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2001/01/08 19:15:31 UTC
cvs commit: xml-xalan/c/src/PlatformSupport DOMStringHelper.cpp DOMStringHelper.hpp
dbertoni 01/01/08 10:15:31
Modified: c/src/PlatformSupport DOMStringHelper.cpp
DOMStringHelper.hpp
Log:
Cleaned up and normalized code.
Revision Changes Path
1.49 +208 -453 xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp
Index: DOMStringHelper.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.cpp,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- DOMStringHelper.cpp 2000/12/06 21:16:18 1.48
+++ DOMStringHelper.cpp 2001/01/08 18:15:30 1.49
@@ -675,7 +675,7 @@
{
assert(theInputString != 0);
-#if defined(XALAN_USE_XERCES_DOMSTRING)
+#if defined(XALAN_USE_STD_STRING) && defined(XALAN_OLD_STD_STRING)
vector<XalanDOMChar> theConvertedString;
TransformString(
@@ -787,223 +787,76 @@
-template <class Type, class SizeType, class FunctionType>
-bool
-doEqualsIgnoreCase(
- const Type* theLHS,
- const Type* theRHS,
- SizeType theLength,
- FunctionType theToUpperFunction)
-{
- // Check each character, converting to uppercase
- // for the test.
- SizeType i = 0;
-
- for(; i < theLength; i++)
- {
- const Type charLHS = theLHS[i];
- const Type charRHS = theRHS[i];
-
- if (charLHS != charRHS &&
- Type(theToUpperFunction(charLHS)) != charRHS &&
- charLHS != Type(theToUpperFunction(charRHS)))
- {
- break;
- }
- }
-
- // Did we reach the end of the string?
- if (i == theLength)
- {
- return true;
- }
- else
- {
- return false;
- }
-}
-
-
-
-template <class FunctionType>
-bool
-doEqualsIgnoreCase(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS,
- FunctionType theUpperCaseFunction)
-{
- assert(theLHS != 0);
- assert(theRHS != 0);
-
- bool fResult = false;
-
- const unsigned int theLength = length(theLHS);
-
- // If they are equal, then compare
- if (theLength == length(theRHS))
- {
- fResult = doEqualsIgnoreCase(theLHS, theRHS, unsigned(theLength), theUpperCaseFunction);
- }
-
- return fResult;
-}
-
-
-
-template <class FunctionType>
-bool
-doEqualsIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS,
- FunctionType theUpperCaseFunction)
+template <class InputCharType, class OutputCharType>
+class IdentityTransform
{
- const bool fLHSIsEmpty = isEmpty(theLHS);
- const bool fRHSIsEmpty = isEmpty(theRHS);
+public:
- if (fLHSIsEmpty == true)
- {
- // If theRHS is empty, then they're equal, or if the
- // length of theRHS is 0, they're equal as well.
- return fRHSIsEmpty == true ? true : length(theRHS) == 0 ? true : false;
- }
- else if (fRHSIsEmpty == true)
- {
- // It the length of theRHS is 0, they're equal.
- return length(theLHS) == 0 ? true : false;
- }
- else
+ OutputCharType
+ operator()(InputCharType theChar) const
{
- assert(c_wstr(theLHS) != 0);
- assert(c_wstr(theRHS) != 0);
-
- unsigned const int theLHSLength = length(theLHS);
-
- if (theLHSLength == length(theRHS))
- {
- return doEqualsIgnoreCase(c_wstr(theLHS), c_wstr(theRHS), unsigned(theLHSLength), theUpperCaseFunction);
- }
- else
- {
- return false;
- }
+ return OutputCharType(theChar);
}
-}
-
-
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCase(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
-{
- return doEqualsIgnoreCase(theLHS, theRHS, towupper);
-}
-
-
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCase(
- const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS)
-{
- const XalanDOMChar* const theBuffer =
- c_wstr(theRHS);
-
- return equalsIgnoreCase(theLHS, theBuffer == 0 ? &theDummyEmptyString : theBuffer);
-}
-
-
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
-{
- const XalanDOMChar* const theBuffer =
- c_wstr(theLHS);
-
- return equalsIgnoreCase(theBuffer == 0 ? &theDummyEmptyString : theBuffer, theRHS);
-}
-
-
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
-{
- return doEqualsIgnoreCase(theLHS, theRHS, towupper);
-}
+};
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCaseASCII(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
+template<class InputCharType, class OutputCharType>
+IdentityTransform<InputCharType, OutputCharType>
+makeIdentityTransform(
+ const InputCharType*,
+ const OutputCharType*)
{
- return doEqualsIgnoreCase(theLHS, theRHS, toUpperASCII);
+ return IdentityTransform<InputCharType, OutputCharType>();
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCaseASCII(
- const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS)
+IdentityTransform<char, char>
+makeCharIdentityTransform()
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theRHS);
+ char theDummy;
- return equalsIgnoreCaseASCII(theLHS, theBuffer == 0 ? &theDummyEmptyString : theBuffer);
+ return makeIdentityTransform(&theDummy, &theDummy);
}
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCaseASCII(
- const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
+IdentityTransform<XalanDOMChar, XalanDOMChar>
+makeXalanDOMCharIdentityTransform()
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theLHS);
-
- return equalsIgnoreCaseASCII(theBuffer == 0 ? &theDummyEmptyString : theBuffer, theRHS);
-}
-
+ XalanDOMChar theDummy;
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equalsIgnoreCaseASCII(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
-{
- return doEqualsIgnoreCase(theLHS, theRHS, toUpperASCII);
+ return makeIdentityTransform(&theDummy, &theDummy);
}
-
-template <class Type, class SizeType>
+template <class Type, class SizeType, class FunctionType>
int
doCompare(
const Type* theLHS,
SizeType theLHSLength,
const Type* theRHS,
- SizeType theRHSLength)
+ SizeType theRHSLength,
+ FunctionType theTransformFunction)
{
- int theResult = 0;
-
- if (theLHSLength != 0 || theRHSLength != 0)
+ // We don't really have to order, so save some time...
+ if (theLHSLength < theRHSLength)
{
- Type theLHSChar = Type(0);
- Type theRHSChar = Type(0);
-
- SizeType i = 0;
+ return -1;
+ }
+ else if (theRHSLength < theLHSLength)
+ {
+ return 1;
+ }
+ else
+ {
+ Type theLHSChar = Type(0);
+ Type theRHSChar = Type(0);
- for(; i < theLHSLength && i < theRHSLength; i++)
+ for(SizeType i = 0; i < theLHSLength; i++)
{
- theLHSChar = theLHS[i];
- theRHSChar = theRHS[i];
+ theLHSChar = theTransformFunction(theLHS[i]);
+ theRHSChar = theTransformFunction(theRHS[i]);
if (theLHSChar != theRHSChar)
{
@@ -1011,80 +864,34 @@
}
}
- if (i == theLHSLength)
- {
- // We reached the end of theLHS...
- if (i != theRHSLength)
- {
- // but not the end of theRHS.
- theResult = -1;
- }
- }
- else if (i == theRHSLength)
- {
- // We reached the end of theRHS string...
- if (i != theLHSLength)
- {
- // but not the end of theLHS string.
- theResult = 1;
- }
- }
- else
- {
- // We didn't reach the end of _either_ string, so
- // return the difference between the two characters
- // that caused the problem.
- theResult = theLHSChar - theRHSChar;
- }
+ return int(theLHSChar - theRHSChar);
}
-
- return theResult;
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compare(
- const CharVectorType& theLHS,
- const CharVectorType& theRHS)
-{
- return doCompare(c_str(theLHS), theLHS.size(), c_str(theRHS), theRHS.size());
-}
-
-
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compare(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
-{
- return doCompare(theLHS, length(theLHS), theRHS, length(theRHS));
-}
-
-
-
template <class Type, class SizeType, class FunctionType>
int
-doCompareIgnoreCase(
+doCollationCompare(
const Type* theLHS,
SizeType theLHSLength,
const Type* theRHS,
SizeType theRHSLength,
- FunctionType theToUpperFunction)
+ FunctionType theTransformFunction)
{
- int theResult = 0;
+ int theResult = 0;
if (theLHSLength != 0 || theRHSLength != 0)
{
- Type theLHSChar = 0;
- Type theRHSChar = 0;
+ Type theLHSChar = Type(0);
+ Type theRHSChar = Type(0);
SizeType i = 0;
for(; i < theLHSLength && i < theRHSLength; i++)
{
- theLHSChar = theToUpperFunction(theLHS[i]);
- theRHSChar = theToUpperFunction(theRHS[i]);
+ theLHSChar = theTransformFunction(theLHS[i]);
+ theRHSChar = theTransformFunction(theRHS[i]);
if (theLHSChar != theRHSChar)
{
@@ -1115,7 +922,7 @@
// We didn't reach the end of _either_ string, so
// return the difference between the two characters
// that caused the problem.
- theResult = int(theLHSChar - theRHSChar);
+ theResult = theLHSChar - theRHSChar;
}
}
@@ -1125,37 +932,50 @@
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCase(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
+compare(
+ const CharVectorType& theLHS,
+ const CharVectorType& theRHS)
{
- return doCompareIgnoreCase(theLHS, length(theLHS), theRHS, length(theRHS), towupper);
+ return doCompare(
+ toCharArray(theLHS),
+ theLHS.size(),
+ toCharArray(theRHS),
+ theRHS.size(),
+ makeCharIdentityTransform());
}
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCase(
+compare(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS)
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength)
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theRHS);
-
- return compareIgnoreCase(theLHS, theBuffer == 0 ? &theDummyEmptyString : theBuffer);
+ return doCompare(
+ theLHS,
+ theLHSLength,
+ theRHS,
+ theRHSLength,
+ makeXalanDOMCharIdentityTransform());
}
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
compareIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
+ const XalanDOMChar* theLHS,
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength)
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theLHS);
-
- return compareIgnoreCase(theBuffer == 0 ? &theDummyEmptyString : theBuffer, theRHS);
+ return doCompare(
+ theLHS,
+ theLHSLength,
+ theRHS,
+ theRHSLength,
+ towupper);
}
@@ -1163,209 +983,159 @@
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
compareIgnoreCaseASCII(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength)
{
- return doCompareIgnoreCase(theLHS, length(theLHS), theRHS, length(theRHS), toUpperASCII);
+ return doCompare(
+ theLHS,
+ theLHSLength,
+ theRHS,
+ theRHSLength,
+ toUpperASCII);
}
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCaseASCII(
+collationCompare(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS)
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength)
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theRHS);
-
- return compareIgnoreCaseASCII(theLHS, theBuffer == 0 ? &theDummyEmptyString : theBuffer);
+ return doCollationCompare(
+ theLHS,
+ theLHSLength,
+ theRHS,
+ theRHSLength,
+ makeXalanDOMCharIdentityTransform());
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCaseASCII(
- const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
+template <class Type, class SizeType, class FunctionType>
+bool
+doEquals(
+ const Type* theLHS,
+ const Type* theRHS,
+ SizeType theLength,
+ FunctionType theTransformFunction)
{
- const XalanDOMChar* const theBuffer =
- c_wstr(theLHS);
-
- return compareIgnoreCaseASCII(theBuffer == 0 ? &theDummyEmptyString : theBuffer, theRHS);
-}
-
-
+ assert(theLHS != 0 && theRHS != 0);
-struct WideStringLexicalCompare
-{
- int
- operator()(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS) const
+#if 1
+ if (theLength == 0)
{
- return compare(theLHS, theRHS);
+ return true;
}
-};
-
-
-
-struct WideStringIgnoreCaseCompare
-{
- int
- operator()(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS) const
+ else
{
- return compareIgnoreCase(theLHS, theRHS);
- }
-};
+ const Type* const theEnd = theLHS + theLength;
+ while(theTransformFunction(*theLHS) == theTransformFunction(*theRHS))
+ {
+ ++theLHS;
+ if (theLHS == theEnd)
+ {
+ return true;
+ }
+ else
+ {
+ ++theRHS;
+ }
+ }
-struct WideStringIgnoreCaseCompareASCII
-{
- int
- operator()(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS) const
- {
- return compareIgnoreCaseASCII(theLHS, theRHS);
+ return false;
}
-};
-
-
-
-struct WideStringCollationCompare
-{
- int
- operator()(
- const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS) const
+#else
+ for(SizeType i = 0; i < theLength; ++i)
{
- return collationCompare(theLHS, theRHS);
- }
-};
+ const Type theLHSChar = theTransformFunction(theLHS[i]);
+ const Type theRHSChar = theTransformFunction(theRHS[i]);
-
-
-template<class CompareFunctionType>
-int
-DOMStringCompare(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS,
- CompareFunctionType theCompareFunction)
-{
- const bool fLHSIsEmpty = isEmpty(theLHS);
- const bool fRHSIsEmpty = isEmpty(theRHS);
-
- // correct?
- if (fLHSIsEmpty == true)
- {
- if (fRHSIsEmpty == true || length(theRHS) == 0)
+ if (theLHSChar != theRHSChar)
{
- return 0;
- }
- else
- {
- return 1;
- }
- }
- else if (isEmpty(theRHS) == true)
- {
- if (length(theLHS) == 0)
- {
- return 0;
- }
- else
- {
- return -1;
+ return false;
}
}
- else
- {
- assert(c_wstr(theLHS) != 0 && c_wstr(theRHS) != 0);
- return theCompareFunction(c_wstr(theLHS), c_wstr(theRHS));
- }
+ return true;
+#endif
}
-
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compare(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
+
+template <class Type, class SizeType, class FunctionType>
+bool
+doEqualsIgnoreCase(
+ const Type* theLHS,
+ const Type* theRHS,
+ SizeType theLength,
+ FunctionType theToUpperFunction)
{
- return DOMStringCompare(theLHS, theRHS, WideStringLexicalCompare());
-}
-
+ // Check each character, converting to uppercase
+ // for the test.
+ for(SizeType i = 0; i < theLength; i++)
+ {
+ const Type charLHS = theLHS[i];
+ const Type charRHS = theRHS[i];
+ if (charLHS != charRHS &&
+ Type(theToUpperFunction(charLHS)) != charRHS &&
+ charLHS != Type(theToUpperFunction(charRHS)))
+ {
+ return false;
+ }
+ }
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
-{
- return DOMStringCompare(theLHS, theRHS, WideStringIgnoreCaseCompare());
+ return true;
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCaseASCII(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+equals(
+ const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS,
+ unsigned int theLength)
{
- return DOMStringCompare(theLHS, theRHS, WideStringIgnoreCaseCompareASCII());
+ return doEquals(
+ theLHS,
+ theRHS,
+ theLength,
+ makeXalanDOMCharIdentityTransform());
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-collationCompare(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+equalsIgnoreCase(
+ const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS,
+ unsigned int theLength)
{
- return DOMStringCompare(theLHS, theRHS, WideStringCollationCompare());
+ return doEqualsIgnoreCase(
+ theLHS,
+ theRHS,
+ theLength,
+ towupper);
}
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equals(
+equalsIgnoreCaseASCII(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS)
+ const XalanDOMChar* theRHS,
+ unsigned int theLength)
{
- assert(theLHS != 0 && theRHS != 0);
-
- for(;;)
- {
- const XalanDOMChar theLHSChar = *theLHS;
- const XalanDOMChar theRHSChar = *theRHS;
-
- if (theLHSChar == 0)
- {
- return theRHSChar == 0 ? true : false;
- }
- else if (theRHSChar == 0)
- {
- return theLHSChar == 0 ? true : false;
- }
- else if (theLHSChar != theRHSChar)
- {
- return false;
- }
- else
- {
- ++theLHS;
- ++theRHS;
- }
- }
-
- assert(false);
-
- // Dummy return value...
- return false;
+ return doEqualsIgnoreCase(
+ theLHS,
+ theRHS,
+ theLength,
+ toUpperASCII);
}
@@ -1568,31 +1338,6 @@
-template <class InputCharType, class OutputCharType>
-class IdentityTransform
-{
-public:
-
- OutputCharType
- operator()(InputCharType theChar) const
- {
- return OutputCharType(theChar);
- }
-};
-
-
-
-template<class InputCharType, class OutputCharType>
-IdentityTransform<InputCharType, OutputCharType>
-makeIdentityTransform(
- const InputCharType*,
- const OutputCharType*)
-{
- return IdentityTransform<InputCharType, OutputCharType>();
-}
-
-
-
// A very cheap decimal number transcoder...
template <class InputCharType, class OutputCharType>
class DecimalNumberTranscodeTransform
@@ -1762,30 +1507,30 @@
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
DoubleToDOMString(
double theDouble,
- XalanDOMString& theString)
+ XalanDOMString& theResult)
{
if (DoubleSupport::isNaN(theDouble) == true)
{
- theString = theNaNString;
+ theResult = theNaNString;
}
else if (DoubleSupport::isPositiveInfinity(theDouble) == true)
{
- theString = thePositiveInfinityString;
+ theResult = thePositiveInfinityString;
}
else if (DoubleSupport::isNegativeInfinity(theDouble) == true)
{
- theString = theNegativeInfinityString;
+ theResult = theNegativeInfinityString;
}
else if (DoubleSupport::isNegativeZero(theDouble) == true)
{
- theString = theNegativeZeroString;
+ theResult = theNegativeZeroString;
}
else if (DoubleSupport::isPositiveZero(theDouble) == true)
{
- theString = thePositiveZeroString;
+ theResult = thePositiveZeroString;
}
else
{
@@ -1816,24 +1561,26 @@
++theCharsWritten;
}
-#if defined(XALAN_USE_XERCES_DOMSTRING)
- XalanDOMChar theResult[sizeof(theBuffer)];
+#if defined(XALAN_USE_STD_STRING) && defined(XALAN_OLD_STD_STRING)
+ XalanDOMChar theTemp[sizeof(theBuffer)];
TranscodeNumber(
theBuffer,
theBuffer + theCharsWritten,
- theResult);
+ theTemp);
- theString = XalanDOMString(theResult, theCharsWritten);
+ theResult = XalanDOMString(theTemp, theCharsWritten);
#else
- reserve(theString, theCharsWritten);
+ reserve(theResult, theCharsWritten + 1);
TranscodeNumber(
theBuffer,
theBuffer + theCharsWritten,
- back_inserter(theString));
+ back_inserter(theResult));
#endif
}
+
+ return theResult;
}
@@ -1959,42 +1706,50 @@
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
LongToHexDOMString(
long theValue,
XalanDOMString& theResult)
{
UnsignedScalarToHexadecimalString(theValue, theResult);
+
+ return theResult;
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
UnsignedLongToHexDOMString(
unsigned long theValue,
XalanDOMString& theResult)
{
UnsignedScalarToHexadecimalString(theValue, theResult);
+
+ return theResult;
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
LongToDOMString(
long theValue,
XalanDOMString& theResult)
{
ScalarToDecimalString(theValue, theResult);
+
+ return theResult;
}
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
UnsignedLongToDOMString(
unsigned long theValue,
XalanDOMString& theResult)
{
ScalarToDecimalString(theValue, theResult);
+
+ return theResult;
}
1.41 +524 -437 xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp
Index: DOMStringHelper.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/DOMStringHelper.hpp,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- DOMStringHelper.hpp 2001/01/03 21:29:47 1.40
+++ DOMStringHelper.hpp 2001/01/08 18:15:31 1.41
@@ -174,15 +174,7 @@
inline const XalanDOMChar*
c_wstr(const XalanDOMString& theString)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
return theString.c_str();
-#else
- const XalanDOMChar* const ptr = theString.rawBuffer();
-
- assert(!ptr || ptr[theString.length()] == '\0');
-
- return ptr;
-#endif
}
@@ -197,11 +189,18 @@
inline const char*
c_str(const CharVectorType& theString)
{
- const char* const ptr = &theString[0];
+ if (theString.size() == 0)
+ {
+ return 0;
+ }
+ else
+ {
+ const char* const ptr = &theString[0];
- assert(!ptr || ptr[theString.size() - 1] == '\0');
+ assert(ptr[theString.size() - 1] == '\0');
- return ptr;
+ return ptr;
+ }
}
@@ -239,11 +238,36 @@
inline const XalanDOMChar*
toCharArray(const XalanDOMString& theString)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
return theString.c_str();
-#else
- return theString.rawBuffer();
-#endif
+}
+
+
+
+/**
+ * Get the underlying representation of a XalanDOMChar.
+ *
+ * @param theString target string
+ * @return array of XalanDOMChar
+ */
+inline const XalanDOMChar*
+toCharArray(const XalanDOMChar* theString)
+{
+ return theString;
+}
+
+
+
+/**
+ * Get the underlying representation of the target CharVectorType as a
+ * pointer to an array of characters
+ *
+ * @param theString target string
+ * @return the pointer
+ */
+inline const char*
+toCharArray(const CharVectorType& theString)
+{
+ return theString.size() == 0 ? 0 : &theString[0];
}
@@ -280,25 +304,41 @@
/**
- * Get the length of a null-terminated buffer of
+ * Get the length of a null-terminated string of
* XalanDOMChar characters
*
- * @param theBuffer target string
+ * @param theString target string
* @return the length of the target string
*/
inline unsigned int
-length(const XalanDOMChar* theBuffer)
+length(const XalanDOMChar* theString)
{
- assert(theBuffer != 0);
+ assert(theString != 0);
- const XalanDOMChar* theBufferPointer = theBuffer;
+ const XalanDOMChar* theBufferPointer = theString;
while(*theBufferPointer != 0)
{
theBufferPointer++;
}
+
+ return theBufferPointer - theString;
+}
+
+
+
+/**
+ * Get the length of a null-terminated string.
+ *
+ * @param theString target string
+ * @return the length of the target string
+ */
+inline unsigned int
+length(const char* theString)
+{
+ assert(theString != 0);
- return theBufferPointer - theBuffer;
+ return strlen(theString);
}
@@ -551,8 +591,9 @@
*
* @param theValue number to be converted
* @param theResult the string to append with the result
+ * @return a reference to the passed string result.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
DoubleToDOMString(
double theValue,
XalanDOMString& theResult);
@@ -583,8 +624,9 @@
*
* @param theValue number to be converted
* @param theResult the string to append with the result
+ * @return a reference to the passed string result.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
LongToHexDOMString(
long theValue,
XalanDOMString& theResult);
@@ -616,8 +658,9 @@
*
* @param theValue number to be converted
* @param theResult the string to append with the result
+ * @return a reference to the passed string result.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
UnsignedLongToHexDOMString(
unsigned long theValue,
XalanDOMString& theResult);
@@ -648,8 +691,9 @@
*
* @param theValue number to be converted
* @param theResult the string to append with the result
+ * @return a reference to the passed string result.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
LongToDOMString(
long theValue,
XalanDOMString& theResult);
@@ -680,8 +724,9 @@
*
* @param theValue number to be converted
* @param theResult the string to append with the result
+ * @return a reference to the passed string result.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void)
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString)&
UnsignedLongToDOMString(
unsigned long theValue,
XalanDOMString& theResult);
@@ -1048,24 +1093,6 @@
/**
- * Creates a copy of the target string
- *
- * @param theString target string
- * @return copy of string
- */
-inline XalanDOMString
-clone(const XalanDOMString& theString)
-{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
- return theString;
-#else
- return theString.clone();
-#endif
-}
-
-
-
-/**
* Retrieves a character at a specified index in the target string
*
* @param theString target string
@@ -1077,11 +1104,7 @@
const XalanDOMString& theString,
unsigned int theIndex)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
return theString[theIndex];
-#else
- return theString.charAt(theIndex);
-#endif
}
@@ -1313,28 +1336,68 @@
-#if defined(XALAN_USE_XERCES_DOMSTRING) && !defined(XALAN_AMBIGUOUS_EVEN_IF_NOT_CALLED)
-// These two function are specifically not defined, and
-// should produce ambiguity during compilation. This
-// is necessary because the Xerces XalanDOMString class
-// defines == as referring to the same underlying
-// handle, not identical strings, as C++ programmers
-// would expect.
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-operator==(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+/**
+ * Compare the contents of two strings.
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ * @see operator<()
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+compare(
+ const CharVectorType& theLHS,
+ const CharVectorType& theRHS);
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-operator!=(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
-#endif
+/**
+ * Compare the contents of two character arrays.
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
+ * @param theLHS first array to compare
+ * @param theLHSLength the length of the first array
+ * @param theRHS second array to compare
+ * @param theRHSLength the length of the second array
+ * @return Returns 0 for equal arrays, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+compare(
+ const XalanDOMChar* theLHS,
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength);
+
+
+/**
+ * Compare the contents of two null-terminated strings.
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+inline int
+compare(
+ const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS)
+{
+ return compare(theLHS, length(theLHS), theRHS, length(theRHS));
+}
+
/**
* Compare the contents of two strings.
*
@@ -1343,58 +1406,102 @@
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
* @see operator<()
+ * @see collationCompare()
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
compare(
- const CharVectorType& theLHS,
- const CharVectorType& theRHS);
+ const XalanDOMString& theLHS,
+ const XalanDOMString& theRHS)
+{
+ return compare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS));
+}
/**
* Compare the contents of two strings.
*
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
compare(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMString& theRHS)
+{
+ return compare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS));
+}
+
+
+/**
+ * Compare the contents of two strings.
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+inline int
+compare(
+ const XalanDOMString& theLHS,
+ const XalanDOMChar* theRHS)
+{
+ return compare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS));
+}
+
/**
* Compare the contents of two strings, in a case insensitive
- * manner
+ * manner.
*
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
* @param theLHS first string to compare
+ * @param theLHSLength the length of the first array
* @param theRHS second string to compare
+ * @param theRHSLength the length of the second array
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
compareIgnoreCase(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength);
/**
* Compare the contents of two strings, in a case insensitive
- * manner
+ * manner.
*
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
compareIgnoreCase(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theRHS)
+{
+ return compareIgnoreCase(theLHS, length(theLHS), theRHS, length(theRHS));
+}
@@ -1406,118 +1513,146 @@
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ * @see operator<
+ * @see collationCompare
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
compareIgnoreCase(
const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMString& theRHS)
+{
+ return compareIgnoreCase(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS));
+}
/**
* Compare the contents of two strings, in a case insensitive
- * manner. Only the characters a-z and A-Z are considered for
- * the comparison.
+ * manner
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
*
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCaseASCII(
+inline int
+compareIgnoreCase(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMString& theRHS)
+{
+ return compareIgnoreCase(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS));
+}
/**
* Compare the contents of two strings, in a case insensitive
- * manner. Only the characters a-z and A-Z are considered for
- * the comparison.
+ * manner
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
*
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCaseASCII(
+inline int
+compareIgnoreCase(
const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMChar* theRHS)
+{
+ return compareIgnoreCase(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS));
+}
/**
- * Compare the contents of two strings, in a case insensitive
- * manner. Only the characters a-z and A-Z are considered for
- * the comparison.
+ * Compare the contents of two arrays in a case insensitive
+ * manner. Only the characters a-z and A-Z are considered as
+ * characters with "case".
*
- * @param theLHS first string to compare
- * @param theRHS second string to compare
- * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * @param theLHS first array to compare
+ * @param theLHSLength the length of the first array
+ * @param theRHS second array to compare
+ * @param theRHSLength the length of the second array
+ * @return Returns 0 for equal arrays, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
*/
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
compareIgnoreCaseASCII(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS);
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength);
/**
- * Compare the contents of two strings using the
- * the collation settings of the current code page.
- *
+ * Compare the contents of two strings, in a case insensitive
+ * manner. Only the characters a-z and A-Z are considered as
+ * characters with "case".
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<()
- * @see compare()
*/
-// Can't really do it, so just call compare...
inline int
-collationCompare(
+compareIgnoreCaseASCII(
const XalanDOMChar* theLHS,
const XalanDOMChar* theRHS)
{
- return compare(theLHS, theRHS);
+ return compareIgnoreCaseASCII(theLHS, length(theLHS), theRHS, length(theRHS));
}
/**
- * Compare the contents of two strings.
- *
+ * Compare the contents of two strings, in a case insensitive
+ * manner. Only the characters a-z and A-Z are considered as
+ * characters with "case".
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<()
- * @see collationCompare()
+ * @see operator<
+ * @see collationCompare
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compare(
+inline int
+compareIgnoreCaseASCII(
const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMString& theRHS)
+{
+ return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS));
+}
+
/**
* Compare the contents of two strings, in a case insensitive
- * manner
- *
+ * manner. Only the characters a-z and A-Z are considered as
+ * characters with "case".
+ *
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<
- * @see collationCompare
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
-compareIgnoreCase(
+inline int
+compareIgnoreCaseASCII(
const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theRHS)
+{
+ return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS));
+}
@@ -1526,23 +1661,45 @@
* manner. Only the characters a-z and A-Z are considered for
* the comparison.
*
+ * THIS FUNCTION DOES NOT COMPARE STRINGS LIKE strcmp() OR ANY
+ * OTHER "COLLATION" ALGORITHM.
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return Returns 0 for equal strings, less than 0 if theLHS is less
* than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<
- * @see collationCompare
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
compareIgnoreCaseASCII(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theLHS,
+ const XalanDOMString& theRHS)
+{
+ return compareIgnoreCaseASCII(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS));
+}
+/**
+ * Compare the contents of two character arrays.
+ *
+ * @param theLHS first array to compare
+ * @param theLHSLength the length of the first array
+ * @param theRHS second array to compare
+ * @param theRHSLength the length of the second array
+ * @return Returns 0 for equal arrays, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+collationCompare(
+ const XalanDOMChar* theLHS,
+ unsigned int theLHSLength,
+ const XalanDOMChar* theRHS,
+ unsigned int theRHSLength);
+
+
+
/**
- * Compare the contents of two strings using the
- * the collation settings of the current code page.
+ * Compare the contents of two strings.
*
* @param theLHS first string to compare
* @param theRHS second string to compare
@@ -1551,24 +1708,85 @@
* @see operator<()
* @see compare()
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int)
+inline int
collationCompare(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS)
+{
+ return collationCompare(theLHS, length(theLHS), theRHS, length(theRHS));
+}
/**
- * Compare the contents of two strings for equality
+ * Compare the contents of two strings.
*
* @param theLHS first string to compare
* @param theRHS second string to compare
- * @return true if the contents of both strings are identical
- */
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
-equals(
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ * @see operator<()
+ * @see compare()
+ */
+inline int
+collationCompare(
+ const XalanDOMString& theLHS,
+ const XalanDOMString& theRHS)
+{
+ return collationCompare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS));
+}
+
+
+
+/**
+ * Compare the contents of two strings.
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+inline int
+collationCompare(
+ const XalanDOMChar* theLHS,
+ const XalanDOMString& theRHS)
+{
+ return collationCompare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS));
+}
+
+
+
+/**
+ * Compare the contents of two strings.
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return Returns 0 for equal strings, less than 0 if theLHS is less
+ * than theRHS, or greater than 0 if theRHS is greater than theLHS.
+ */
+inline int
+collationCompare(
+ const XalanDOMString& theLHS,
+ const XalanDOMChar* theRHS)
+{
+ return collationCompare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS));
+}
+
+
+
+/**
+ * Compare the contents of two arrays for equality
+ *
+ * @param theLHS first array to compare
+ * @param theRHS second array to compare
+ * @param theLength the length of the arrays
+ * @return true if the contents of both arrays are identical
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+equals(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMChar* theRHS,
+ unsigned int theLength);
@@ -1582,14 +1800,34 @@
inline bool
equals(
const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS)
+{
+ const unsigned int theLHSLength = length(theLHS);
+
+ return theLHSLength != length(theRHS) ? false : equals(theLHS, theRHS, theLHSLength);
+}
+
+
+
+/**
+ * Compare the contents of two strings for equality
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return true if the contents of both strings are identical
+ */
+inline bool
+equals(
+ const XalanDOMString& theLHS,
const XalanDOMString& theRHS)
{
- assert(theLHS != 0);
+#if defined(XALAN_USE_STD_STRING)
+ const unsigned int theLHSLength = length(theLHS);
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
- return theLHS == theRHS;
+ return theLHSLength != length(theRHS) ? false :
+ equals(toCharArray(theLHS), toCharArray(theRHS), theLHSLength);
#else
- return theRHS.equals(theLHS);
+ return theLHS == theRHS;
#endif
}
@@ -1603,17 +1841,17 @@
* @return true if the contents of both strings are identical
*/
inline bool
-equals(const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS)
+equals(
+ const XalanDOMChar* theLHS,
+ const XalanDOMString& theRHS)
{
- assert(theRHS != 0);
+ assert(theLHS != 0);
-#if defined(XALAN_USE_CUSTOM_STRING)
- return theLHS == theRHS;
-#elif defined(XALAN_USE_STD_STRING)
- return equals(c_wstr(theLHS), theRHS);
+#if defined(XALAN_USE_STD_STRING)
+ return equals(theLHS, c_wstr(theRHS));
#else
- return theLHS.equals(theRHS);
+ // Swap them...
+ return theRHS == theLHS;
#endif
}
@@ -1628,17 +1866,40 @@
*/
inline bool
equals(const XalanDOMString& theLHS,
+ const XalanDOMChar* theRHS)
+{
+ return equals(theRHS, theLHS);
+}
+
+
+
+/**
+ * Compare the contents of two strings for equality
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return true if the contents of both strings are identical
+ */
+inline bool
+equals(const XalanDOMString& theLHS,
const char* theRHS)
{
assert(theRHS != 0);
+
+ const unsigned int theRHSLength = length(theRHS);
-#if defined(XALAN_USE_CUSTOM_STRING)
- return theLHS == XalanDOMString(theRHS);
-#elif defined(XALAN_USE_STD_STRING)
- return theLHS == TranscodeFromLocalCodePage(theRHS);
+ if (theRHSLength != length(theLHS))
+ {
+ return false;
+ }
+ else
+ {
+#if defined(XALAN_USE_STD_STRING)
+ return theLHS == TranscodeFromLocalCodePage(theRHS);
#else
- return theLHS.equals(theRHS) ? true : false;
+ return theLHS == XalanDOMString(theRHS, theRHSLength);
#endif
+ }
}
@@ -1651,14 +1912,10 @@
* @return true if the contents of both strings are identical
*/
inline bool
-equals(const XalanDOMChar* theLHS,
- const char* theRHS)
+equals(const char* theLHS,
+ const XalanDOMString& theRHS)
{
-#if defined(XALAN_USE_STD_STRING)
- return equals(theLHS, TranscodeFromLocalCodePage(theRHS));
-#else
- return equals(theLHS, XalanDOMString(theRHS));
-#endif
+ return equals(theRHS, theLHS);
}
@@ -1671,17 +1928,26 @@
* @return true if the contents of both strings are identical
*/
inline bool
-equals(const char* theLHS,
- const XalanDOMChar* theRHS)
+equals(const XalanDOMChar* theLHS,
+ const char* theRHS)
{
assert(theLHS != 0);
assert(theRHS != 0);
+ const unsigned int theRHSLength = length(theRHS);
+
+ if (theRHSLength != length(theLHS))
+ {
+ return false;
+ }
+ else
+ {
#if defined(XALAN_USE_STD_STRING)
- return equals(TranscodeFromLocalCodePage(theLHS), theRHS);
+ return equals(TranscodeFromLocalCodePage(theRHS), theLHS);
#else
- return equals(XalanDOMString(theLHS), theRHS);
+ return equals(XalanDOMString(theRHS, theRHSLength), theLHS);
#endif
+ }
}
@@ -1694,32 +1960,46 @@
* @return true if the contents of both strings are identical
*/
inline bool
-equals(
- const XalanDOMString& theLHS,
- const XalanDOMString& theRHS)
+equals(const char* theLHS,
+ const XalanDOMChar* theRHS)
{
-#if defined(XALAN_USE_CUSTOM_STRING)
- return theLHS == theRHS;
-#elif defined(XALAN_USE_STD_STRING)
- return equals(c_wstr(theLHS), c_wstr(theRHS));
-#else
- return theLHS.equals(theRHS) ? true : false;
-#endif
+ return equals(theRHS, theLHS);
}
/**
+ * Compare the contents of two arrays for equality, without regard for case
+ *
+ * @param theLHS first array to compare
+ * @param theRHS second array to compare
+ * @param theLength the length of the arrays
+ * @return true if the contents of both arrays are identical
+ */
+XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+equalsIgnoreCase(
+ const XalanDOMChar* theLHS,
+ const XalanDOMChar* theRHS,
+ unsigned int theLength);
+
+
+
+/**
* Compare the contents of two strings for equality, without regard for case
*
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCase(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMChar* theRHS)
+{
+ const unsigned int theLength = length(theLHS);
+
+ return theLength != length(theRHS) ? false : equalsIgnoreCase(theLHS, theRHS, theLength);
+}
@@ -1730,11 +2010,17 @@
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCase(
- const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMString& theLHS,
+ const XalanDOMString& theRHS)
+{
+ const unsigned int theLHSLength = length(theLHS);
+ return theLHSLength != length(theRHS) ? false :
+ equalsIgnoreCase(toCharArray(theLHS), toCharArray(theRHS), theLHSLength);
+}
+
/**
@@ -1744,13 +2030,19 @@
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCase(
- const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMChar* theLHS,
+ const XalanDOMString& theRHS)
+{
+ const unsigned int theRHSLength = length(theRHS);
+ return theRHSLength != length(theLHS) ? false :
+ equalsIgnoreCase(theLHS, toCharArray(theRHS), theRHSLength);
+}
+
/**
* Compare the contents of two strings for equality, without regard for case
*
@@ -1758,16 +2050,19 @@
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCase(
const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theRHS)
+{
+ return equalsIgnoreCase(theRHS, theLHS);
+}
/**
- * Compare the contents of two strings for equality, without regard for case.
- * Only the characters A-Z and a-z are considered.
+ * Compare the contents of two arrays for equality, without regard for case.
+ * Only the characters a-z and A-Z are considered characters with "case".
*
* @param theLHS first string to compare
* @param theRHS second string to compare
@@ -1776,52 +2071,89 @@
XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
equalsIgnoreCaseASCII(
const XalanDOMChar* theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMChar* theRHS,
+ unsigned int theLength);
/**
* Compare the contents of two strings for equality, without regard for case.
- * Only the characters A-Z and a-z are considered.
+ * Only the characters a-z and A-Z are considered characters with "case".
*
* @param theLHS first string to compare
* @param theRHS second string to compare
- * @return true if the case-insensitive contents of both strings are identical
+ * @return true if both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCaseASCII(
const XalanDOMChar* theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theRHS)
+{
+ const unsigned int theLength = length(theLHS);
+ return theLength != length(theRHS) ? false :
+ equalsIgnoreCaseASCII(theLHS, theRHS, theLength);
+}
+
/**
- * Compare the contents of two strings for equality, without regard for case.
+ * Compare the contents of two strings for equality, without regard for case
* Only the characters A-Z and a-z are considered.
- *
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCaseASCII(
const XalanDOMString& theLHS,
- const XalanDOMChar* theRHS);
+ const XalanDOMString& theRHS)
+{
+ const unsigned int theLength = length(theLHS);
+
+ return theLength != length(theRHS) ? false :
+ equalsIgnoreCaseASCII(toCharArray(theLHS), toCharArray(theRHS), theLength);
+}
/**
- * Compare the contents of two strings for equality, without regard for case
+ * Compare the contents of two strings for equality, without regard for case.
+ * Only the characters a-z and A-Z are considered characters with "case".
+ *
+ * @param theLHS first string to compare
+ * @param theRHS second string to compare
+ * @return true if the case-insensitive contents of both strings are identical
+ */
+inline bool
+equalsIgnoreCaseASCII(
+ const XalanDOMChar* theLHS,
+ const XalanDOMString& theRHS)
+{
+ const unsigned int theRHSLength = length(theRHS);
+
+ return theRHSLength != length(theLHS) ? false :
+ equalsIgnoreCaseASCII(theLHS, toCharArray(theRHS), theRHSLength);
+}
+
+
+
+/**
+ * Compare the contents of two strings for equality, without regard for case.
* Only the characters A-Z and a-z are considered.
- *
+ *
* @param theLHS first string to compare
* @param theRHS second string to compare
* @return true if the case-insensitive contents of both strings are identical
*/
-XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool)
+inline bool
equalsIgnoreCaseASCII(
const XalanDOMString& theLHS,
- const XalanDOMString& theRHS);
+ const XalanDOMChar* theRHS)
+{
+ return equalsIgnoreCaseASCII(theRHS, theLHS);
+}
@@ -1919,11 +2251,7 @@
XalanDOMString& theString,
const XalanDOMString& theStringToAssign)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
theString = theStringToAssign;
-#else
- theString = theStringToAssign.clone();
-#endif
return theString;
}
@@ -1944,7 +2272,6 @@
const XalanDOMChar* theStringToAssign,
unsigned int theStringToAssignLength = unsigned(-1))
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
if (theStringToAssignLength == unsigned(-1))
{
theString.assign(theStringToAssign);
@@ -1953,16 +2280,6 @@
{
theString.assign(theStringToAssign, theStringToAssignLength);
}
-#else
- if (theStringToAssignLength == unsigned(-1))
- {
- theString = XalanDOMString(theStringToAssign);
- }
- else
- {
- theString = XalanDOMString(theStringToAssign, theStringToAssignLength);
- }
-#endif
return theString;
}
@@ -1981,11 +2298,7 @@
XalanDOMString& theString,
const XalanDOMString& theStringToAppend)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
theString.append(theStringToAppend);
-#else
- theString = theString + theStringToAppend;
-#endif
return theString;
}
@@ -2008,7 +2321,6 @@
{
assert(theStringToAppend != 0);
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
if (theStringToAppendLength == unsigned(-1))
{
theString.append(theStringToAppend);
@@ -2017,16 +2329,6 @@
{
theString.append(theStringToAppend, theStringToAppendLength);
}
-#else
- if (theStringToAppendLength == unsigned(-1))
- {
- theString.appendData(theStringToAppend);
- }
- else
- {
- append(theString, XalanDOMString(theStringToAppend, theStringToAppendLength));
- }
-#endif
return theString;
}
@@ -2047,22 +2349,7 @@
const char* theStringToAppend,
unsigned int theStringToAppendLength = unsigned(-1))
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
- theString.append(TranscodeFromLocalCodePage(theStringToAppend, theStringToAppendLength));
-#else
- if (theStringToAppendLength == unsigned(-1))
- {
- theString.appendData(theStringToAppend);
- }
- else
- {
- CharVectorType theTemp(theStringToAppend, theStringToAppend + theStringToAppendLength);
-
- theTemp.push_back(char(0));
-
- append(theString, XalanDOMString(&theTemp[0], theTemp.size() - 1));
- }
-#endif
+ theString.append(TranscodeFromLocalCodePage(theStringToAppend, theStringToAppendLength));
return theString;
}
@@ -2081,11 +2368,7 @@
XalanDOMString& theString,
const XalanDOMChar theCharToAppend)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
theString.append(1, theCharToAppend);
-#else
- theString.appendData(theCharToAppend);
-#endif
return theString;
}
@@ -2118,11 +2401,7 @@
unsigned int thePosition,
const XalanDOMString& theStringToInsert)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
theString.insert(thePosition, theStringToInsert);
-#else
- theString.insertData(thePosition, theStringToInsert);
-#endif
return theString;
}
@@ -2148,15 +2427,7 @@
inline void
clear(XalanDOMString& theString)
{
-#if defined(XALAN_USE_CUSTOM_STRING) || defined(XALAN_USE_STD_STRING)
theString.erase();
-#else
-#if defined(XALAN_OLD_STYLE_CASTS)
- theString = (DOM_NullPtr*)0;
-#else
- theString = static_cast<DOM_NullPtr*>(0);
-#endif
-#endif
}
@@ -2172,190 +2443,6 @@
CopyStringToVector(
const char* theString,
CharVectorType& theVector);
-
-
-
-/**
- * Get a pointer to the first element of the vector as
- * a null-terminated string
- *
- * @param theSVector target vector
- * @return null-terminated string of XalanDOMChar
- */
-inline const XalanDOMChar*
-c_wstr(const XalanDOMCharVectorType& theVector)
-{
- return &theVector[0];
-}
-
-
-
-/**
- * Compare the contents of two vectors for equality
- *
- * @param theLHS first vector to compare
- * @param theRHS second vector to compare
- * @return true if the contents of both vectors are identical
- */
-inline bool
-equals(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return theLHS == theRHS;
-}
-
-
-
-/**
- * Compare the contents of two strings for equality
- *
- * @param theLHS XalanDOMCharVectorType to compare
- * @param theRHS string to compare
- * @return true if the contents of are identical
- */
-inline bool
-equals(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMChar* theRHS)
-{
- return equals(c_wstr(theLHS), theRHS);
-}
-
-
-
-/**
- * Compare the contents of two strings for equality
- *
- * @param theLHS string to compare
- * @param theRHS XalanDOMCharVectorType to compare
- * @return true if the contents are identical
- */
-inline bool
-equals(
- const XalanDOMChar* theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return equals(theLHS, c_wstr(theRHS));
-}
-
-
-
-/**
- * Compare the contents of a XalanDOMCharVectorType
- * and a XalanDOMString for equality
- *
- * @param theLHS XalanDOMCharVectorType to compare
- * @param theRHS XalanDOMString to compare
- * @return true if the contents of both are identical
- */
-inline bool
-equals(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMString& theRHS)
-{
- return equals(c_wstr(theLHS), c_wstr(theRHS));
-}
-
-
-
-/**
- * Compare the contents of a XalanDOMString and a
- * XalanDOMCharVectorType for equality
- *
- * @param theLHS XalanDOMString to compare
- * @param theRHS XalanDOMCharVectorType to compare
- * @return true if the contents of both are identical
- */
-inline bool
-equals(
- const XalanDOMString& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return equals(c_wstr(theLHS), c_wstr(theRHS));
-}
-
-
-
-/**
- * Compare the contents of two XalanDOMCharVectorTypes.
- *
- * @param theLHS first vector to compare
- * @param theRHS second vector to compare
- * @return Returns 0 for equal vectors, less than 0 if theLHS is less
- * than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<
- * @see collationCompare
- */
-inline int
-compare(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return compare(&theLHS[0], &theRHS[0]);
-}
-
-
-
-/**
- * Compare the contents of two XalanDOMCharVectorTypes, in a case insensitive
- * manner
- *
- * @param theLHS first vector to compare
- * @param theRHS second vector to compare
- * @return Returns 0 for equal vectors, less than 0 if theLHS is less
- * than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<
- * @see collationCompare
- */
-inline int
-compareIgnoreCase(
-
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return compareIgnoreCase(&theLHS[0], &theRHS[0]);
-}
-
-
-
-/**
- * Compare the contents of two vectors using the
- * the collation settings of the current code page.
- *
- * @param theLHS first vector to compare
- * @param theRHS second vector to compare
- * @return Returns 0 for equal vectors, less than 0 if theLHS is less
- * than theRHS, or greater than 0 if theRHS is greater than theLHS.
- * @see operator<()
- * @see compare()
- */
-inline int
-collationCompare(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return collationCompare(&theLHS[0], &theRHS[0]);
-}
-
-
-
-/**
- * Implements operator< for XalanDOMCharVectorType.
- *
- * @param theLHS first vector to compare
- * @param theRHS second vector to compare
- * @return Returns true if theLHS is lexically
- * less than theRHS
- * @see compare
- */
-inline bool
-operator<(
- const XalanDOMCharVectorType& theLHS,
- const XalanDOMCharVectorType& theRHS)
-{
- return compare(theLHS, theRHS) < 0 ? true : false;
-}