aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/icu/i18n/currunit.cpp
diff options
context:
space:
mode:
authormcheshkov <mcheshkov@yandex-team.ru>2022-02-10 16:46:16 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:16 +0300
commit1312621288956f199a5bd5342b0133d4395fa725 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/libs/icu/i18n/currunit.cpp
parente9d19cec64684c9c1e6b0c98297e5b895cf904fe (diff)
downloadydb-1312621288956f199a5bd5342b0133d4395fa725.tar.gz
Restoring authorship annotation for <mcheshkov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/icu/i18n/currunit.cpp')
-rw-r--r--contrib/libs/icu/i18n/currunit.cpp158
1 files changed, 79 insertions, 79 deletions
diff --git a/contrib/libs/icu/i18n/currunit.cpp b/contrib/libs/icu/i18n/currunit.cpp
index 041653972e..92bcf1268a 100644
--- a/contrib/libs/icu/i18n/currunit.cpp
+++ b/contrib/libs/icu/i18n/currunit.cpp
@@ -1,4 +1,4 @@
-// © 2016 and later: Unicode, Inc. and others.
+// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
@@ -16,93 +16,93 @@
#include "unicode/currunit.h"
#include "unicode/ustring.h"
-#include "unicode/uchar.h"
-#include "cstring.h"
-#include "uinvchar.h"
-#include "charstr.h"
-#include "ustr_imp.h"
-#include "measunit_impl.h"
+#include "unicode/uchar.h"
+#include "cstring.h"
+#include "uinvchar.h"
+#include "charstr.h"
+#include "ustr_imp.h"
+#include "measunit_impl.h"
U_NAMESPACE_BEGIN
-CurrencyUnit::CurrencyUnit(ConstChar16Ptr _isoCode, UErrorCode& ec) {
- // The constructor always leaves the CurrencyUnit in a valid state (with a 3-character currency code).
- // Note: in ICU4J Currency.getInstance(), we check string length for 3, but in ICU4C we allow a
- // non-NUL-terminated string to be passed as an argument, so it is not possible to check length.
- // However, we allow a NUL-terminated empty string, which should have the same behavior as nullptr.
- // Consider NUL-terminated strings of length 1 or 2 as invalid.
- bool useDefault = false;
- if (U_FAILURE(ec) || _isoCode == nullptr || _isoCode[0] == 0) {
- useDefault = true;
- } else if (_isoCode[1] == 0 || _isoCode[2] == 0) {
- useDefault = true;
- ec = U_ILLEGAL_ARGUMENT_ERROR;
- } else if (!uprv_isInvariantUString(_isoCode, 3)) {
- // TODO: Perform a more strict ASCII check like in ICU4J isAlpha3Code?
- useDefault = true;
- ec = U_INVARIANT_CONVERSION_ERROR;
- } else {
- for (int32_t i=0; i<3; i++) {
- isoCode[i] = u_asciiToUpper(_isoCode[i]);
+CurrencyUnit::CurrencyUnit(ConstChar16Ptr _isoCode, UErrorCode& ec) {
+ // The constructor always leaves the CurrencyUnit in a valid state (with a 3-character currency code).
+ // Note: in ICU4J Currency.getInstance(), we check string length for 3, but in ICU4C we allow a
+ // non-NUL-terminated string to be passed as an argument, so it is not possible to check length.
+ // However, we allow a NUL-terminated empty string, which should have the same behavior as nullptr.
+ // Consider NUL-terminated strings of length 1 or 2 as invalid.
+ bool useDefault = false;
+ if (U_FAILURE(ec) || _isoCode == nullptr || _isoCode[0] == 0) {
+ useDefault = true;
+ } else if (_isoCode[1] == 0 || _isoCode[2] == 0) {
+ useDefault = true;
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ } else if (!uprv_isInvariantUString(_isoCode, 3)) {
+ // TODO: Perform a more strict ASCII check like in ICU4J isAlpha3Code?
+ useDefault = true;
+ ec = U_INVARIANT_CONVERSION_ERROR;
+ } else {
+ for (int32_t i=0; i<3; i++) {
+ isoCode[i] = u_asciiToUpper(_isoCode[i]);
}
- isoCode[3] = 0;
+ isoCode[3] = 0;
}
- if (useDefault) {
- uprv_memcpy(isoCode, kDefaultCurrency, sizeof(UChar) * 4);
- }
- char simpleIsoCode[4];
- u_UCharsToChars(isoCode, simpleIsoCode, 4);
- initCurrency(simpleIsoCode);
+ if (useDefault) {
+ uprv_memcpy(isoCode, kDefaultCurrency, sizeof(UChar) * 4);
+ }
+ char simpleIsoCode[4];
+ u_UCharsToChars(isoCode, simpleIsoCode, 4);
+ initCurrency(simpleIsoCode);
+}
+
+CurrencyUnit::CurrencyUnit(StringPiece _isoCode, UErrorCode& ec) {
+ // Note: unlike the old constructor, reject empty arguments with an error.
+ char isoCodeBuffer[4];
+ const char* isoCodeToUse;
+ // uprv_memchr checks that the string contains no internal NULs
+ if (_isoCode.length() != 3 || uprv_memchr(_isoCode.data(), 0, 3) != nullptr) {
+ isoCodeToUse = kDefaultCurrency8;
+ ec = U_ILLEGAL_ARGUMENT_ERROR;
+ } else if (!uprv_isInvariantString(_isoCode.data(), 3)) {
+ // TODO: Perform a more strict ASCII check like in ICU4J isAlpha3Code?
+ isoCodeToUse = kDefaultCurrency8;
+ ec = U_INVARIANT_CONVERSION_ERROR;
+ } else {
+ // Have to use isoCodeBuffer to ensure the string is NUL-terminated
+ for (int32_t i=0; i<3; i++) {
+ isoCodeBuffer[i] = uprv_toupper(_isoCode.data()[i]);
+ }
+ isoCodeBuffer[3] = 0;
+ isoCodeToUse = isoCodeBuffer;
+ }
+ u_charsToUChars(isoCodeToUse, isoCode, 4);
+ initCurrency(isoCodeToUse);
}
-CurrencyUnit::CurrencyUnit(StringPiece _isoCode, UErrorCode& ec) {
- // Note: unlike the old constructor, reject empty arguments with an error.
- char isoCodeBuffer[4];
- const char* isoCodeToUse;
- // uprv_memchr checks that the string contains no internal NULs
- if (_isoCode.length() != 3 || uprv_memchr(_isoCode.data(), 0, 3) != nullptr) {
- isoCodeToUse = kDefaultCurrency8;
- ec = U_ILLEGAL_ARGUMENT_ERROR;
- } else if (!uprv_isInvariantString(_isoCode.data(), 3)) {
- // TODO: Perform a more strict ASCII check like in ICU4J isAlpha3Code?
- isoCodeToUse = kDefaultCurrency8;
- ec = U_INVARIANT_CONVERSION_ERROR;
- } else {
- // Have to use isoCodeBuffer to ensure the string is NUL-terminated
- for (int32_t i=0; i<3; i++) {
- isoCodeBuffer[i] = uprv_toupper(_isoCode.data()[i]);
- }
- isoCodeBuffer[3] = 0;
- isoCodeToUse = isoCodeBuffer;
- }
- u_charsToUChars(isoCodeToUse, isoCode, 4);
- initCurrency(isoCodeToUse);
-}
-
-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, kDefaultCurrency);
- char simpleIsoCode[4];
- u_UCharsToChars(isoCode, simpleIsoCode, 4);
- initCurrency(simpleIsoCode);
-}
-
+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, kDefaultCurrency);
+ char simpleIsoCode[4];
+ u_UCharsToChars(isoCode, simpleIsoCode, 4);
+ initCurrency(simpleIsoCode);
+}
+
CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) {
if (this == &other) {
return *this;
@@ -112,7 +112,7 @@ CurrencyUnit& CurrencyUnit::operator=(const CurrencyUnit& other) {
return *this;
}
-CurrencyUnit* CurrencyUnit::clone() const {
+CurrencyUnit* CurrencyUnit::clone() const {
return new CurrencyUnit(*this);
}