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...@locus.apache.org on 2000/07/12 23:45:42 UTC

cvs commit: xml-xalan/c/src/ICUBridge FunctionICUFormatNumber.cpp ICUBridge.cpp ICUBridge.hpp ICUBridgeCollationCompareFunctor.cpp

dbertoni    00/07/12 14:45:41

  Modified:    c/src/ICUBridge FunctionICUFormatNumber.cpp ICUBridge.cpp
                        ICUBridge.hpp ICUBridgeCollationCompareFunctor.cpp
  Log:
  Changes to allow for Linux integration.  Cleaned up interfaces.
  
  Revision  Changes    Path
  1.2       +6 -40     xml-xalan/c/src/ICUBridge/FunctionICUFormatNumber.cpp
  
  Index: FunctionICUFormatNumber.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/ICUBridge/FunctionICUFormatNumber.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FunctionICUFormatNumber.cpp	2000/05/08 17:13:13	1.1
  +++ FunctionICUFormatNumber.cpp	2000/07/12 21:45:38	1.2
  @@ -112,16 +112,6 @@
   
   
   
  -ICUBridge::UTF16VectorType
  -makeUTF16VectorType(const XalanDOMString&	theString)
  -{
  -	return ICUBridge::UTF16VectorType(
  -		c_wstr(theString),
  -		c_wstr(theString) + length(theString));
  -}
  -
  -
  -
   XalanDOMString
   FunctionICUFormatNumber::doFormat(
   			XPathExecutionContext&				executionContext,
  @@ -130,39 +120,15 @@
   			const XalanDOMString&				thePattern,
   			const XalanDecimalFormatSymbols*	theDFS)
   {
  -	ICUBridge::UTF16VectorType			theResultString;
  +	XalanDOMString	theResultString;
   
  -	unsigned long		theResult = 0;
  +	unsigned long	theResult = 0;
   
  -	if (theDFS == 0)
  -	{
  -		// Nothing special, so use the default call...
  -		theResult = ICUBridge::FormatNumber(
  -					makeUTF16VectorType(thePattern),
  +	theResult = ICUBridge::FormatNumber(
  +					thePattern,
   					theNumber,
  +					theDFS,
   					theResultString);
  -	}
  -	else
  -	{
  -		// DecimalFormatSymbols specified, so use those values...
  -		theResult = ICUBridge::FormatNumber(
  -					makeUTF16VectorType(thePattern),
  -					theNumber,
  -					makeUTF16VectorType(theDFS->getCurrencySymbol()),
  -					theDFS->getDecimalSeparator(),
  -					theDFS->getDigit(),
  -					theDFS->getGroupingSeparator(),
  -					makeUTF16VectorType(theDFS->getInfinity()),
  -					makeUTF16VectorType(theDFS->getInternationalCurrencySymbol()),
  -					theDFS->getMinusSign(),
  -					theDFS->getMonetaryDecimalSeparator(),
  -					makeUTF16VectorType(theDFS->getNaN()),
  -					theDFS->getPatternSeparator(),
  -					theDFS->getPercent(),
  -					theDFS->getPerMill(),
  -					theDFS->getZeroDigit(),
  -					theResultString);
  -	}
   
   	if (theResult != 0)
   	{
  @@ -181,6 +147,6 @@
   	}
   	else
   	{
  -		return XalanDOMString(theResultString.begin(), theResultString.size());
  +		return theResultString;
   	}
   }
  
  
  
  1.4       +179 -90   xml-xalan/c/src/ICUBridge/ICUBridge.cpp
  
  Index: ICUBridge.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/ICUBridge/ICUBridge.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ICUBridge.cpp	2000/07/10 22:46:56	1.3
  +++ ICUBridge.cpp	2000/07/12 21:45:38	1.4
  @@ -59,6 +59,11 @@
   
   
   
  +#include <PlatformSupport/DOMStringHelper.hpp>
  +#include <PlatformSupport/XalanDecimalFormatSymbols.hpp>
  +
  +
  +
   #include <memory>
   
   
  @@ -69,103 +74,198 @@
   
   
   
  -unsigned long
  -ICUBridge::FormatNumber(
  -			const UTF16VectorType&		thePattern,
  -			double						theNumber,
  -			UTF16VectorType&			theResult)
  +#if defined(XALAN_NO_NAMESPACES)
  +	typedef vector<UChar>					UCharVectorType;
  +#else
  +	typedef std::vector<UChar>				UCharVectorType;
  +#endif
  +
  +
  +
  +const UnicodeString
  +ICUBridge::XalanDOMCharStringToUnicodeString(const XalanDOMChar*	theString)
   {
  -	const UnicodeString		theUnicodePattern(&thePattern[0], thePattern.size());
  +	if (theString == 0)
  +	{
  +		return UnicodeString();
  +	}
  +	else
  +	{
  +#if defined(XALAN_ICU_BRIDGE_UCHAR_MISMATCH)
   
  -	UErrorCode				theStatus = U_ZERO_ERROR;
  +		// Create a buffer to copy out the UnicodeString data...
  +		UCharVectorType		theBuffer;
   
  -	UnicodeString			theUnicodeResult;
  +		const unsigned int	theLength = length(theString);
   
  -	DecimalFormat			theFormatter(theUnicodePattern, theStatus);
  +		// Resize the buffer appropriately...
  +		theBuffer.reserve(theLength);
   
  -	if (theStatus == U_ZERO_ERROR ||
  -		theStatus == U_USING_DEFAULT_ERROR)
  -	{
  -		// Do the format...
  -		theFormatter.format(theNumber, theUnicodeResult);
  +		// Copy the data, truncating each character...
  +		for (unsigned int i = 0; i < theLength; ++i)
  +		{
  +			// There should be no truncation, since XalanDOMChars
  +			// hold UTF-16 code points, but assert, just in case...
  +			assert(theString[i] == UChar(theString[i]));
  +			theBuffer.push_back(theString[i]);
  +		}
   
  -		const int32_t	theLength = theUnicodeResult.length();
  +		return UnicodeString(&theBuffer[0], theBuffer.size());
   
  -		// Resize the vector to the appropriate length...
  -		theResult.clear();
  -		theResult.resize(theLength);
  +#else
   
  -		theUnicodeResult.extract(0, theLength, &theResult[0]);
  +		return UnicodeString(theString, length(theString));
   
  -		theStatus = U_ZERO_ERROR;
  +#endif
   	}
  +}
   
  -	return theStatus;
  +
  +
  +const UnicodeString
  +ICUBridge::XalanDOMStringToUnicodeString(const XalanDOMString&	theString)
  +{
  +	// Just call up to the XalanDOMChar* version...
  +	return XalanDOMCharStringToUnicodeString(c_wstr(theString));
  +}
  +
  +
  +
  +const XalanDOMString
  +ICUBridge::UnicodeStringToXalanDOMString(const UnicodeString&		theString)
  +{
  +#if defined(XALAN_ICU_BRIDGE_UCHAR_MISMATCH)
  +
  +	// If XalanDOMChar is larger than the ICU's UChar, we have to more work...
  +	const int32_t	theLength = theString.length();
  +
  +	// Create a buffer...
  +	XalanDOMCharVectorType	theBuffer;
  +
  +	// Reserve the appropriate amount of space...
  +	theBuffer.reserve(theLength);
  +
  +	// Copy the data...
  +	for (int32_t i = 0; i < theLength; ++i)
  +	{
  +		theBuffer.push_back(theString[i]);
  +	}
  +
  +	return XalanDOMString(&theBuffer[0], theBuffer.size());
  +
  +#else
  +
  +	// Create a buffer to copy out the UnicodeString data...
  +	UCharVectorType		theResult;
  +
  +	const int32_t	theLength = theString.length();
  +
  +	// Resize the buffer appropriately...
  +	theResult.resize(theLength);
  +
  +	// Extract the data...
  +	theString.extract(0, theLength, &theResult[0]);
  +
  +	return XalanDOMString(&theResult[0], theResult.size());
  +
  +#endif
   }
   
   
   
  +void
  +ICUBridge::UnicodeStringToXalanDOMString(
  +			const UnicodeString&	theString,
  +			XalanDOMString&			theResult)
  +{
  +#if defined(XALAN_ICU_BRIDGE_UCHAR_MISMATCH)
  +	
  +	// If XalanDOMChar is larger than the ICU's UChar, we have to more work.
  +	// Don't bother to provide the optimized version, just call to the
  +	// previous function.
  +
  +	theResult = UnicodeStringToXalanDOMString(theString);
  +
  +#else
  +
  +#if defined(XALAN_NO_NAMESPACES)
  +	typedef vector<UChar>					UCharVectorType;
  +#else
  +	typedef std::vector<UChar>				UCharVectorType;
  +#endif
  +
  +	// Create a buffer to copy out the UnicodeString data...
  +	UCharVectorType		theBuffer;
  +
  +	const int32_t	theLength = theString.length();
  +
  +	// Resize the buffer appropriately...
  +	theBuffer.resize(theLength);
  +
  +	// Extract the data...
  +	theString.extract(0, theLength, &theBuffer[0]);
  +
  +	theResult = XalanDOMString(&theBuffer[0], theBuffer.size());
  +
  +#endif
  +}
  +
  +
  +
   unsigned long
   ICUBridge::FormatNumber(
  -			const UTF16VectorType&	thePattern,
  -			double					theNumber,
  -			const UTF16VectorType&	theCurrencySymbolString,
  -			unsigned short			theDecimalSeparatorChar,
  -			unsigned short			theDigitChar,
  -			unsigned short			theGroupingSeparatorChar,
  -			const UTF16VectorType&	theInfinityString,
  -			const UTF16VectorType&	theInternationalCurrencySymbolString,
  -			unsigned short			theMinusSignChar,
  -			unsigned short			theMonetaryDecimalSeparatorChar,
  -			const UTF16VectorType&	theNaNString,
  -			unsigned short			thePatternSeparatorChar,
  -			unsigned short			thePercentChar,
  -			unsigned short			thePerMillChar,
  -			unsigned short			theZeroDigitChar,
  -			UTF16VectorType&		theResult)
  +			const XalanDOMString&				thePattern,
  +			double								theNumber,
  +			const XalanDecimalFormatSymbols*	theXalanDFS,
  +			XalanDOMString&						theResult)
   {
  -	const UnicodeString		theUnicodePattern(&thePattern[0], thePattern.size());
  +#if !defined(XALAN_NO_NAMESPACES)
  +	using std::auto_ptr;
  +#endif
   
   	UErrorCode				theStatus = U_ZERO_ERROR;
   
  -	UnicodeString			theUnicodeResult;
  +	// Use an auto_ptr, to keep this safe until we construct the DecimalFormat instance.
  +	const auto_ptr<DecimalFormatSymbols>	theDFS(new DecimalFormatSymbols(theStatus));
   
  -	DecimalFormatSymbols	theDFS(theStatus);
  -
  -	theDFS.setZeroDigit(theZeroDigitChar);
  -	theDFS.setGroupingSeparator(theGroupingSeparatorChar);
  -	theDFS.setDecimalSeparator(theDecimalSeparatorChar);
  -	theDFS.setPerMill(thePerMillChar);
  -	theDFS.setPercent(thePercentChar);
  -	theDFS.setDigit(theDigitChar);
  -	theDFS.setPatternSeparator(thePatternSeparatorChar);
  -	theDFS.setInfinity(UnicodeString(&theInfinityString[0], theInfinityString.size()));
  -	theDFS.setNaN(UnicodeString(&theNaNString[0], theNaNString.size()));
  -//	theDFS.setPlusSign(theZeroDigitChar);
  -	theDFS.setMinusSign(theMinusSignChar);
  -//	theDFS.setExponentialSymbol(theZeroDigitChar);
  -	theDFS.setCurrencySymbol(UnicodeString(&theCurrencySymbolString[0], theCurrencySymbolString.size()));
  -	theDFS.setInternationalCurrencySymbol(UnicodeString(&theInternationalCurrencySymbolString[0], theInternationalCurrencySymbolString.size()));
  -	theDFS.setMonetaryDecimalSeparator(theMonetaryDecimalSeparatorChar);
  -
   	if (theStatus == U_ZERO_ERROR ||
   		theStatus == U_USING_DEFAULT_ERROR)
   	{
  -		DecimalFormat			theFormatter(theUnicodePattern, theDFS, theStatus);
  +		if (theXalanDFS != 0)
  +		{
  +			// We got a XalanDecimalFormatSymbols, so set the
  +			// corresponding data in the ICU DecimalFormatSymbols.
  +			theDFS->setZeroDigit(theXalanDFS->getZeroDigit());
  +			theDFS->setGroupingSeparator(theXalanDFS->getGroupingSeparator());
  +			theDFS->setDecimalSeparator(theXalanDFS->getDecimalSeparator());
  +			theDFS->setPerMill(theXalanDFS->getPerMill());
  +			theDFS->setPercent(theXalanDFS->getPercent());
  +			theDFS->setDigit(theXalanDFS->getDigit());
  +			theDFS->setPatternSeparator(theXalanDFS->getPatternSeparator());
  +
  +			theDFS->setInfinity(XalanDOMStringToUnicodeString(theXalanDFS->getInfinity()));
  +			theDFS->setNaN(XalanDOMStringToUnicodeString(theXalanDFS->getNaN()));
  +		//	theDFS->setPlusSign(theZeroDigitChar);
  +			theDFS->setMinusSign(theXalanDFS->getMinusSign());
  +		//	theDFS->setExponentialSymbol(theZeroDigitChar);
  +			theDFS->setCurrencySymbol(XalanDOMStringToUnicodeString(theXalanDFS->getCurrencySymbol()));
  +			theDFS->setInternationalCurrencySymbol(XalanDOMStringToUnicodeString(theXalanDFS->getInternationalCurrencySymbol()));
  +			theDFS->setMonetaryDecimalSeparator(theXalanDFS->getMonetaryDecimalSeparator());
  +		}
  +
  +		UnicodeString	theUnicodeResult;
   
  +		// Construct a DecimalFormat.  Note that we release the auto_ptr, since the
  +		// DecimalFormat will adopt the DecimalFormatSymbols instance.
  +		DecimalFormat	theFormatter(XalanDOMStringToUnicodeString(thePattern), theDFS.release(), theStatus);
  +
   		if (theStatus == U_ZERO_ERROR ||
   			theStatus == U_USING_DEFAULT_ERROR)
   		{
   			// Do the format...
   			theFormatter.format(theNumber, theUnicodeResult);
  -
  -			const int32_t	theLength = theUnicodeResult.length();
  -
  -			// Resize the vector to the appropriate length...
  -			theResult.clear();
  -			theResult.resize(theLength);
   
  -			theUnicodeResult.extract(0, theLength, &theResult[0]);
  +			UnicodeStringToXalanDOMString(theUnicodeResult, theResult);
   
   			theStatus = U_ZERO_ERROR;
   		}
  @@ -177,51 +277,40 @@
   
   
   int
  -ICUBridge::strLength(const UnicodeCharType*		theString)
  +ICUBridge::collationCompare(
  +			const XalanDOMString&	theLHS,
  +			const XalanDOMString&	theRHS)
   {
  -	if (theString == 0)
  -	{
  -		return 0;
  -	}
  -	else
  -	{
  -		const UnicodeCharType*	current = theString;
  -
  -		while(*current)
  -		{
  -			++current;
  -		}
  -
  -		return current - theString;
  -	}
  +	// Just call to the XalanDOMChar* version...
  +	return collationCompare(c_wstr(theLHS), c_wstr(theRHS));
   }
   
   
   
   int
   ICUBridge::collationCompare(
  -			const UnicodeCharType*		theLHS,
  -			const UnicodeCharType*		theRHS)
  +			const XalanDOMChar*		theLHS,
  +			const XalanDOMChar*		theRHS)
   {
   #if !defined(XALAN_NO_NAMESPACES)
   	using std::auto_ptr;
   #endif
   
  -	const UnicodeString		theUnicodeLHS(theLHS, strLength(theLHS));
  -	const UnicodeString		theUnicodeRHS(theRHS, strLength(theRHS));
  -
   	UErrorCode				theStatus = U_ZERO_ERROR;
   
  -	auto_ptr<Collator>	theCollator(Collator::createInstance(theStatus));
  +	// Create a collcator, and keep it in an auto_ptr
  +	const auto_ptr<Collator>	theCollator(Collator::createInstance(theStatus));
   
   	if (theStatus == U_ZERO_ERROR || theStatus == U_USING_DEFAULT_ERROR)
   	{
  +		// OK, do the compare...
   		return theCollator->compare(
  -					theUnicodeLHS,
  -					theUnicodeRHS);
  +					XalanDOMCharStringToUnicodeString(theLHS),
  +					XalanDOMCharStringToUnicodeString(theRHS));
   	}
   	else
   	{
  -		return theUnicodeLHS.compare(theUnicodeRHS);
  +		// If creating the ICU Collator failed, fall back to the default...
  +		return collationCompare(theLHS, theRHS);
   	}
   }
  
  
  
  1.3       +29 -30    xml-xalan/c/src/ICUBridge/ICUBridge.hpp
  
  Index: ICUBridge.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/ICUBridge/ICUBridge.hpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ICUBridge.hpp	2000/07/10 01:04:59	1.2
  +++ ICUBridge.hpp	2000/07/12 21:45:39	1.3
  @@ -68,50 +68,49 @@
   
   
   
  +#include <XalanDOM/XalanDOMString.hpp>
  +
  +
  +
  +class UnicodeString;
  +class XalanDecimalFormatSymbols;
  +
  +
  +
   class XALAN_ICUBRIDGE_EXPORT ICUBridge
   {
   public:
   
  -	typedef wchar_t							UnicodeCharType;
  +	static const UnicodeString
  +	XalanDOMCharStringToUnicodeString(const XalanDOMChar*	theString);
   
  -#if defined(XALAN_NO_NAMESPACES
  -	typedef vector<unsigned short>			UTF16VectorType;
  -#else
  -	typedef std::vector<unsigned short>		UTF16VectorType;
  -#endif
  +	static const UnicodeString
  +	XalanDOMStringToUnicodeString(const XalanDOMString&		theString);
   
  -	static unsigned long
  -	FormatNumber(
  -			const UTF16VectorType&		thePattern,
  -			double						theNumber,
  -			UTF16VectorType&			theResult);
  +	static const XalanDOMString
  +	UnicodeStringToXalanDOMString(const UnicodeString&	theString);
   
  +	static void
  +	UnicodeStringToXalanDOMString(
  +			const UnicodeString&	theString,
  +			XalanDOMString&			theResult);
  +
   	static unsigned long
   	FormatNumber(
  -			const UTF16VectorType&		thePattern,
  -			double						theNumber,
  -			const UTF16VectorType&		theCurrencySymbolString,
  -			unsigned short				theDecimalSeparatorChar,
  -			unsigned short				theDigitChar,
  -			unsigned short				theGroupingSeparatorChar,
  -			const UTF16VectorType&		theInfinityString,
  -			const UTF16VectorType&		theInternationalCurrencySymbolString,
  -			unsigned short				theMinusSignChar,
  -			unsigned short				theMonetaryDecimalSeparatorChar,
  -			const UTF16VectorType&		theNaNString,
  -			unsigned short				thePatternSeparatorChar,
  -			unsigned short				thePercentChar,
  -			unsigned short				thePerMillChar,
  -			unsigned short				theZeroDigitChar,
  -			UTF16VectorType&			theResult);
  +			const XalanDOMString&				thePattern,
  +			double								theNumber,
  +			const XalanDecimalFormatSymbols*	theXalanDFS,
  +			XalanDOMString&						theResult);
   
   	static int
   	collationCompare(
  -			const UnicodeCharType*		theLHS,
  -			const UnicodeCharType*		theRHS);
  +			const XalanDOMString&	theLHS,
  +			const XalanDOMString&	theRHS);
   
   	static int
  -	strLength(const UnicodeCharType*	theString);
  +	collationCompare(
  +			const XalanDOMChar*		theLHS,
  +			const XalanDOMChar*		theRHS);
   };
   
   
  
  
  
  1.2       +6 -5      xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctor.cpp
  
  Index: ICUBridgeCollationCompareFunctor.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/ICUBridge/ICUBridgeCollationCompareFunctor.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ICUBridgeCollationCompareFunctor.cpp	2000/07/10 01:04:35	1.1
  +++ ICUBridgeCollationCompareFunctor.cpp	2000/07/12 21:45:39	1.2
  @@ -60,6 +60,10 @@
   
   
   
  +#include <PlatformSupport/DOMStringHelper.hpp>
  +
  +
  +
   #include <unicode/coll.h>
   
   
  @@ -104,11 +108,8 @@
   	{
   		assert(m_collator != 0);
   
  -		const UnicodeString		theUnicodeLHS(theLHS, ICUBridge::strLength(theLHS));
  -		const UnicodeString		theUnicodeRHS(theRHS, ICUBridge::strLength(theRHS));
  -
   		return m_collator->compare(
  -					theUnicodeLHS,
  -					theUnicodeRHS);
  +					ICUBridge::XalanDOMCharStringToUnicodeString(theLHS),
  +					ICUBridge::XalanDOMCharStringToUnicodeString(theRHS));
   	}
   }