Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: source/i18n/digitaffixesandpadding.h

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/i18n/digitaffix.cpp ('k') | source/i18n/digitaffixesandpadding.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/i18n/digitaffixesandpadding.h
diff --git a/source/i18n/digitaffixesandpadding.h b/source/i18n/digitaffixesandpadding.h
new file mode 100644
index 0000000000000000000000000000000000000000..6b2a5ed05686674a1d5d8f0f1e9a05fa9753ff5b
--- /dev/null
+++ b/source/i18n/digitaffixesandpadding.h
@@ -0,0 +1,177 @@
+/*
+*******************************************************************************
+* Copyright (C) 2015, International Business Machines
+* Corporation and others. All Rights Reserved.
+*******************************************************************************
+* digitaffixesandpadding.h
+*
+* created on: 2015jan06
+* created by: Travis Keep
+*/
+
+#ifndef __DIGITAFFIXESANDPADDING_H__
+#define __DIGITAFFIXESANDPADDING_H__
+
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
+#include "unicode/uobject.h"
+#include "pluralaffix.h"
+
+U_NAMESPACE_BEGIN
+
+class DigitList;
+class ValueFormatter;
+class UnicodeString;
+class FieldPositionHandler;
+class PluralRules;
+class VisibleDigitsWithExponent;
+
+/**
+ * A formatter of numbers. This class can format any numerical value
+ * except for not a number (NaN), positive infinity, and negative infinity.
+ * This class manages prefixes, suffixes, and padding but delegates the
+ * formatting of actual positive values to a ValueFormatter.
+ */
+class U_I18N_API DigitAffixesAndPadding : public UMemory {
+public:
+
+/**
+ * Equivalent to DecimalFormat EPadPosition, but redeclared here to prevent
+ * depending on DecimalFormat which would cause a circular dependency.
+ */
+enum EPadPosition {
+ kPadBeforePrefix,
+ kPadAfterPrefix,
+ kPadBeforeSuffix,
+ kPadAfterSuffix
+};
+
+/**
+ * The positive prefix
+ */
+PluralAffix fPositivePrefix;
+
+/**
+ * The positive suffix
+ */
+PluralAffix fPositiveSuffix;
+
+/**
+ * The negative suffix
+ */
+PluralAffix fNegativePrefix;
+
+/**
+ * The negative suffix
+ */
+PluralAffix fNegativeSuffix;
+
+/**
+ * The padding position
+ */
+EPadPosition fPadPosition;
+
+/**
+ * The padding character.
+ */
+UChar32 fPadChar;
+
+/**
+ * The field width in code points. The format method inserts instances of
+ * the padding character as needed in the desired padding position so that
+ * the entire formatted string contains this many code points. If the
+ * formatted string already exceeds this many code points, the format method
+ * inserts no padding.
+ */
+int32_t fWidth;
+
+/**
+ * Pad position is before prefix; padding character is '*' field width is 0.
+ * The affixes are all the empty string with no annotated fields with just
+ * the 'other' plural variation.
+ */
+DigitAffixesAndPadding()
+ : fPadPosition(kPadBeforePrefix), fPadChar(0x2a), fWidth(0) { }
+
+/**
+ * Returns TRUE if this object is equal to rhs.
+ */
+UBool equals(const DigitAffixesAndPadding &rhs) const {
+ return (fPositivePrefix.equals(rhs.fPositivePrefix) &&
+ fPositiveSuffix.equals(rhs.fPositiveSuffix) &&
+ fNegativePrefix.equals(rhs.fNegativePrefix) &&
+ fNegativeSuffix.equals(rhs.fNegativeSuffix) &&
+ fPadPosition == rhs.fPadPosition &&
+ fWidth == rhs.fWidth &&
+ fPadChar == rhs.fPadChar);
+}
+
+/**
+ * Returns TRUE if a plural rules instance is needed to complete the
+ * formatting by detecting if any of the affixes have multiple plural
+ * variations.
+ */
+UBool needsPluralRules() const;
+
+/**
+ * Formats value and appends to appendTo.
+ *
+ * @param value the value to format. May be NaN or ininite.
+ * @param formatter handles the details of formatting the actual value.
+ * @param handler records field positions
+ * @param optPluralRules the plural rules, but may be NULL if
+ * needsPluralRules returns FALSE.
+ * @appendTo formatted string appended here.
+ * @status any error returned here.
+ */
+UnicodeString &format(
+ const VisibleDigitsWithExponent &value,
+ const ValueFormatter &formatter,
+ FieldPositionHandler &handler,
+ const PluralRules *optPluralRules,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
+/**
+ * For testing only.
+ */
+UnicodeString &format(
+ DigitList &value,
+ const ValueFormatter &formatter,
+ FieldPositionHandler &handler,
+ const PluralRules *optPluralRules,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
+/**
+ * Formats a 32-bit integer and appends to appendTo. When formatting an
+ * integer, this method is preferred to plain format as it can run
+ * several times faster under certain conditions.
+ *
+ * @param value the value to format.
+ * @param formatter handles the details of formatting the actual value.
+ * @param handler records field positions
+ * @param optPluralRules the plural rules, but may be NULL if
+ * needsPluralRules returns FALSE.
+ * @appendTo formatted string appended here.
+ * @status any error returned here.
+ */
+UnicodeString &formatInt32(
+ int32_t value,
+ const ValueFormatter &formatter,
+ FieldPositionHandler &handler,
+ const PluralRules *optPluralRules,
+ UnicodeString &appendTo,
+ UErrorCode &status) const;
+
+private:
+UnicodeString &appendPadding(int32_t paddingCount, UnicodeString &appendTo) const;
+
+};
+
+
+U_NAMESPACE_END
+#endif /* #if !UCONFIG_NO_FORMATTING */
+#endif // __DIGITAFFIXANDPADDING_H__
« no previous file with comments | « source/i18n/digitaffix.cpp ('k') | source/i18n/digitaffixesandpadding.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698