]> granicus.if.org Git - icu/commitdiff
ICU-21334 Promote ICU4C ListFormatter openForType to stable.
authorShane F. Carr <shane@unicode.org>
Wed, 21 Oct 2020 23:24:30 +0000 (18:24 -0500)
committerShane F. Carr <shane@unicode.org>
Thu, 22 Oct 2020 06:48:50 +0000 (01:48 -0500)
Also fixes ICU-20957 and ICU-21286.

icu4c/source/common/unicode/docmain.h
icu4c/source/i18n/listformatter.cpp
icu4c/source/i18n/unicode/listformatter.h
icu4c/source/i18n/unicode/ulistformatter.h

index b7984ada03287ff20f68dda054ac26356bdf1e04..edcb5d4e835f654f260acb4c17aaded3b267b813 100644 (file)
  *     <td>icu::MessageFormat</td>
  *   </tr>
  *   <tr>
+ *     <td>List Formatting</td>
+ *     <td>ulistformatter.h</td>
+ *     <td>icu::ListFormatter</td>
+ *   </tr>
+ *   <tr>
  *     <td>Number Formatting<br/>(includes currency and unit formatting)</td>
  *     <td>unumberformatter.h, unum.h</td>
  *     <td>icu::number::NumberFormatter (ICU 60+) or icu::NumberFormat (older versions)</td>
index ab04ac9080a5aba69bc850a5e794184d0b953d48..66d76b571536f7d6bf903bab306d24bd9925267e 100644 (file)
 *   created by: Umesh P. Nair
 */
 
+#include "unicode/utypes.h"
+
+#if !UCONFIG_NO_FORMATTING
+
 #include "cmemory.h"
 #include "unicode/fpositer.h"  // FieldPositionIterator
 #include "unicode/listformatter.h"
