dbertoni 00/05/08 10:17:06
Added: c/src/PlatformSupport XalanDecimalFormat.cpp
XalanDecimalFormat.hpp
XalanDecimalFormatSymbols.cpp
XalanDecimalFormatSymbols.hpp XalanNumberFormat.cpp
XalanNumberFormat.hpp
Log:
Prepended Xalan to classes with the same names as those in the ICU. These
are replacements for DecimalFormat.*, DecimalFormatSymbols.*, and NumberFormat.*
Revision Changes Path
1.1 xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.cpp
Index: XalanDecimalFormat.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include "XalanDecimalFormat.hpp"
#include "DOMStringHelper.hpp"
const XalanDOMString XalanDecimalFormat::s_defaultPatternString;
XalanDecimalFormat::XalanDecimalFormat(
const XalanDOMString&
thePatternString,
const XalanDecimalFormatSymbols& theSymbols) :
XalanNumberFormat(),
m_patternString(length(thePatternString) == 0 ? s_defaultPatternString
: thePatternString),
m_decimalFormatSymbols(theSymbols)
{
}
XalanDecimalFormat::~XalanDecimalFormat()
{
}
XalanDOMString
XalanDecimalFormat::format(double theValue)
{
// $$$ ToDo: Fix this!!!
return XalanNumberFormat::format(theValue);
}
XalanDOMString
XalanDecimalFormat::format(int theValue)
{
// $$$ ToDo: Fix this!!!
return XalanNumberFormat::format(theValue);
}
XalanDOMString
XalanDecimalFormat::format(unsigned int theValue)
{
// $$$ ToDo: Fix this!!!
return XalanNumberFormat::format(theValue);
}
XalanDOMString
XalanDecimalFormat::format(long theValue)
{
// $$$ ToDo: Fix this!!!
return XalanNumberFormat::format(theValue);
}
XalanDOMString
XalanDecimalFormat::format(unsigned long theValue)
{
// $$$ ToDo: Fix this!!!
return XalanNumberFormat::format(theValue);
}
void
XalanDecimalFormat::applyPattern(const XalanDOMString& thePattern)
{
// $$$ ToDo: Fix this!!!
}
void
XalanDecimalFormat::applyLocalizedPattern(const XalanDOMString&
thePattern)
{
// $$$ ToDo: Fix this!!!
}
XalanDOMString
XalanDecimalFormat::getNormalizedPattern(const XalanDOMString&
thePattern)
{
// A pattern may not have an explicit specification for
// negative numbers. If there is no pattern separator,
// and therefore no explicit specification for negative
// numbers, then assume that the pattern for negative
// numbers is the same as that for positive numbers.
const XalanDOMChar thePatternSeparatorChar =
m_decimalFormatSymbols.getPatternSeparator();
// Is the a separator?
const unsigned int theSeparatorIndex =
indexOf(thePattern, thePatternSeparatorChar);
if (theSeparatorIndex < length(thePattern))
{
// There is, so the pattern is already normalized.
return thePattern;
}
else
{
// There isn't, so
XalanDOMString theNewPattern(thePattern);
theNewPattern += thePatternSeparatorChar;
theNewPattern += m_decimalFormatSymbols.getMinusSign();
theNewPattern += thePattern;
return theNewPattern;
}
}
1.1 xml-xalan/c/src/PlatformSupport/XalanDecimalFormat.hpp
Index: XalanDecimalFormat.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#if !defined(XALANDECIMALFORMAT_HEADER_GUARD_1357924680)
#define XALANDECIMALFORMAT_HEADER_GUARD_1357924680
// Base include file. Must be first.
#include <PlatformSupport/PlatformSupportDefinitions.hpp>
#include <XalanDOM/XalanDOMString.hpp>
// Base class header file.
#include <PlatformSupport/XalanDecimalFormatSymbols.hpp>
#include <PlatformSupport/XalanNumberFormat.hpp>
class XALAN_PLATFORMSUPPORT_EXPORT XalanDecimalFormat : public
XalanNumberFormat
{
public:
/**
* Constructor
*
* @param thePatternString string defining how output should be
formatted
* @param theSymbols class defining the symbols used for output,
for
* example, symbol for currency
*/
explicit
XalanDecimalFormat(
const XalanDOMString&
thePatternString = XalanDOMString(),
const XalanDecimalFormatSymbols& theSymbols =
XalanDecimalFormatSymbols());
virtual
~XalanDecimalFormat();
// From NumberFormat...
virtual XalanDOMString
format(double theValue);
virtual XalanDOMString
format(int theValue);
virtual XalanDOMString
format(unsigned int theValue);
virtual XalanDOMString
format(long theValue);
virtual XalanDOMString
format(unsigned long theValue);
// New for XalanDecimalFormat...
/**
* Retrieve class defining symbols used for output
*
* @return class defining the symbols used for output, for example,
symbol
* for currency
*/
const XalanDecimalFormatSymbols&
getDecimalFormatSymbols() const
{
return m_decimalFormatSymbols;
}
/**
* Set class defining symbols used for output
*
* @param class defining the symbols used for output, for example,
symbol
* for currency
*/
void
setDecimalFormatSymbols(const XalanDecimalFormatSymbols&
theDecimalFormatSymbols)
{
m_decimalFormatSymbols = theDecimalFormatSymbols;
}
void
applyPattern(const XalanDOMString& thePattern);
void
applyLocalizedPattern(const XalanDOMString& thePattern);
protected:
XalanDOMString
getNormalizedPattern(const XalanDOMString& thePattern);
private:
// Not implemented
XalanDecimalFormat(const XalanDecimalFormat&);
XalanDecimalFormat&
operator=(const XalanDecimalFormat&);
bool
operator==(const XalanDecimalFormat&);
// Data members...
XalanDOMString m_patternString;
XalanDecimalFormatSymbols m_decimalFormatSymbols;
static const XalanDOMString s_defaultPatternString;
};
#endif // XALANDECIMALFORMAT_HEADER_GUARD_1357924680
1.1
xml-xalan/c/src/PlatformSupport/XalanDecimalFormatSymbols.cpp
Index: XalanDecimalFormatSymbols.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include "XalanDecimalFormatSymbols.hpp"
#include "DOMStringHelper.hpp"
static XalanDOMChar theNaNDefault[] = { 0xFFFD, 0 };
static XalanDOMChar theInfinityDefault[] = { 0x221E, 0 };
XalanDecimalFormatSymbols::XalanDecimalFormatSymbols() :
m_currencySymbol(XALAN_STATIC_UCODE_STRING("$")),
m_decimalSeparator('.'),
m_digit(0),
m_groupingSeparator(','),
m_infinity(theInfinityDefault),
m_internationalCurrencySymbol(),
m_minusSign('-'),
m_monetaryDecimalSeparator('.'),
m_NaN(theNaNDefault),
m_patternSeparator(';'),
m_percent('%'),
m_perMill(0),
m_zeroDigit('0')
{
}
XalanDecimalFormatSymbols::XalanDecimalFormatSymbols(const
XalanDecimalFormatSymbols& theSource) :
m_currencySymbol(theSource.m_currencySymbol),
m_decimalSeparator(theSource.m_decimalSeparator),
m_digit(theSource.m_digit),
m_groupingSeparator(theSource.m_groupingSeparator),
m_infinity(theSource.m_infinity),
m_internationalCurrencySymbol(theSource.m_internationalCurrencySymbol),
m_minusSign(theSource.m_minusSign),
m_monetaryDecimalSeparator(theSource.m_monetaryDecimalSeparator),
m_NaN(theSource.m_NaN),
m_patternSeparator(theSource.m_patternSeparator),
m_percent(theSource.m_percent),
m_perMill(theSource.m_perMill),
m_zeroDigit(theSource.m_zeroDigit)
{
}
XalanDecimalFormatSymbols::~XalanDecimalFormatSymbols()
{
}
XalanDecimalFormatSymbols&
XalanDecimalFormatSymbols::operator=(const XalanDecimalFormatSymbols&
theRHS)
{
if (&theRHS != this)
{
m_currencySymbol = theRHS.m_currencySymbol;
m_decimalSeparator = theRHS.m_decimalSeparator;
m_digit = theRHS.m_digit;
m_groupingSeparator = theRHS.m_groupingSeparator;
m_infinity = theRHS.m_infinity;
m_internationalCurrencySymbol =
theRHS.m_internationalCurrencySymbol;
m_minusSign = theRHS.m_minusSign;
m_monetaryDecimalSeparator = theRHS.m_monetaryDecimalSeparator;
m_NaN = theRHS.m_NaN;
m_patternSeparator = theRHS.m_patternSeparator;
m_percent = theRHS.m_percent;
m_perMill = theRHS.m_perMill;
m_zeroDigit = theRHS.m_zeroDigit;
}
return *this;
}
1.1
xml-xalan/c/src/PlatformSupport/XalanDecimalFormatSymbols.hpp
Index: XalanDecimalFormatSymbols.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#if !defined(XALANDECIMALFORMATSYMBOLS_HEADER_GUARD_1357924680)
#define XALANDECIMALFORMATSYMBOLS_HEADER_GUARD_1357924680
// Base include file. Must be first.
#include <PlatformSupport/PlatformSupportDefinitions.hpp>
#include <XalanDOM/XalanDOMString.hpp>
class XALAN_PLATFORMSUPPORT_EXPORT XalanDecimalFormatSymbols
{
public:
// Eventually, this constructor should take a locale to determine
// all of the stuff it needs to know. But locales are implemented
// on all of our platforms yet.
explicit
XalanDecimalFormatSymbols();
XalanDecimalFormatSymbols(const XalanDecimalFormatSymbols&
theSource);
~XalanDecimalFormatSymbols();
XalanDecimalFormatSymbols&
operator=(const XalanDecimalFormatSymbols& theRHS);
/**
* Retrieve the string denoting the local currency, "$", for example
*
* @return string used for local currency
*/
const XalanDOMString&
getCurrencySymbol() const
{
return m_currencySymbol;
}
/**
* Retrieve the character used for decimal sign, '.' for example
*
* @return character used for decimal sign
*/
XalanDOMChar
getDecimalSeparator() const
{
return m_decimalSeparator;
}
/**
* Retrieve character used for a digit in a pattern
*
* @return character used for a digit in a pattern
*/
XalanDOMChar
getDigit() const
{
return m_digit;
}
/**
* Retrieve the character used for thousands separator, "," for example
*
* @return character used for thousands separator
*/
XalanDOMChar
getGroupingSeparator() const
{
return m_groupingSeparator;
}
/**
* Retrieve the string used to represent infinity
*
* @return string used to represent infinity
*/
const XalanDOMString&
getInfinity() const
{
return m_infinity;
}
/**
* Retrieve the international string denoting the local currency
*
* @return international string denoting the local currency
*/
const XalanDOMString&
getInternationalCurrencySymbol() const
{
return m_internationalCurrencySymbol;
}
/**
* Retrieve the character used to represent minus sign
*
* @return character used to represent minus sign
*/
XalanDOMChar
getMinusSign() const
{
return m_minusSign;
}
/**
* Retrieve the monetary decimal separator
*
* @return character used to separate decimal portion of currency
*/
XalanDOMChar
getMonetaryDecimalSeparator() const
{
return m_monetaryDecimalSeparator;
}
/**
* Retrieve the string used for a numeric value that cannot be
represented
* as a number
*
* @return string representing "not a number" value
*/
const XalanDOMString&
getNaN() const
{
return m_NaN;
}
/**
* Retrieve the character used to separate positive and negative
* subpatterns in a pattern
*
* @return character used to separate positive and negative subpatterns
*/
XalanDOMChar
getPatternSeparator() const
{
return m_patternSeparator;
}
/**
* Retrieve the character used for percent sign, "%," for example
*
* @return character used for percent sign
*/
XalanDOMChar
getPercent() const
{
return m_percent;
}
/**
* Retrieve the character used for per thousand sign
*
* @return character used for per thousand sign
*/
XalanDOMChar
getPerMill() const
{
return m_perMill;
}
/**
* Retrieve the character used for zero
*
* @return character used for zero
*/
XalanDOMChar
getZeroDigit() const
{
return m_zeroDigit;
}
/**
* Sets the string denoting the local currency, "$", for example
*
* @param theCurrencySymbol symbol used for local currency
*/
void
setCurrencySymbol(const XalanDOMString& theCurrencySymbol)
{
m_currencySymbol = theCurrencySymbol;
}
/**
* Sets the character used for decimal sign, '.' for example
*
* @param theDecimalSeparator character used for decimal sign
*/
void
setDecimalSeparator(XalanDOMChar theDecimalSeparator)
{
m_decimalSeparator = theDecimalSeparator;
}
/**
* Sets the character used for a digit in a pattern
*
* @param theDigit character used for a digit in a pattern
*/
void
setDigit(XalanDOMChar theDigit)
{
m_digit = theDigit;
}
/**
* Sets the character used for thousands separator, "," for example
*
* @param theGroupingSeparator character used for thousands separator
*/
void
setGroupingSeparator(XalanDOMChar theGroupingSeparator)
{
m_groupingSeparator = theGroupingSeparator;
}
/**
* Sets the string used to represent infinity
*
* @param theInfinity string used to represent infinity
*/
void
setInfinity(const XalanDOMString& theInfinity)
{
m_infinity = theInfinity;
}
/**
* Sets the international string denoting the local currency
*
* @param theInternationalCurrencySymbol international string denoting
the
* local currency
*/
void
setInternationalCurrencySymbol(const XalanDOMString&
theInternationalCurrencySymbol)
{
m_internationalCurrencySymbol = theInternationalCurrencySymbol;
}
/**
* Sets the character used to represent minus sign
*
* @param theMinusSign character used to represent minus sign
*/
void
setMinusSign(XalanDOMChar theMinusSign)
{
m_minusSign = theMinusSign;
}
/**
* Sets the monetary decimal separator
*
* @param theMonetaryDecimalSeparator character used to separate decimal
* portion of currency
*/
void
setMonetaryDecimalSeparator(XalanDOMChar
theMonetaryDecimalSeparator)
{
m_monetaryDecimalSeparator = theMonetaryDecimalSeparator;
}
/**
* Sets the string used for a numeric value that cannot be represented
* as a number
*
* @param theNaN string representing "not a number" value
*/
void
setNaN(const XalanDOMString& theNaN)
{
m_NaN = theNaN;
}
/**
* Sets the character used to separate positive and negative
subpatterns in
* a pattern
*
* @param thePatternSeparator character used to separate positive and
* negative subpatterns
*/
void
setPatternSeparator(XalanDOMChar thePatternSeparator)
{
m_patternSeparator = thePatternSeparator;
}
/**
* Sets the character used for percent sign, "%," for example
*
* @param thePercent character used for percent sign
*/
void
setPercent(XalanDOMChar thePercent)
{
m_percent = thePercent;
}
/**
* Sets the character used for per thousand sign
*
* @param thePerMill character used for per thousand sign
*/
void
setPerMill(XalanDOMChar thePerMill)
{
m_perMill = thePerMill;
}
/**
* Sets the character used for zero
*
* @param theZeroDigit character used for zero
*/
void
setZeroDigit(XalanDOMChar theZeroDigit)
{
m_zeroDigit = theZeroDigit;
}
private:
XalanDOMString m_currencySymbol;
XalanDOMChar m_decimalSeparator;
XalanDOMChar m_digit;
XalanDOMChar m_groupingSeparator;
XalanDOMString m_infinity;
XalanDOMString m_internationalCurrencySymbol;
XalanDOMChar m_minusSign;
XalanDOMChar m_monetaryDecimalSeparator;
XalanDOMString m_NaN;
XalanDOMChar m_patternSeparator;
XalanDOMChar m_percent;
XalanDOMChar m_perMill;
XalanDOMChar m_zeroDigit;
};
#endif // XALANDECIMALFORMATSYMBOLS_HEADER_GUARD_1357924680
1.1 xml-xalan/c/src/PlatformSupport/XalanNumberFormat.cpp
Index: XalanNumberFormat.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include "XalanNumberFormat.hpp"
#include "DOMStringHelper.hpp"
XalanNumberFormat::XalanNumberFormat() :
m_isGroupingUsed(false),
m_groupingSeparator(XALAN_STATIC_UCODE_STRING(",")),
m_groupingSize(3) // Default to US values
{
}
XalanNumberFormat::~XalanNumberFormat()
{
}
XalanDOMString
XalanNumberFormat::format(double theValue)
{
// $$$ ToDo: Fix this!
return applyGrouping(DoubleToDOMString(theValue));
}
XalanDOMString
XalanNumberFormat::format(int theValue)
{
// $$$ ToDo: Fix this!
return applyGrouping(LongToDOMString(theValue));
}
XalanDOMString
XalanNumberFormat::format(unsigned int theValue)
{
// $$$ ToDo: Fix this!
return applyGrouping(UnsignedLongToDOMString(theValue));
}
XalanDOMString
XalanNumberFormat::format(long theValue)
{
// $$$ ToDo: Fix this!
return applyGrouping(LongToDOMString(theValue));
}
XalanDOMString
XalanNumberFormat::applyGrouping(const XalanDOMString& value)
/*
* Convert a string value using the currently active values for grouping size
* and separator; returns the converted string
*/
{
if (!m_isGroupingUsed) return value;
if (m_groupingSize == 0) return value;
int len = value.length();
if (len == 0) return value;
const unsigned int bufsize = len + len/m_groupingSize + 1;
XalanDOMChar* const buffer = new XalanDOMChar[bufsize];
XalanDOMChar* p = buffer + bufsize - 1;
*p-- = 0; // null terminate
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;
}
XalanDOMString s(++p);
delete [] buffer;
return s;
}
XalanDOMString
XalanNumberFormat::format(unsigned long theValue)
{
// $$$ ToDo: Fix this!
return UnsignedLongToDOMString(theValue);
}
bool
XalanNumberFormat::isGroupingUsed() const
{
return m_isGroupingUsed;
}
void
XalanNumberFormat::setGroupingUsed(bool bUsed)
{
m_isGroupingUsed = bUsed;
}
void
XalanNumberFormat::setGroupingSize(unsigned long size)
{
assert(size > 0);
m_groupingSize = size;
}
void
XalanNumberFormat::setGroupingSeparator(const XalanDOMString& s)
{
m_groupingSeparator = s;
}
1.1 xml-xalan/c/src/PlatformSupport/XalanNumberFormat.hpp
Index: XalanNumberFormat.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.ibm.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#if !defined(XALANNUMBERFORMAT_HEADER_GUARD_1357924680)
#define XALANNUMBERFORMAT_HEADER_GUARD_1357924680
// Base include file. Must be first.
#include <PlatformSupport/PlatformSupportDefinitions.hpp>
#include <XalanDOM/XalanDOMString.hpp>
class XALAN_PLATFORMSUPPORT_EXPORT XalanNumberFormat
{
public:
explicit
XalanNumberFormat();
virtual
~XalanNumberFormat();
/**
* Format a number into a string.
*
* @param theValue number to format
* @return string representation of number
*/
virtual XalanDOMString
format(double theValue);
/**
* Format a number into a string.
*
* @param theValue number to format
* @return string representation of number
*/
virtual XalanDOMString
format(int theValue);
/**
* Format a number into a string.
*
* @param theValue number to format
* @return string representation of number
*/
virtual XalanDOMString
format(unsigned int theValue);
/**
* Format a number into a string.
*
* @param theValue number to format
* @return string representation of number
*/
virtual XalanDOMString
format(long theValue);
/**
* Format a number into a string.
*
* @param theValue number to format
* @return string representation of number
*/
virtual XalanDOMString
format(unsigned long theValue);
/**
* Whether groupings are used for numbers, for example, "234,678"
*
* @return true if grouping used
*/
virtual bool
isGroupingUsed() const;
/**
* Change whether groupings are used for numbers, for example, "234,678"
*
* @param bUsed true to use grouping
*/
virtual void
setGroupingUsed(bool bUsed);
/**
* Change the size of groupings, for example, "234,678" uses a size of
"3"
*
* @param size the grouping size
*/
virtual void
setGroupingSize(unsigned long size);
/**
* Change the separator string used for groupings, for example,
"234,678"
* uses the separator ","
*
* @param s grouping separator string
*/
virtual void
setGroupingSeparator(const XalanDOMString& s);
private:
XalanDOMString
applyGrouping(const XalanDOMString& value);
// Not implemented...
XalanNumberFormat(const XalanNumberFormat&);
XalanNumberFormat&
operator=(const XalanNumberFormat&);
bool
operator==(const XalanNumberFormat&);
// Data members...
bool m_isGroupingUsed;
XalanDOMString m_groupingSeparator;
int m_groupingSize;
};
#endif // XALANNUMBERFORMAT_HEADER_GUARD_1357924680