dbertoni    01/06/14 12:04:10

  Modified:    c/src/PlatformSupport XalanDecimalFormat.cpp
                        XalanDecimalFormat.hpp XalanNumberFormat.cpp
                        XalanNumberFormat.hpp
  Log:
  New formatting overloads.
  
  Revision  Changes    Path
  1.2       +60 -4     xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.cpp
  
  Index: XalanDecimalFormat.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XalanDecimalFormat.cpp    2000/05/08 17:17:05     1.1
  +++ XalanDecimalFormat.cpp    2001/06/14 19:04:02     1.2
  @@ -58,6 +58,7 @@
   #include "DOMStringHelper.hpp"
   
   
  +
   const XalanDOMString XalanDecimalFormat::s_defaultPatternString;
   
   
  @@ -66,8 +67,8 @@
                        const XalanDOMString&                           
thePatternString,
                        const XalanDecimalFormatSymbols&        theSymbols) :
        XalanNumberFormat(),
  -     m_patternString(length(thePatternString) == 0 ? s_defaultPatternString 
: thePatternString),
  -     m_decimalFormatSymbols(theSymbols)
  +     m_patternString(thePatternString),
  +     m_decimalFormatSymbols(&theSymbols)
   {
   }
   
  @@ -88,6 +89,17 @@
   
   
   
  +void
  +XalanDecimalFormat::format(
  +                     double                          theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     XalanNumberFormat::format(theValue, theResult);
  +}
  +
  +
  +
   XalanDOMString
   XalanDecimalFormat::format(int       theValue)
   {
  @@ -97,6 +109,17 @@
   
   
   
  +void
  +XalanDecimalFormat::format(
  +                     int                                     theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     XalanNumberFormat::format(theValue, theResult);
  +}
  +
  +
  +
   XalanDOMString
   XalanDecimalFormat::format(unsigned int      theValue)
   {
  @@ -106,6 +129,17 @@
   
   
   
  +void
  +XalanDecimalFormat::format(
  +                     unsigned int            theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     XalanNumberFormat::format(theValue, theResult);
  +}
  +
  +
  +
   XalanDOMString
   XalanDecimalFormat::format(long      theValue)
   {
  @@ -115,6 +149,17 @@
   
   
   
  +void
  +XalanDecimalFormat::format(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     XalanNumberFormat::format(theValue, theResult);
  +}
  +
  +
  +
   XalanDOMString
   XalanDecimalFormat::format(unsigned long     theValue)
   {
  @@ -125,6 +170,17 @@
   
   
   void
  +XalanDecimalFormat::format(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     XalanNumberFormat::format(theValue, theResult);
  +}
  +
  +
  +
  +void
   XalanDecimalFormat::applyPattern(const XalanDOMString&       thePattern)
   {
        // $$$ ToDo: Fix this!!!
  @@ -149,7 +205,7 @@
        // numbers, then assume that the pattern for negative
        // numbers is the same as that for positive numbers.
        const XalanDOMChar      thePatternSeparatorChar =
  -             m_decimalFormatSymbols.getPatternSeparator();
  +             m_decimalFormatSymbols->getPatternSeparator();
   
        // Is the a separator?
        const unsigned int      theSeparatorIndex =
  @@ -166,7 +222,7 @@
                XalanDOMString  theNewPattern(thePattern);
   
                theNewPattern += thePatternSeparatorChar;
  -             theNewPattern += m_decimalFormatSymbols.getMinusSign();
  +             theNewPattern += m_decimalFormatSymbols->getMinusSign();
                theNewPattern += thePattern;
   
                return theNewPattern;
  
  
  
  1.2       +31 -8     xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.hpp
  
  Index: XalanDecimalFormat.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.hpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XalanDecimalFormat.hpp    2000/05/08 17:17:05     1.1
  +++ XalanDecimalFormat.hpp    2001/06/14 19:04:03     1.2
  @@ -85,10 +85,9 @@
         * @param theSymbols       class defining the symbols used for output, 
for
         *                         example, symbol for currency
         */
  -     explicit
        XalanDecimalFormat(
  -                     const XalanDOMString&                           
thePatternString = XalanDOMString(),
  -                     const XalanDecimalFormatSymbols&        theSymbols = 
XalanDecimalFormatSymbols());
  +                     const XalanDOMString&                           
thePatternString,
  +                     const XalanDecimalFormatSymbols&        theSymbols);
   
        virtual
        ~XalanDecimalFormat();
  @@ -97,18 +96,42 @@
        virtual XalanDOMString
        format(double   theValue);
   
  +     virtual void
  +     format(
  +                     double                          theValue,
  +                     XalanDOMString&         theResult);
  +
        virtual XalanDOMString
        format(int      theValue);
   
  +     virtual void
  +     format(
  +                     int                                     theValue,
  +                     XalanDOMString&         theResult);
  +
        virtual XalanDOMString
        format(unsigned int             theValue);
   
  +     virtual void
  +     format(
  +                     unsigned int            theValue,
  +                     XalanDOMString&         theResult);
  +
        virtual XalanDOMString
        format(long             theValue);
   
  +     virtual void
  +     format(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult);
  +
        virtual XalanDOMString
        format(unsigned long    theValue);
   
  +     virtual void
  +     format(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult);
   
        // New for XalanDecimalFormat...
   
  @@ -121,7 +144,7 @@
        const XalanDecimalFormatSymbols&
        getDecimalFormatSymbols() const
        {
  -             return m_decimalFormatSymbols;
  +             return *m_decimalFormatSymbols;
        }
   
        /**
  @@ -133,7 +156,7 @@
        void
        setDecimalFormatSymbols(const XalanDecimalFormatSymbols&        
theDecimalFormatSymbols)
        {
  -             m_decimalFormatSymbols = theDecimalFormatSymbols;
  +             m_decimalFormatSymbols = &theDecimalFormatSymbols;
        }
   
        void
  @@ -160,11 +183,11 @@
   
   
        // Data members...
  -     XalanDOMString                                  m_patternString;
  +     XalanDOMString                                          m_patternString;
   
  -     XalanDecimalFormatSymbols               m_decimalFormatSymbols;
  +     const XalanDecimalFormatSymbols*        m_decimalFormatSymbols;
   
  -     static const XalanDOMString             s_defaultPatternString;
  +     static const XalanDOMString                     s_defaultPatternString;
   };
   
   
  
  
  
  1.9       +133 -34   xml-xalan/c/src/PlatformSupport/XalanNumberFormat.cpp
  
  Index: XalanNumberFormat.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanNumberFormat.cpp,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XalanNumberFormat.cpp     2001/04/30 18:07:06     1.8
  +++ XalanNumberFormat.cpp     2001/06/14 19:04:04     1.9
  @@ -92,10 +92,27 @@
   
   
   XalanDOMString
  -XalanNumberFormat::format(double             theValue)
  +XalanNumberFormat::format(double     theValue)
   {
        // $$$ ToDo: Fix this!
  -     return applyGrouping(DoubleToDOMString(theValue));
  +     XalanDOMString  theResult;
  +
  +     format(theValue, theResult);
  +
  +     return theResult;
  +}
  +
  +
  +
  +void
  +XalanNumberFormat::format(
  +                     double                          theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     DoubleToDOMString(theValue, theResult);
  +
  +     applyGrouping(theResult, theResult);
   }
   
   
  @@ -104,16 +121,50 @@
   XalanNumberFormat::format(int        theValue)
   {
        // $$$ ToDo: Fix this!
  -     return applyGrouping(LongToDOMString(theValue));
  +     XalanDOMString  theResult;
  +
  +     format(theValue, theResult);
  +
  +     return theResult;
   }
   
   
   
  +void
  +XalanNumberFormat::format(
  +                     int                                     theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     LongToDOMString(theValue, theResult);
  +
  +     applyGrouping(theResult, theResult);
  +}
  +
  +
  +
   XalanDOMString
   XalanNumberFormat::format(unsigned int       theValue)
   {
  +     // $$$ ToDo: Fix this!
  +     XalanDOMString  theResult;
  +
  +     format(theValue, theResult);
  +
  +     return theResult;
  +}
  +
  +
  +
  +void
  +XalanNumberFormat::format(
  +                     unsigned int            theValue,
  +                     XalanDOMString&         theResult)
  +{
        // $$$ ToDo: Fix this!
  -     return applyGrouping(UnsignedLongToDOMString(theValue));
  +     UnsignedLongToDOMString(theValue, theResult);
  +
  +     applyGrouping(theResult, theResult);
   }
   
   
  @@ -121,58 +172,106 @@
   XalanDOMString
   XalanNumberFormat::format(long       theValue)
   {
  +     // $$$ ToDo: Fix this!
  +     XalanDOMString  theResult;
  +
  +     format(theValue, theResult);
  +
  +     return theResult;
  +}
  +
  +
  +
  +void
  +XalanNumberFormat::format(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult)
  +{
        // $$$ ToDo: Fix this!
  -     return applyGrouping(LongToDOMString(theValue));
  +     LongToDOMString(theValue, theResult);
  +
  +     applyGrouping(theResult, theResult);
   }
   
   
   
   XalanDOMString
  -XalanNumberFormat::applyGrouping(const XalanDOMString& value)
  -/*
  - * Convert a string value using the currently active values for grouping size
  - * and separator; returns the converted string
  - */
  +XalanNumberFormat::format(unsigned long              theValue)
   {
  -     if (!m_isGroupingUsed) return value;
  -     if (m_groupingSize == 0) return value;
  -     const unsigned int len = length(value);
  -     if (len == 0) return value;
  +     // $$$ ToDo: Fix this!
  +     XalanDOMString  theResult;
   
  -     const unsigned int      bufsize = len + len/m_groupingSize + 1;
  +     format(theValue, theResult);
   
  -     XalanDOMChar* const             buffer = new XalanDOMChar[bufsize];
  +     return theResult;
  +}
   
  -     XalanArrayAutoPtr<XalanDOMChar>         theGuard(buffer);
   
  -     XalanDOMChar*                   p = buffer + bufsize - 1;
   
  -     *p-- = 0;       // null terminate
  +void
  +XalanNumberFormat::format(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult)
  +{
  +     // $$$ ToDo: Fix this!
  +     UnsignedLongToDOMString(theValue, theResult);
  +
  +     applyGrouping(theResult, theResult);
  +}
   
  -     for (unsigned int i = 0, ix = len - 1; i < len; i++, ix--)
  +
  +
  +/*
  + * Convert a string value using the currently active values for grouping size
  + * and separator; returns the converted string
  + */
  +void
  +XalanNumberFormat::applyGrouping(
  +                     const XalanDOMString&   value,
  +                     XalanDOMString&                 result)
  +{
  +     if (m_isGroupingUsed == false ||
  +             m_groupingSize == 0)
  +     {
  +             result = value;
  +     }
  +     else
        {
  -             const XalanDOMChar              c = charAt(value, ix);
  +             const unsigned int len = length(value);
   
  -             if (i && !(i% m_groupingSize))
  +             if (len == 0)
                {
  -                     // Could be a multiple character separator??
  -                     for (int j= m_groupingSeparator.length()-1; j>=0; j--)
  -                             *p-- = charAt(m_groupingSeparator, j);
  +                     result = value;
                }
  +             else
  +             {
  +                     const unsigned int      bufsize = len + 
len/m_groupingSize + 1;
   
  -             *p-- = c;
  -     }
  +                     XalanDOMChar* const             buffer = new 
XalanDOMChar[bufsize];
   
  -     return XalanDOMString(++p);
  -}
  +                     XalanArrayAutoPtr<XalanDOMChar>         
theGuard(buffer);
   
  +                     XalanDOMChar*                   p = buffer + bufsize - 
1;
   
  +                     *p-- = 0;       // null terminate
   
  -XalanDOMString
  -XalanNumberFormat::format(unsigned long      theValue)
  -{
  -     // $$$ ToDo: Fix this!
  -     return UnsignedLongToDOMString(theValue);
  +                     for (unsigned int i = 0, ix = len - 1; i < len; i++, 
ix--)
  +                     {
  +                             const XalanDOMChar              c = 
charAt(value, ix);
  +
  +                             if (i && !(i% m_groupingSize))
  +                             {
  +                                     // Could be a multiple character 
separator??
  +                                     for (int j= 
m_groupingSeparator.length()-1; j>=0; j--)
  +                                             *p-- = 
charAt(m_groupingSeparator, j);
  +                             }
  +
  +                             *p-- = c;
  +                     }
  +
  +                     result = ++p;
  +             }
  +     }
   }
   
   
  
  
  
  1.4       +61 -3     xml-xalan/c/src/PlatformSupport/XalanNumberFormat.hpp
  
  Index: XalanNumberFormat.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/PlatformSupport/XalanNumberFormat.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XalanNumberFormat.hpp     2001/02/08 21:39:09     1.3
  +++ XalanNumberFormat.hpp     2001/06/14 19:04:05     1.4
  @@ -91,6 +91,17 @@
         * Format a number into a string.
         *
         * @param theValue number to format
  +      * @param theResult the string result
  +      */
  +     virtual void
  +     format(
  +                     double                          theValue,
  +                     XalanDOMString&         theResult);
  +
  +     /**
  +      * Format a number into a string.
  +      *
  +      * @param theValue number to format
         * @return string representation of number
         */
        virtual XalanDOMString
  @@ -100,6 +111,17 @@
         * Format a number into a string.
         *
         * @param theValue number to format
  +      * @param theResult the string result
  +      */
  +     virtual void
  +     format(
  +                     int                                     theValue,
  +                     XalanDOMString&         theResult);
  +
  +     /**
  +      * Format a number into a string.
  +      *
  +      * @param theValue number to format
         * @return string representation of number
         */
        virtual XalanDOMString
  @@ -109,6 +131,17 @@
         * Format a number into a string.
         *
         * @param theValue number to format
  +      * @param theResult the string result
  +      */
  +     virtual void
  +     format(
  +                     unsigned int            theValue,
  +                     XalanDOMString&         theResult);
  +
  +     /**
  +      * Format a number into a string.
  +      *
  +      * @param theValue number to format
         * @return string representation of number
         */
        virtual XalanDOMString
  @@ -118,12 +151,34 @@
         * Format a number into a string.
         *
         * @param theValue number to format
  +      * @param theResult the string result
  +      */
  +     virtual void
  +     format(
  +                     long                            theValue,
  +                     XalanDOMString&         theResult);
  +
  +     /**
  +      * Format a number into a string.
  +      *
  +      * @param theValue number to format
         * @return string representation of number
         */
        virtual XalanDOMString
        format(unsigned long    theValue);
   
        /**
  +      * Format a number into a string.
  +      *
  +      * @param theValue number to format
  +      * @param theResult the string result
  +      */
  +     virtual void
  +     format(
  +                     unsigned long           theValue,
  +                     XalanDOMString&         theResult);
  +
  +     /**
         * Whether groupings are used for numbers, for example, "234,678"
         *
         * @return true if grouping used
  @@ -156,11 +211,14 @@
        virtual void
        setGroupingSeparator(const XalanDOMString&      s);
   
  -private:
  +protected:
   
  -     XalanDOMString
  -     applyGrouping(const XalanDOMString&             value);
  +     void
  +     applyGrouping(
  +                     const XalanDOMString&           value,
  +                     XalanDOMString&                         result);
   
  +private:
   
        // Not implemented...
        XalanNumberFormat(const XalanNumberFormat&);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to