#include "unicode/currunit.h"
#include "unicode/ustring.h"
+#include "cstring.h"
U_NAMESPACE_BEGIN
}
}
-CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) :
- MeasureUnit(other) {
+CurrencyUnit::CurrencyUnit(const CurrencyUnit& other) : MeasureUnit(other) {
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) {
if (this == &other) {
return *this;
}
return -1;
}
-
+
+MeasureUnit::MeasureUnit() {
+ fCurrency[0] = 0;
+ initNoUnit("base");
+}
+
MeasureUnit::MeasureUnit(const MeasureUnit &other)
: fTypeId(other.fTypeId), fSubTypeId(other.fSubTypeId) {
uprv_strcpy(fCurrency, other.fCurrency);
*/
class U_I18N_API CurrencyUnit: public MeasureUnit {
public:
+ /**
+ * Default constructor. Initializes currency code to "XXX" (no currency).
+ * @draft ICU 60
+ */
+ CurrencyUnit();
+
/**
* Construct an object with the given ISO currency code.
* @param isoCode the 3-letter ISO 4217 currency code; must not be
*/
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
* @stable ICU 3.0