ICU-13351 Adding additional CurrencyUnit constructors and stabilizing API constract of MeasureUnit default constructor.
X-SVN-Rev: 40379
This commit is contained in:
parent
57913822e0
commit
d0c762e71c
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include "unicode/currunit.h"
|
#include "unicode/currunit.h"
|
||||||
#include "unicode/ustring.h"
|
#include "unicode/ustring.h"
|
||||||
|
#include "cstring.h"
|
||||||
|
|
||||||
U_NAMESPACE_BEGIN
|
U_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -33,11 +34,30 @@ CurrencyUnit::CurrencyUnit(ConstChar16Ptr _isoCode, UErrorCode& ec) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) :
|
CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) : MeasureUnit(other) {
|
||||||
MeasureUnit(other) {
|
|
||||||
u_strcpy(isoCode, other.isoCode);
|
u_strcpy(isoCode, other.isoCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CurrencyUnit::CurrencyUnit(const MeasureUnit& other, UErrorCode& ec) : MeasureUnit(other) {
|
||||||
|
// Make sure this is a currency.
|
||||||
|
// OK to hard-code the string because we are comparing against another hard-coded string.
|
||||||
|
if (uprv_strcmp("currency", getType()) != 0) {
|
||||||
|
ec = U_ILLEGAL_ARGUMENT_ERROR;
|
||||||
|
isoCode[0] = 0;
|
||||||
|
} else {
|
||||||
|
// Get the ISO Code from the subtype field.
|
||||||
|
u_charsToUChars(getSubtype(), isoCode, 4);
|
||||||
|
isoCode[3] = 0; // make 100% sure it is NUL-terminated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrencyUnit::CurrencyUnit() : MeasureUnit() {
|
||||||
|
u_strcpy(isoCode, u"XXX");
|
||||||
|
char simpleIsoCode[4];
|
||||||
|
u_UCharsToChars(isoCode, simpleIsoCode, 4);
|
||||||
|
initCurrency(simpleIsoCode);
|
||||||
|
}
|
||||||
|
|
||||||
CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) {
|
CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) {
|
||||||
if (this == &other) {
|
if (this == &other) {
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -1079,7 +1079,12 @@ static int32_t binarySearch(
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MeasureUnit::MeasureUnit() {
|
||||||
|
fCurrency[0] = 0;
|
||||||
|
initNoUnit("base");
|
||||||
|
}
|
||||||
|
|
||||||
MeasureUnit::MeasureUnit(const MeasureUnit &other)
|
MeasureUnit::MeasureUnit(const MeasureUnit &other)
|
||||||
: fTypeId(other.fTypeId), fSubTypeId(other.fSubTypeId) {
|
: fTypeId(other.fTypeId), fSubTypeId(other.fSubTypeId) {
|
||||||
uprv_strcpy(fCurrency, other.fCurrency);
|
uprv_strcpy(fCurrency, other.fCurrency);
|
||||||
|
@ -36,6 +36,12 @@ U_NAMESPACE_BEGIN
|
|||||||
*/
|
*/
|
||||||
class U_I18N_API CurrencyUnit: public MeasureUnit {
|
class U_I18N_API CurrencyUnit: public MeasureUnit {
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* Default constructor. Initializes currency code to "XXX" (no currency).
|
||||||
|
* @draft ICU 60
|
||||||
|
*/
|
||||||
|
CurrencyUnit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object with the given ISO currency code.
|
* Construct an object with the given ISO currency code.
|
||||||
* @param isoCode the 3-letter ISO 4217 currency code; must not be
|
* @param isoCode the 3-letter ISO 4217 currency code; must not be
|
||||||
@ -52,6 +58,16 @@ class U_I18N_API CurrencyUnit: public MeasureUnit {
|
|||||||
*/
|
*/
|
||||||
CurrencyUnit(const CurrencyUnit& other);
|
CurrencyUnit(const CurrencyUnit& other);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy constructor from MeasureUnit. This constructor allows you to
|
||||||
|
* restore a CurrencyUnit that was sliced to MeasureUnit.
|
||||||
|
*
|
||||||
|
* @param measureUnit The MeasureUnit to copy from.
|
||||||
|
* @param ec Set to a failing value if the MeasureUnit is not a currency.
|
||||||
|
* @draft ICU 60
|
||||||
|
*/
|
||||||
|
CurrencyUnit(const MeasureUnit& measureUnit, UErrorCode &ec);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assignment operator
|
* Assignment operator
|
||||||
* @stable ICU 3.0
|
* @stable ICU 3.0
|
||||||
|
@ -40,11 +40,10 @@ class U_I18N_API MeasureUnit: public UObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
|
* Populates the instance with the base dimensionless unit.
|
||||||
* @stable ICU 3.0
|
* @stable ICU 3.0
|
||||||
*/
|
*/
|
||||||
MeasureUnit() : fTypeId(0), fSubTypeId(0) {
|
MeasureUnit();
|
||||||
fCurrency[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor.
|
* Copy constructor.
|
||||||
|
Loading…
Reference in New Issue
Block a user