intl/icu/source/common/unicode/listformatter.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/unicode/listformatter.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,155 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2012-2013, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  listformatter.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 20120426
    1.17 +*   created by: Umesh P. Nair
    1.18 +*/
    1.19 +
    1.20 +#ifndef __LISTFORMATTER_H__
    1.21 +#define __LISTFORMATTER_H__
    1.22 +
    1.23 +#include "unicode/utypes.h"
    1.24 +
    1.25 +#ifndef U_HIDE_DRAFT_API
    1.26 +
    1.27 +#include "unicode/unistr.h"
    1.28 +#include "unicode/locid.h"
    1.29 +
    1.30 +U_NAMESPACE_BEGIN
    1.31 +
    1.32 +/** @internal */
    1.33 +class Hashtable;
    1.34 +
    1.35 +#ifndef U_HIDE_INTERNAL_API
    1.36 +/** @internal */
    1.37 +struct ListFormatData : public UMemory {
    1.38 +    UnicodeString twoPattern;
    1.39 +    UnicodeString startPattern;
    1.40 +    UnicodeString middlePattern;
    1.41 +    UnicodeString endPattern;
    1.42 +
    1.43 +  ListFormatData(const UnicodeString& two, const UnicodeString& start, const UnicodeString& middle, const UnicodeString& end) :
    1.44 +      twoPattern(two), startPattern(start), middlePattern(middle), endPattern(end) {}
    1.45 +};
    1.46 +#endif  /* U_HIDE_INTERNAL_API */
    1.47 +
    1.48 +
    1.49 +/**
    1.50 + * \file
    1.51 + * \brief C++ API: API for formatting a list.
    1.52 + */
    1.53 +
    1.54 +
    1.55 +/**
    1.56 + * An immutable class for formatting a list, using data from CLDR (or supplied
    1.57 + * separately).
    1.58 + *
    1.59 + * Example: Input data ["Alice", "Bob", "Charlie", "Delta"] will be formatted
    1.60 + * as "Alice, Bob, Charlie and Delta" in English.
    1.61 + *
    1.62 + * The ListFormatter class is not intended for public subclassing.
    1.63 + * @draft ICU 50
    1.64 + */
    1.65 +class U_COMMON_API ListFormatter : public UObject{
    1.66 +
    1.67 +  public:
    1.68 +
    1.69 +    /**
    1.70 +     * Copy constructor.
    1.71 +     * @draft ICU 52
    1.72 +     */
    1.73 +    ListFormatter(const ListFormatter&);
    1.74 +
    1.75 +    /**
    1.76 +     * Assignment operator.
    1.77 +     * @draft ICU 52
    1.78 +     */
    1.79 +    ListFormatter& operator=(const ListFormatter& other);
    1.80 +
    1.81 +    /**
    1.82 +     * Creates a ListFormatter appropriate for the default locale.
    1.83 +     *
    1.84 +     * @param errorCode ICU error code, set if no data available for default locale.
    1.85 +     * @return Pointer to a ListFormatter object for the default locale,
    1.86 +     *     created from internal data derived from CLDR data.
    1.87 +     * @draft ICU 50
    1.88 +     */
    1.89 +    static ListFormatter* createInstance(UErrorCode& errorCode);
    1.90 +
    1.91 +    /**
    1.92 +     * Creates a ListFormatter appropriate for a locale.
    1.93 +     *
    1.94 +     * @param locale The locale.
    1.95 +     * @param errorCode ICU error code, set if no data available for the given locale.
    1.96 +     * @return A ListFormatter object created from internal data derived from
    1.97 +     *     CLDR data.
    1.98 +     * @draft ICU 50
    1.99 +     */
   1.100 +    static ListFormatter* createInstance(const Locale& locale, UErrorCode& errorCode);
   1.101 +
   1.102 +#ifndef U_HIDE_INTERNAL_API
   1.103 +    /**
   1.104 +     * Creates a ListFormatter appropriate for a locale and style.
   1.105 +     *
   1.106 +     * @param locale The locale.
   1.107 +     * @param style the style, either "standard", "duration", or "duration-short"
   1.108 +     * @param errorCode ICU error code, set if no data available for the given locale.
   1.109 +     * @return A ListFormatter object created from internal data derived from
   1.110 +     *     CLDR data.
   1.111 +     * @internal
   1.112 +     */
   1.113 +    static ListFormatter* createInstance(const Locale& locale, const char* style, UErrorCode& errorCode);
   1.114 +#endif  /* U_HIDE_INTERNAL_API */
   1.115 +
   1.116 +    /**
   1.117 +     * Destructor.
   1.118 +     *
   1.119 +     * @draft ICU 50
   1.120 +     */
   1.121 +    virtual ~ListFormatter();
   1.122 +
   1.123 +
   1.124 +    /**
   1.125 +     * Formats a list of strings.
   1.126 +     *
   1.127 +     * @param items An array of strings to be combined and formatted.
   1.128 +     * @param n_items Length of the array items.
   1.129 +     * @param appendTo The string to which the result should be appended to.
   1.130 +     * @param errorCode ICU error code, set if there is an error.
   1.131 +     * @return Formatted string combining the elements of items, appended to appendTo.
   1.132 +     * @draft ICU 50
   1.133 +     */
   1.134 +    UnicodeString& format(const UnicodeString items[], int32_t n_items,
   1.135 +        UnicodeString& appendTo, UErrorCode& errorCode) const;
   1.136 +
   1.137 +#ifndef U_HIDE_INTERNAL_API
   1.138 +    /**
   1.139 +     * @internal constructor made public for testing.
   1.140 +     */
   1.141 +    ListFormatter(const ListFormatData* listFormatterData);
   1.142 +#endif  /* U_HIDE_INTERNAL_API */
   1.143 +
   1.144 +  private:
   1.145 +    static void initializeHash(UErrorCode& errorCode);
   1.146 +    static const ListFormatData* getListFormatData(const Locale& locale, const char *style, UErrorCode& errorCode);
   1.147 +
   1.148 +    ListFormatter();
   1.149 +    void addNewString(const UnicodeString& pattern, UnicodeString& originalString,
   1.150 +                      const UnicodeString& newString, UErrorCode& errorCode) const;
   1.151 +
   1.152 +    const ListFormatData* data;
   1.153 +};
   1.154 +
   1.155 +U_NAMESPACE_END
   1.156 +
   1.157 +#endif /* U_HIDE_DRAFT_API */
   1.158 +#endif

mercurial