@@ -171,21 +175,21 @@ PatternHandler* createPatternHandler(
     UErrorCode& status) {
     if (uprv_strcmp(lang, "es") == 0) {
         // Spanish
-        UnicodeString spanishYStr(TRUE, spanishY, -1);
+        UnicodeString spanishYStr(true, spanishY, -1);
         bool twoIsY = two == spanishYStr;
         bool endIsY = end == spanishYStr;
         if (twoIsY || endIsY) {
-            UnicodeString replacement(TRUE, spanishE, -1);
+            UnicodeString replacement(true, spanishE, -1);
             return new ContextualHandler(
                 shouldChangeToE,
                 twoIsY ? replacement : two, two,
                 endIsY ? replacement : end, end, status);
         }
-        UnicodeString spanishOStr(TRUE, spanishO, -1);
+        UnicodeString spanishOStr(true, spanishO, -1);
         bool twoIsO = two == spanishOStr;
         bool endIsO = end == spanishOStr;
         if (twoIsO || endIsO) {
-            UnicodeString replacement(TRUE, spanishU, -1);
+            UnicodeString replacement(true, spanishU, -1);
             return new ContextualHandler(
                 shouldChangeToU,
                 twoIsO ? replacement : two, two,
@@ -193,11 +197,11 @@ PatternHandler* createPatternHandler(
         }
     } else if (uprv_strcmp(lang, "he") == 0 || uprv_strcmp(lang, "iw") == 0) {
         // Hebrew
-        UnicodeString hebrewVavStr(TRUE, hebrewVav, -1);
+        UnicodeString hebrewVavStr(true, hebrewVav, -1);
         bool twoIsVav = two == hebrewVavStr;
         bool endIsVav = end == hebrewVavStr;
         if (twoIsVav || endIsVav) {
-            UnicodeString replacement(TRUE, hebrewVavDash, -1);
+            UnicodeString replacement(true, hebrewVavDash, -1);
             return new ContextualHandler(
                 shouldChangeToVavDash,
                 twoIsVav ? replacement : two, two,
@@ -238,7 +242,6 @@ ListFormatInternal(const ListFormatInternal &other) :
 };
 
 
-#if !UCONFIG_NO_FORMATTING
 class FormattedListData : public FormattedValueStringBuilderImpl {
 public:
     FormattedListData(UErrorCode&) : FormattedValueStringBuilderImpl(kUndefinedField) {}
@@ -248,7 +251,6 @@ public:
 FormattedListData::~FormattedListData() = default;
 
 UPRV_FORMATTED_VALUE_SUBCLASS_AUTO_IMPL(FormattedList)
-#endif
 
 
 static Hashtable* listPatternHash = nullptr;
@@ -257,7 +259,7 @@ U_CDECL_BEGIN
 static UBool U_CALLCONV uprv_listformatter_cleanup() {
     delete listPatternHash;
     listPatternHash = nullptr;
-    return TRUE;
+    return true;
 }
 
 static void U_CALLCONV
@@ -350,7 +352,6 @@ const ListFormatInternal* ListFormatter::getListFormatInternal(
     return result;
 }
 
-#if !UCONFIG_NO_FORMATTING
 static const char* typeWidthToStyleString(UListFormatterType type, UListFormatterWidth width) {
     switch (type) {
         case ULISTFMT_TYPE_AND:
@@ -394,7 +395,6 @@ static const char* typeWidthToStyleString(UListFormatterType type, UListFormatte
 
     return nullptr;
 }
-#endif
 
 static const UChar solidus = 0x2F;
 static const UChar aliasPrefix[] = { 0x6C,0x69,0x73,0x74,0x50,0x61,0x74,0x74,0x65,0x72,0x6E,0x2F }; // "listPattern/"
@@ -515,14 +515,9 @@ ListFormatter* ListFormatter::createInstance(UErrorCode& errorCode) {
 }
 
 ListFormatter* ListFormatter::createInstance(const Locale& locale, UErrorCode& errorCode) {
-#if !UCONFIG_NO_FORMATTING
     return createInstance(locale, ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, errorCode);
-#else
-    return createInstance(locale, "standard", errorCode);
-#endif
 }
 
-#if !UCONFIG_NO_FORMATTING
 ListFormatter* ListFormatter::createInstance(
         const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode) {
     const char* style = typeWidthToStyleString(type, width);
@@ -532,7 +527,6 @@ ListFormatter* ListFormatter::createInstance(
     }
     return createInstance(locale, style, errorCode);
 }
-#endif
 
 ListFormatter* ListFormatter::createInstance(const Locale& locale, const char *style, UErrorCode& errorCode) {
     const ListFormatInternal* listFormatInternal = getListFormatInternal(locale, style, errorCode);
@@ -660,7 +654,6 @@ UnicodeString& ListFormatter::format(
         int32_t index,
         int32_t &offset,
         UErrorCode& errorCode) const {
-#if !UCONFIG_NO_FORMATTING
     int32_t initialOffset = appendTo.length();
     auto result = formatStringsToValue(items, nItems, errorCode);
     UnicodeStringAppendable appendable(appendTo);
@@ -671,11 +664,9 @@ UnicodeString& ListFormatter::format(
         result.nextPosition(cfpos, errorCode);
         offset = initialOffset + cfpos.getStart();
     }
-#endif
     return appendTo;
 }
 
-#if !UCONFIG_NO_FORMATTING
 FormattedList ListFormatter::formatStringsToValue(
         const UnicodeString items[],
         int32_t nItems,
@@ -741,7 +732,8 @@ FormattedList ListFormatter::formatStringsToValue(
         return FormattedList(result.data.orphan());
     }
 }
-#endif
 
 
 U_NAMESPACE_END
+
+#endif /* #if !UCONFIG_NO_FORMATTING */
index 211055d9d1c1d839ef02c91661066279d081e1c2..76a728942d97697bde72616c2199e432a099b7ea 100644 (file)
@@ -23,6 +23,8 @@
 
 #if U_SHOW_CPLUSPLUS_API
 
+#if !UCONFIG_NO_FORMATTING
+
 #include "unicode/unistr.h"
 #include "unicode/locid.h"
 #include "unicode/formattedvalue.h"
@@ -65,7 +67,6 @@ struct ListFormatData : public UMemory {
  */
 
 
-#if !UCONFIG_NO_FORMATTING
 /**
  * An immutable class containing the result of a list formatting operation.
  *
@@ -135,7 +136,6 @@ class U_I18N_API FormattedList : public UMemory, public FormattedValue {
         : fData(nullptr), fErrorCode(errorCode) {}
     friend class ListFormatter;
 };
-#endif // !UCONFIG_NO_FORMATTING
 
 
 /**
@@ -185,8 +185,6 @@ class U_I18N_API ListFormatter : public UObject{
      */
     static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
 
-#ifndef U_HIDE_DRAFT_API
-#if !UCONFIG_NO_FORMATTING
     /**
      * Creates a ListFormatter for the given locale, list type, and style.
      *
@@ -195,12 +193,10 @@ class U_I18N_API ListFormatter : public UObject{
      * @param width The width of formatting to use.
      * @param errorCode ICU error code, set if no data available for the given locale.
      * @return A ListFormatter object created from internal data derived from CLDR data.
-     * @draft ICU 67
+     * @stable ICU 67
      */
     static ListFormatter* createInstance(
       const Locale& locale, UListFormatterType type, UListFormatterWidth width, UErrorCode& errorCode);
-#endif  /* !UCONFIG_NO_FORMATTING */
-#endif  /* U_HIDE_DRAFT_API */
   
 #ifndef U_HIDE_INTERNAL_API
     /**
@@ -239,7 +235,6 @@ class U_I18N_API ListFormatter : public UObject{
     UnicodeString& format(const UnicodeString items[], int32_t n_items,
         UnicodeString& appendTo, UErrorCode& errorCode) const;
 
-#if !UCONFIG_NO_FORMATTING
     /**
      * Formats a list of strings to a FormattedList, which exposes field
      * position information. The FormattedList contains more information than
@@ -255,7 +250,6 @@ class U_I18N_API ListFormatter : public UObject{
         const UnicodeString items[],
         int32_t n_items,
         UErrorCode& errorCode) const;
-#endif // !UCONFIG_NO_FORMATTING
 
 #ifndef U_HIDE_INTERNAL_API
     /**
@@ -296,6 +290,8 @@ class U_I18N_API ListFormatter : public UObject{
 
 U_NAMESPACE_END
 
+#endif /* #if !UCONFIG_NO_FORMATTING */
+
 #endif /* U_SHOW_CPLUSPLUS_API */
 
 #endif // __LISTFORMATTER_H__
index 0500c89c48a465bdc63bbd5d4f59a558b808b5f1..8334c7852f0cc965599966033936843af652b960 100644 (file)
@@ -62,17 +62,16 @@ typedef enum UListFormatterField {
     ULISTFMT_ELEMENT_FIELD
 } UListFormatterField;
 
-#ifndef U_HIDE_DRAFT_API
 /**
  * Type of meaning expressed by the list.
  *
- * @draft ICU 67
+ * @stable ICU 67
  */
 typedef enum UListFormatterType {
     /**
      * Conjunction formatting, e.g. "Alice, Bob, Charlie, and Delta".
      *
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_TYPE_AND,
 
@@ -80,14 +79,14 @@ typedef enum UListFormatterType {
      * Disjunction (or alternative, or simply one of) formatting, e.g.
      * "Alice, Bob, Charlie, or Delta".
      *
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_TYPE_OR,
 
     /**
      * Formatting of a list of values with units, e.g. "5 pounds, 12 ounces".
      *
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_TYPE_UNITS
 } UListFormatterType;
@@ -95,29 +94,28 @@ typedef enum UListFormatterType {
 /**
  * Verbosity level of the list patterns.
  *
- * @draft ICU 67
+ * @stable ICU 67
  */
 typedef enum UListFormatterWidth {
     /**
      * Use list formatting with full words (no abbreviations) when possible.
      *
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_WIDTH_WIDE,
 
     /**
      * Use list formatting of typical length.
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_WIDTH_SHORT,
 
     /**
      * Use list formatting of the shortest possible length.
-     * @draft ICU 67
+     * @stable ICU 67
      */
     ULISTFMT_WIDTH_NARROW,
 } UListFormatterWidth;
-#endif /* U_HIDE_DRAFT_API */
 
 /**
  * Open a new UListFormatter object using the rules for a given locale.
@@ -141,7 +139,6 @@ U_CAPI UListFormatter* U_EXPORT2
 ulistfmt_open(const char*  locale,
               UErrorCode*  status);
 
-#ifndef U_HIDE_DRAFT_API
 /**
  * Open a new UListFormatter object appropriate for the given locale, list type,
  * and style.
@@ -162,12 +159,11 @@ ulistfmt_open(const char*  locale,
  * @return
  *            A pointer to a UListFormatter object for the specified locale,
  *            or NULL if an error occurred.
- * @draft ICU 67
+ * @stable ICU 67
  */
 U_CAPI UListFormatter* U_EXPORT2
 ulistfmt_openForType(const char*  locale, UListFormatterType type,
                      UListFormatterWidth width, UErrorCode*  status);
-#endif /* U_HIDE_DRAFT_API */
 
 /**
  * Close a UListFormatter object. Once closed it may no longer be used.