Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/format.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 ********************************************************************************
0005 * Copyright (C) 1997-2011, International Business Machines Corporation and others.
0006 * All Rights Reserved.
0007 ********************************************************************************
0008 *
0009 * File FORMAT.H
0010 *
0011 * Modification History:
0012 *
0013 *   Date        Name        Description
0014 *   02/19/97    aliu        Converted from java.
0015 *   03/17/97    clhuang     Updated per C++ implementation.
0016 *   03/27/97    helena      Updated to pass the simple test after code review.
0017 ********************************************************************************
0018 */
0019 // *****************************************************************************
0020 // This file was generated from the java source file Format.java
0021 // *****************************************************************************
0022 
0023 #ifndef FORMAT_H
0024 #define FORMAT_H
0025 
0026 
0027 #include "unicode/utypes.h"
0028 
0029 #if U_SHOW_CPLUSPLUS_API
0030 
0031 /**
0032  * \file 
0033  * \brief C++ API: Base class for all formats. 
0034  */
0035 
0036 #if !UCONFIG_NO_FORMATTING
0037 
0038 #include "unicode/unistr.h"
0039 #include "unicode/fmtable.h"
0040 #include "unicode/fieldpos.h"
0041 #include "unicode/fpositer.h"
0042 #include "unicode/parsepos.h"
0043 #include "unicode/parseerr.h" 
0044 #include "unicode/locid.h"
0045 
0046 U_NAMESPACE_BEGIN
0047 
0048 /**
0049  * Base class for all formats.  This is an abstract base class which
0050  * specifies the protocol for classes which convert other objects or
0051  * values, such as numeric values and dates, and their string
0052  * representations.  In some cases these representations may be
0053  * localized or contain localized characters or strings.  For example,
0054  * a numeric formatter such as DecimalFormat may convert a numeric
0055  * value such as 12345 to the string "$12,345".  It may also parse
0056  * the string back into a numeric value.  A date and time formatter
0057  * like SimpleDateFormat may represent a specific date, encoded
0058  * numerically, as a string such as "Wednesday, February 26, 1997 AD".
0059  * <P>
0060  * Many of the concrete subclasses of Format employ the notion of
0061  * a pattern.  A pattern is a string representation of the rules which
0062  * govern the interconversion between values and strings.  For example,
0063  * a DecimalFormat object may be associated with the pattern
0064  * "$#,##0.00;($#,##0.00)", which is a common US English format for
0065  * currency values, yielding strings such as "$1,234.45" for 1234.45,
0066  * and "($987.65)" for 987.6543.  The specific syntax of a pattern
0067  * is defined by each subclass.
0068  * <P>
0069  * Even though many subclasses use patterns, the notion of a pattern
0070  * is not inherent to Format classes in general, and is not part of
0071  * the explicit base class protocol.
0072  * <P>
0073  * Two complex formatting classes bear mentioning.  These are
0074  * MessageFormat and ChoiceFormat.  ChoiceFormat is a subclass of
0075  * NumberFormat which allows the user to format different number ranges
0076  * as strings.  For instance, 0 may be represented as "no files", 1 as
0077  * "one file", and any number greater than 1 as "many files".
0078  * MessageFormat is a formatter which utilizes other Format objects to
0079  * format a string containing with multiple values.  For instance,
0080  * A MessageFormat object might produce the string "There are no files
0081  * on the disk MyDisk on February 27, 1997." given the arguments 0,
0082  * "MyDisk", and the date value of 2/27/97.  See the ChoiceFormat
0083  * and MessageFormat headers for further information.
0084  * <P>
0085  * If formatting is unsuccessful, a failing UErrorCode is returned when
0086  * the Format cannot format the type of object, otherwise if there is
0087  * something illformed about the the Unicode replacement character
0088  * 0xFFFD is returned.
0089  * <P>
0090  * If there is no match when parsing, a parse failure UErrorCode is
0091  * returned for methods which take no ParsePosition.  For the method
0092  * that takes a ParsePosition, the index parameter is left unchanged.
0093  * <P>
0094  * <em>User subclasses are not supported.</em> While clients may write
0095  * subclasses, such code will not necessarily work and will not be
0096  * guaranteed to work stably from release to release.
0097  */
0098 class U_I18N_API Format : public UObject {
0099 public:
0100 
0101     /** Destructor
0102      * @stable ICU 2.4
0103      */
0104     virtual ~Format();
0105 
0106     /**
0107      * Return true if the given Format objects are semantically equal.
0108      * Objects of different subclasses are considered unequal.
0109      * @param other    the object to be compared with.
0110      * @return         Return true if the given Format objects are semantically equal.
0111      *                 Objects of different subclasses are considered unequal.
0112      * @stable ICU 2.0
0113      */
0114     virtual bool operator==(const Format& other) const = 0;
0115 
0116     /**
0117      * Return true if the given Format objects are not semantically
0118      * equal.
0119      * @param other    the object to be compared with.
0120      * @return         Return true if the given Format objects are not semantically.
0121      * @stable ICU 2.0
0122      */
0123     bool operator!=(const Format& other) const { return !operator==(other); }
0124 
0125     /**
0126      * Clone this object polymorphically.  The caller is responsible
0127      * for deleting the result when done.
0128      * @return    A copy of the object
0129      * @stable ICU 2.0
0130      */
0131     virtual Format* clone() const = 0;
0132 
0133     /**
0134      * Formats an object to produce a string.
0135      *
0136      * @param obj       The object to format.
0137      * @param appendTo  Output parameter to receive result.
0138      *                  Result is appended to existing contents.
0139      * @param status    Output parameter filled in with success or failure status.
0140      * @return          Reference to 'appendTo' parameter.
0141      * @stable ICU 2.0
0142      */
0143     UnicodeString& format(const Formattable& obj,
0144                           UnicodeString& appendTo,
0145                           UErrorCode& status) const;
0146 
0147     /**
0148      * Format an object to produce a string.  This is a pure virtual method which
0149      * subclasses must implement. This method allows polymorphic formatting
0150      * of Formattable objects. If a subclass of Format receives a Formattable
0151      * object type it doesn't handle (e.g., if a numeric Formattable is passed
0152      * to a DateFormat object) then it returns a failing UErrorCode.
0153      *
0154      * @param obj       The object to format.
0155      * @param appendTo  Output parameter to receive result.
0156      *                  Result is appended to existing contents.
0157      * @param pos       On input: an alignment field, if desired.
0158      *                  On output: the offsets of the alignment field.
0159      * @param status    Output param filled with success/failure status.
0160      * @return          Reference to 'appendTo' parameter.
0161      * @stable ICU 2.0
0162      */
0163     virtual UnicodeString& format(const Formattable& obj,
0164                                   UnicodeString& appendTo,
0165                                   FieldPosition& pos,
0166                                   UErrorCode& status) const = 0;
0167     /**
0168      * Format an object to produce a string.  Subclasses should override this
0169      * method. This method allows polymorphic formatting of Formattable objects.
0170      * If a subclass of Format receives a Formattable object type it doesn't
0171      * handle (e.g., if a numeric Formattable is passed to a DateFormat object)
0172      * then it returns a failing UErrorCode.
0173      *
0174      * @param obj       The object to format.
0175      * @param appendTo  Output parameter to receive result.
0176      *                  Result is appended to existing contents.
0177      * @param posIter   On return, can be used to iterate over positions
0178      *                  of fields generated by this format call.
0179      * @param status    Output param filled with success/failure status.
0180      * @return          Reference to 'appendTo' parameter.
0181      * @stable ICU 4.4
0182      */
0183     virtual UnicodeString& format(const Formattable& obj,
0184                                   UnicodeString& appendTo,
0185                                   FieldPositionIterator* posIter,
0186                                   UErrorCode& status) const;
0187 
0188     /**
0189      * Parse a string to produce an object.  This is a pure virtual
0190      * method which subclasses must implement.  This method allows
0191      * polymorphic parsing of strings into Formattable objects.
0192      * <P>
0193      * Before calling, set parse_pos.index to the offset you want to
0194      * start parsing at in the source.  After calling, parse_pos.index
0195      * is the end of the text you parsed.  If error occurs, index is
0196      * unchanged.
0197      * <P>
0198      * When parsing, leading whitespace is discarded (with successful
0199      * parse), while trailing whitespace is left as is.
0200      * <P>
0201      * Example:
0202      * <P>
0203      * Parsing "_12_xy" (where _ represents a space) for a number,
0204      * with index == 0 will result in the number 12, with
0205      * parse_pos.index updated to 3 (just before the second space).
0206      * Parsing a second time will result in a failing UErrorCode since
0207      * "xy" is not a number, and leave index at 3.
0208      * <P>
0209      * Subclasses will typically supply specific parse methods that
0210      * return different types of values. Since methods can't overload
0211      * on return types, these will typically be named "parse", while
0212      * this polymorphic method will always be called parseObject.  Any
0213      * parse method that does not take a parse_pos should set status
0214      * to an error value when no text in the required format is at the
0215      * start position.
0216      *
0217      * @param source    The string to be parsed into an object.
0218      * @param result    Formattable to be set to the parse result.
0219      *                  If parse fails, return contents are undefined.
0220      * @param parse_pos The position to start parsing at. Upon return
0221      *                  this param is set to the position after the
0222      *                  last character successfully parsed. If the
0223      *                  source is not parsed successfully, this param
0224      *                  will remain unchanged.
0225      * @stable ICU 2.0
0226      */
0227     virtual void parseObject(const UnicodeString& source,
0228                              Formattable& result,
0229                              ParsePosition& parse_pos) const = 0;
0230 
0231     /**
0232      * Parses a string to produce an object. This is a convenience method
0233      * which calls the pure virtual parseObject() method, and returns a
0234      * failure UErrorCode if the ParsePosition indicates failure.
0235      *
0236      * @param source    The string to be parsed into an object.
0237      * @param result    Formattable to be set to the parse result.
0238      *                  If parse fails, return contents are undefined.
0239      * @param status    Output param to be filled with success/failure
0240      *                  result code.
0241      * @stable ICU 2.0
0242      */
0243     void parseObject(const UnicodeString& source,
0244                      Formattable& result,
0245                      UErrorCode& status) const;
0246 
0247     /** Get the locale for this format object. You can choose between valid and actual locale.
0248      *  @param type type of the locale we're looking for (valid or actual) 
0249      *  @param status error code for the operation
0250      *  @return the locale
0251      *  @stable ICU 2.8
0252      */
0253     Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
0254 
0255 #ifndef U_HIDE_INTERNAL_API
0256     /** Get the locale for this format object. You can choose between valid and actual locale.
0257      *  @param type type of the locale we're looking for (valid or actual) 
0258      *  @param status error code for the operation
0259      *  @return the locale
0260      *  @internal
0261      */
0262     const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
0263 #endif  /* U_HIDE_INTERNAL_API */
0264 
0265  protected:
0266     /** @stable ICU 2.8 */
0267     void setLocaleIDs(const char* valid, const char* actual);
0268 
0269 protected:
0270     /**
0271      * Default constructor for subclass use only.  Does nothing.
0272      * @stable ICU 2.0
0273      */
0274     Format();
0275 
0276     /**
0277      * @stable ICU 2.0
0278      */
0279     Format(const Format&); // Does nothing; for subclasses only
0280 
0281     /**
0282      * @stable ICU 2.0
0283      */
0284     Format& operator=(const Format&); // Does nothing; for subclasses
0285 
0286        
0287     /**
0288      * Simple function for initializing a UParseError from a UnicodeString.
0289      *
0290      * @param pattern The pattern to copy into the parseError
0291      * @param pos The position in pattern where the error occurred
0292      * @param parseError The UParseError object to fill in
0293      * @stable ICU 2.4
0294      */
0295     static void syntaxError(const UnicodeString& pattern,
0296                             int32_t pos,
0297                             UParseError& parseError);
0298 
0299  private:
0300     char actualLocale[ULOC_FULLNAME_CAPACITY];
0301     char validLocale[ULOC_FULLNAME_CAPACITY];
0302 };
0303 
0304 U_NAMESPACE_END
0305 
0306 #endif /* #if !UCONFIG_NO_FORMATTING */
0307 
0308 #endif /* U_SHOW_CPLUSPLUS_API */
0309 
0310 #endif // _FORMAT
0311 //eof