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/10 03:05:00 UTC

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

dbertoni    00/07/09 18:05:00

  Modified:    c/src/ICUBridge ICUBridge.cpp ICUBridge.hpp
  Log:
  New collation function.
  
  Revision  Changes    Path
  1.2       +61 -2     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ICUBridge.cpp	2000/05/08 17:13:13	1.1
  +++ ICUBridge.cpp	2000/07/10 01:04:59	1.2
  @@ -59,6 +59,11 @@
   
   
   
  +#include <memory>
  +
  +
  +
  +#include <unicode/coll.h>
   #include <unicode/dcfmtsym.h>
   #include <unicode/decimfmt.h>
   
  @@ -70,7 +75,6 @@
   			double						theNumber,
   			UTF16VectorType&			theResult)
   {
  -
   	const UnicodeString		theUnicodePattern(&thePattern[0], thePattern.size());
   
   	UErrorCode				theStatus = U_ZERO_ERROR;
  @@ -79,7 +83,8 @@
   
   	DecimalFormat			theFormatter(theUnicodePattern, theStatus);
   
  -	if (theStatus == U_ZERO_ERROR)
  +	if (theStatus == U_ZERO_ERROR ||
  +		theStatus == U_USING_DEFAULT_ERROR)
   	{
   		// Do the format...
   		theFormatter.format(theNumber, theUnicodeResult);
  @@ -91,6 +96,8 @@
   		theResult.resize(theLength);
   
   		theUnicodeResult.extract(0, theLength, &theResult[0]);
  +
  +		theStatus = U_ZERO_ERROR;
   	}
   
   	return theStatus;
  @@ -161,4 +168,56 @@
   	}
   
   	return theStatus;
  +}
  +
  +
  +
  +int
  +ICUBridge::strLength(const UnicodeCharType*		theString)
  +{
  +	if (theString == 0)
  +	{
  +		return 0;
  +	}
  +	else
  +	{
  +		const UnicodeCharType*	current = theString;
  +
  +		while(*current)
  +		{
  +			++current;
  +		}
  +
  +		return current - theString;
  +	}
  +}
  +
  +
  +
  +int
  +ICUBridge::collationCompare(
  +			const UnicodeCharType*		theLHS,
  +			const UnicodeCharType*		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));
  +
  +	if (theStatus == U_ZERO_ERROR || theStatus == U_USING_DEFAULT_ERROR)
  +	{
  +		return theCollator->compare(
  +					theUnicodeLHS,
  +					theUnicodeRHS);
  +	}
  +	else
  +	{
  +		return theUnicodeLHS.compare(theUnicodeRHS);
  +	}
   }
  
  
  
  1.2       +10 -0     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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ICUBridge.hpp	2000/05/08 17:13:13	1.1
  +++ ICUBridge.hpp	2000/07/10 01:04:59	1.2
  @@ -72,6 +72,8 @@
   {
   public:
   
  +	typedef wchar_t							UnicodeCharType;
  +
   #if defined(XALAN_NO_NAMESPACES
   	typedef vector<unsigned short>			UTF16VectorType;
   #else
  @@ -102,6 +104,14 @@
   			unsigned short				thePerMillChar,
   			unsigned short				theZeroDigitChar,
   			UTF16VectorType&			theResult);
  +
  +	static int
  +	collationCompare(
  +			const UnicodeCharType*		theLHS,
  +			const UnicodeCharType*		theRHS);
  +
  +	static int
  +	strLength(const UnicodeCharType*	theString);
   };