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 2005/05/10 23:02:04 UTC
cvs commit: xml-xalan/c/src/xalanc/ICUBridge ICUFormatNumberFunctor.cpp ICUFormatNumberFunctor.hpp
dbertoni 2005/05/10 14:02:04
Modified: c/src/xalanc/ICUBridge ICUFormatNumberFunctor.cpp
ICUFormatNumberFunctor.hpp
Log:
Fix for Jira issue XALANC-513.
Revision Changes Path
1.10 +119 -50 xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.cpp
Index: ICUFormatNumberFunctor.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ICUFormatNumberFunctor.cpp 8 May 2005 01:11:17 -0000 1.9
+++ ICUFormatNumberFunctor.cpp 10 May 2005 21:02:04 -0000 1.10
@@ -48,14 +48,9 @@
ICUFormatNumberFunctor::ICUFormatNumberFunctor(MemoryManagerType& theManager) :
m_decimalFormatCache(theManager),
- m_defaultDecimalFormat(0),
+ m_defaultDecimalFormat(theManager, createDecimalFormat(theManager)),
m_memoryManager(theManager)
{
- XalanDecimalFormatSymbols tmpFormat(theManager);
-
- DecimalFormatType** tmpFormatPtr = const_cast<DecimalFormatType**>(&m_defaultDecimalFormat) ;
-
- (*tmpFormatPtr)= createDecimalFormat(tmpFormat);
}
@@ -80,14 +75,12 @@
ICUFormatNumberFunctor::~ICUFormatNumberFunctor()
{
- delete m_defaultDecimalFormat;
-
XALAN_USING_STD(for_each)
for_each(
m_decimalFormatCache.begin(),
m_decimalFormatCache.end(),
- DecimalFormatCacheStruct::DecimalFormatDeleteFunctor());
+ DecimalFormatCacheStruct::DecimalFormatDeleteFunctor(m_memoryManager));
}
@@ -155,7 +148,7 @@
{
// Save the formatter, because splice() may invalidate
// i.
- DecimalFormatType* const theFormatter = (*i).m_formatter;
+ DecimalFormatType* const theFormatter = (*i).m_formatter;
// Move the entry to the beginning the cache
theNonConstCache.splice(theBegin, theNonConstCache, i);
@@ -177,36 +170,48 @@
if (theDFS == 0)
{
- return doICUFormat(theNumber,thePattern,theResult);
+ return doICUFormat(theNumber, thePattern, theResult);
}
- XalanDOMString nonLocalPattern(theResult.getMemoryManager());
+ XalanDOMString nonLocalPattern(m_memoryManager);
- UnlocalizePatternFunctor formatter(*theDFS);
+ UnlocalizePatternFunctor formatter(*theDFS);
- formatter(thePattern, nonLocalPattern);
+ formatter(thePattern, nonLocalPattern, m_memoryManager);
- DecimalFormatType* theFormatter = getCachedDecimalFormat(*theDFS);
+ DecimalFormatType* const theFormatter =
+ getCachedDecimalFormat(*theDFS);
if (theFormatter != 0)
{
- return doICUFormat(theNumber, nonLocalPattern, theResult, theFormatter);
+ return doICUFormat(
+ theNumber,
+ nonLocalPattern,
+ theResult,
+ theFormatter);
}
else
{
- XalanAutoPtr<DecimalFormatType> theDecimalFormatGuard(createDecimalFormat(*theDFS));
+ DFAutoPtrType theDecimalFormatGuard(
+ m_memoryManager,
+ createDecimalFormat(*theDFS, m_memoryManager));
- if (theDecimalFormatGuard.get() !=0)
+ if (theDecimalFormatGuard.get() != 0)
{
// OK, there was no error, so cache the instance...
cacheDecimalFormat(theDecimalFormatGuard.get(), *theDFS);
// Release the collator, since it's in the cache and
// will be controlled by the cache...
- DecimalFormatType * theDecimalFormat = theDecimalFormatGuard.release();
+ DecimalFormatType* const theDecimalFormat =
+ theDecimalFormatGuard.releasePtr();
- return doICUFormat(theNumber, nonLocalPattern, theResult, theDecimalFormat);
+ return doICUFormat(
+ theNumber,
+ nonLocalPattern,
+ theResult,
+ theDecimalFormat);
}
else
{
@@ -217,42 +222,99 @@
-DecimalFormatType *
+DecimalFormatType*
ICUFormatNumberFunctor::createDecimalFormat(
- const XalanDecimalFormatSymbols& theXalanDFS) const
+ const XalanDecimalFormatSymbols& theXalanDFS,
+ MemoryManager& theManager)
{
UErrorCode theStatus = U_ZERO_ERROR;
-
+
// 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->setSymbol(DecimalFormatSymbols::kZeroDigitSymbol, UChar(theXalanDFS.getZeroDigit()));
- theDFS->setSymbol(DecimalFormatSymbols::kGroupingSeparatorSymbol, UChar(theXalanDFS.getGroupingSeparator()));
- theDFS->setSymbol(DecimalFormatSymbols::kDecimalSeparatorSymbol, UChar(theXalanDFS.getDecimalSeparator()));
- theDFS->setSymbol(DecimalFormatSymbols::kPerMillSymbol, UChar(theXalanDFS.getPerMill()));
- theDFS->setSymbol(DecimalFormatSymbols::kPercentSymbol, UChar(theXalanDFS.getPercent()));
- theDFS->setSymbol(DecimalFormatSymbols::kDigitSymbol, UChar(theXalanDFS.getDigit()));
- theDFS->setSymbol(DecimalFormatSymbols::kPatternSeparatorSymbol, UChar(theXalanDFS.getPatternSeparator()));
-
- theDFS->setSymbol(DecimalFormatSymbols::kInfinitySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getInfinity()));
- theDFS->setSymbol(DecimalFormatSymbols::kNaNSymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager,theXalanDFS.getNaN()));
- theDFS->setSymbol(DecimalFormatSymbols::kMinusSignSymbol, UChar(theXalanDFS.getMinusSign()));
- theDFS->setSymbol(DecimalFormatSymbols::kCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getCurrencySymbol()));
- theDFS->setSymbol(DecimalFormatSymbols::kIntlCurrencySymbol, ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, theXalanDFS.getInternationalCurrencySymbol()));
- theDFS->setSymbol(DecimalFormatSymbols::kMonetarySeparatorSymbol, UChar(theXalanDFS.getMonetaryDecimalSeparator()));
-
- // Construct a DecimalFormat. Note that we release the XalanAutoPtr, since the
- // DecimalFormat will adopt the DecimalFormatSymbols instance.
- DecimalFormatType * theFormatter= new DecimalFormatType("", theDFS.release(), theStatus);
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kZeroDigitSymbol,
+ UChar(theXalanDFS.getZeroDigit()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kGroupingSeparatorSymbol,
+ UChar(theXalanDFS.getGroupingSeparator()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kDecimalSeparatorSymbol,
+ UChar(theXalanDFS.getDecimalSeparator()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kPerMillSymbol,
+ UChar(theXalanDFS.getPerMill()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kPercentSymbol,
+ UChar(theXalanDFS.getPercent()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kDigitSymbol,
+ UChar(theXalanDFS.getDigit()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kPatternSeparatorSymbol,
+ UChar(theXalanDFS.getPatternSeparator()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kInfinitySymbol,
+ ICUBridge::XalanDOMStringToUnicodeString(
+ theManager,
+ theXalanDFS.getInfinity()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kNaNSymbol,
+ ICUBridge::XalanDOMStringToUnicodeString(
+ theManager,
+ theXalanDFS.getNaN()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kMinusSignSymbol,
+ UChar(theXalanDFS.getMinusSign()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kCurrencySymbol,
+ ICUBridge::XalanDOMStringToUnicodeString(
+ theManager,
+ theXalanDFS.getCurrencySymbol()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kIntlCurrencySymbol,
+ ICUBridge::XalanDOMStringToUnicodeString(
+ theManager,
+ theXalanDFS.getInternationalCurrencySymbol()));
+
+ theDFS->setSymbol(
+ DecimalFormatSymbols::kMonetarySeparatorSymbol,
+ UChar(theXalanDFS.getMonetaryDecimalSeparator()));
+
+ // Construct a DecimalFormat instance.
+ DecimalFormatType* theFormatter = 0;
+
+ XalanConstruct(
+ theManager,
+ theFormatter,
+ theStatus);
+
+ // Guard this, just in case something happens before
+ // we return it.
+ DFAutoPtrType theGuard(theManager, theFormatter);
if (U_SUCCESS(theStatus))
{
- return theFormatter;
+ // Note that we release the XalanAutoPtr, since the
+ // DecimalFormat will adopt the DecimalFormatSymbols instance.
+ theGuard->adoptDecimalFormatSymbols(theDFS.release());
+
+ return theGuard.releasePtr();
}
else
{
- delete theFormatter;
return 0;
}
}
@@ -278,12 +340,14 @@
if (theNonConstCache.size() == eCacheMax)
{
// Yes, so guard the collator instance, in case pop_back() throws...
- XalanAutoPtr<DecimalFormatType> theDecimalFormatGuard(theNonConstCache.back().m_formatter);
+ DFAutoPtrType theDecimalFormatGuard(
+ m_memoryManager,
+ theNonConstCache.back().m_formatter);
theNonConstCache.pop_back();
}
- DecimalFormatCacheListType::value_type emptyDFC(m_memoryManager);
+ const DecimalFormatCacheListType::value_type emptyDFC(m_memoryManager);
theNonConstCache.push_front(emptyDFC);
@@ -307,9 +371,9 @@
if (theFormatter == 0)
{
- if (m_defaultDecimalFormat != 0)
+ if (m_defaultDecimalFormat.get() != 0)
{
- theFormatter = m_defaultDecimalFormat;
+ theFormatter = m_defaultDecimalFormat.get();
}
else
{
@@ -317,7 +381,9 @@
}
}
- theFormatter->applyPattern(ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, thePattern),theStatus);
+ theFormatter->applyPattern(
+ ICUBridge::XalanDOMStringToUnicodeString(m_memoryManager, thePattern),
+ theStatus);
if (U_SUCCESS(theStatus))
{
@@ -331,10 +397,13 @@
}
XalanDOMString&
-ICUFormatNumberFunctor::UnlocalizePatternFunctor::operator()(const XalanDOMString& thePattern, XalanDOMString& theResult) const
+ICUFormatNumberFunctor::UnlocalizePatternFunctor::operator()(
+ const XalanDOMString& thePattern,
+ XalanDOMString& theResult,
+ MemoryManager& theManager) const
{
- XalanDecimalFormatSymbols defaultDFS( theResult.getMemoryManager());
+ XalanDecimalFormatSymbols defaultDFS(theManager);
XalanDOMString::const_iterator iterator = thePattern.begin();
1.7 +55 -17 xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.hpp
Index: ICUFormatNumberFunctor.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/xalanc/ICUBridge/ICUFormatNumberFunctor.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ICUFormatNumberFunctor.hpp 29 Apr 2005 21:39:42 -0000 1.6
+++ ICUFormatNumberFunctor.hpp 10 May 2005 21:02:04 -0000 1.7
@@ -23,6 +23,10 @@
+#include <xalanc/Include/XalanMemMgrAutoPtr.hpp>
+
+
+
#include <xalanc/PlatformSupport/XalanDecimalFormatSymbols.hpp>
@@ -62,26 +66,29 @@
{
}
- DecimalFormatCacheStruct(MemoryManagerType& theManager) :
- m_DFS(theManager),
+ DecimalFormatCacheStruct(MemoryManagerType& theManager) :
+ m_DFS(theManager),
m_formatter(0)
{
}
- DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other, MemoryManagerType& theManager) :
- m_DFS(other.m_DFS, theManager),
+ DecimalFormatCacheStruct(
+ const DecimalFormatCacheStruct& other,
+ MemoryManagerType& theManager) :
+ m_DFS(other.m_DFS, theManager),
m_formatter(other.m_formatter)
{
}
+
#if defined(XALAN_NO_SELECTIVE_TEMPLATE_INSTANTIATION)
bool
- operator<(const DecimalFormatCacheStruct& theRHS) const
+ operator<(const DecimalFormatCacheStruct& theRHS) const
{
return this < &theRHS;
}
bool
- operator==(const DecimalFormatCacheStruct& theRHS) const
+ operator==(const DecimalFormatCacheStruct& theRHS) const
{
return this == &theRHS;
}
@@ -91,14 +98,33 @@
DecimalFormatType * m_formatter;
- struct DecimalFormatDeleteFunctor
+ class DecimalFormatDeleteFunctor
{
+ public:
+
+ DecimalFormatDeleteFunctor(MemoryManager& theManager) :
+ m_memoryManager(theManager)
+ {
+ }
void
- operator()(DecimalFormatCacheStruct& theStruct) const
+ operator()(DecimalFormatCacheStruct& theStruct) const
{
- delete theStruct.m_formatter;
+ assert(theStruct.m_formatter != 0);
+
+ XalanDestroy(
+ m_memoryManager,
+ *theStruct.m_formatter);
}
+
+ private:
+
+ // Not implemented...
+ DecimalFormatDeleteFunctor&
+ operator=(const DecimalFormatDeleteFunctor&);
+
+ // Data members.
+ MemoryManager& m_memoryManager;
};
struct DecimalFormatFindFunctor
@@ -121,7 +147,6 @@
DecimalFormatCacheStruct();
DecimalFormatCacheStruct(const DecimalFormatCacheStruct& other);
-
};
@@ -161,15 +186,18 @@
}
XalanDOMString&
- operator()(const XalanDOMString& thePattern, XalanDOMString& theResult) const;
+ operator()(
+ const XalanDOMString& thePattern,
+ XalanDOMString& theResult,
+ MemoryManager& theManager) const;
private:
- const XalanDecimalFormatSymbols& m_DFS;
+
+ const XalanDecimalFormatSymbols& m_DFS;
};
typedef XalanList<DecimalFormatCacheStruct> DecimalFormatCacheListType;
-
private:
DecimalFormatType*
@@ -194,9 +222,18 @@
DecimalFormatType* theFormatter,
const XalanDecimalFormatSymbols& theDFS) const;
- DecimalFormat *
+ static DecimalFormat*
createDecimalFormat(
- const XalanDecimalFormatSymbols& theXalanDFS) const;
+ const XalanDecimalFormatSymbols& theXalanDFS,
+ MemoryManager& theManager);
+
+ static DecimalFormat*
+ createDecimalFormat(MemoryManager& theManager)
+ {
+ const XalanDecimalFormatSymbols theDFS(theManager);
+
+ return createDecimalFormat(theDFS, theManager);
+ }
enum { eCacheMax = 10u };
@@ -209,13 +246,14 @@
bool
operator==(const ICUFormatNumberFunctor&) const;
+ typedef XalanMemMgrAutoPtr<DecimalFormatType> DFAutoPtrType;
// Data members...
mutable DecimalFormatCacheListType m_decimalFormatCache;
- DecimalFormatType* const m_defaultDecimalFormat;
+ const DFAutoPtrType m_defaultDecimalFormat;
- MemoryManagerType& m_memoryManager;
+ MemoryManagerType& m_memoryManager;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org