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/09/19 16:36:56 UTC

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

dbertoni    00/09/19 07:36:32

  Modified:    c/src/ICUBridge ICUBridge.cpp
  Log:
  Use our own default XalanDecimalFormatSymbols to get proper XSLT-default number formatting.
  
  Revision  Changes    Path
  1.7       +64 -31    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ICUBridge.cpp	2000/08/22 20:17:54	1.6
  +++ ICUBridge.cpp	2000/09/19 14:36:07	1.7
  @@ -65,6 +65,10 @@
   
   
   
  +#include <PlatformSupport/DoubleSupport.hpp>
  +
  +
  +
   #include <unicode/coll.h>
   #include <unicode/dcfmtsym.h>
   #include <unicode/decimfmt.h>
  @@ -209,48 +213,44 @@
   
   
   
  -unsigned long
  -ICUBridge::FormatNumber(
  +static void
  +doFormatNumber(
   			const XalanDOMString&				thePattern,
   			double								theNumber,
  -			const XalanDecimalFormatSymbols*	theXalanDFS,
  +			const XalanDecimalFormatSymbols&	theXalanDFS,
  +			UErrorCode&							theStatus,
   			XalanDOMString&						theResult)
   {
  -	UErrorCode				theStatus = U_ZERO_ERROR;
  -
  -	// Use a XalanAutoPtr, to keep this safe until we construct the DecimalFormat instance.
  -	XalanAutoPtr<DecimalFormatSymbols>	theDFS(new DecimalFormatSymbols(theStatus));
  -
   	if (theStatus == U_ZERO_ERROR ||
   		theStatus == U_USING_DEFAULT_ERROR)
   	{
  -		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());
  -		}
  +		// Use a XalanAutoPtr, to keep this safe until we construct the DecimalFormat instance.
  +		XalanAutoPtr<DecimalFormatSymbols>	theDFS(new DecimalFormatSymbols(theStatus));
   
  +		// 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(ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getInfinity()));
  +		theDFS->setNaN(ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getNaN()));
  +	//	theDFS->setPlusSign(theZeroDigitChar);
  +		theDFS->setMinusSign(theXalanDFS.getMinusSign());
  +	//	theDFS->setExponentialSymbol(theZeroDigitChar);
  +		theDFS->setCurrencySymbol(ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getCurrencySymbol()));
  +		theDFS->setInternationalCurrencySymbol(ICUBridge::XalanDOMStringToUnicodeString(theXalanDFS.getInternationalCurrencySymbol()));
  +		theDFS->setMonetaryDecimalSeparator(theXalanDFS.getMonetaryDecimalSeparator());
  +
   		UnicodeString	theUnicodeResult;
   
   		// Construct a DecimalFormat.  Note that we release the XalanAutoPtr, since the
   		// DecimalFormat will adopt the DecimalFormatSymbols instance.
  -		DecimalFormat	theFormatter(XalanDOMStringToUnicodeString(thePattern), theDFS.release(), theStatus);
  +		DecimalFormat	theFormatter(ICUBridge::XalanDOMStringToUnicodeString(thePattern), theDFS.release(), theStatus);
   
   		if (theStatus == U_ZERO_ERROR ||
   			theStatus == U_USING_DEFAULT_ERROR)
  @@ -258,10 +258,43 @@
   			// Do the format...
   			theFormatter.format(theNumber, theUnicodeResult);
   
  -			UnicodeStringToXalanDOMString(theUnicodeResult, theResult);
  +			ICUBridge::UnicodeStringToXalanDOMString(theUnicodeResult, theResult);
   
   			theStatus = U_ZERO_ERROR;
   		}
  +	}
  +}
  +
  +
  +
  +unsigned long
  +ICUBridge::FormatNumber(
  +			const XalanDOMString&				thePattern,
  +			double								theNumber,
  +			const XalanDecimalFormatSymbols*	theXalanDFS,
  +			XalanDOMString&						theResult)
  +{
  +	UErrorCode	theStatus = U_ZERO_ERROR;
  +
  +	if (theXalanDFS == 0)
  +	{
  +		XalanDecimalFormatSymbols	theDefaultSymbols;
  +
  +		doFormatNumber(
  +				thePattern,
  +				theNumber,
  +				theDefaultSymbols,
  +				theStatus,
  +				theResult);
  +	}
  +	else
  +	{
  +		doFormatNumber(
  +				thePattern,
  +				theNumber,
  +				*theXalanDFS,
  +				theStatus,
  +				theResult);
   	}
   
   	return theStatus;