ICU-329 First take on adding better error reporting with UParseError struct.

X-SVN-Rev: 5473
This commit is contained in:
Ram Viswanadha 2001-08-16 00:55:51 +00:00
parent d7d6c296e2
commit 00462d3f97
11 changed files with 669 additions and 101 deletions

View File

@ -28,7 +28,6 @@
#include "unicode/numfmt.h"
#include "unicode/fieldpos.h"
#include "unicode/format.h"
/**
* <p><code>ChoiceFormat</code> converts between ranges of numeric values
* and string names for those ranges. A <code>ChoiceFormat</code> splits
@ -329,6 +328,19 @@ public:
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
/**
* Sets the pattern.
* @param pattern The pattern to be applied.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @draft
*/
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
/**
* Gets the pattern.
* @stable
@ -564,8 +576,8 @@ public:
private:
// static cache management (thread-safe)
static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
static void releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
// static NumberFormat* getNumberFormat(UErrorCode &status); // call this function to 'check out' a numberformat from the cache.
// static void releaseNumberFormat(NumberFormat *adopt); // call this function to 'return' the number format to the cache.
/**
* Converts a string to a double value using a default NumberFormat object
@ -586,13 +598,26 @@ private:
*/
static UnicodeString& dtos(double value, UnicodeString& string, UErrorCode& status);
static UMTX fgMutex;
static NumberFormat* fgNumberFormat;
//static UMTX fgMutex;
//static NumberFormat* fgNumberFormat;
static char fgClassID;
static const UChar fgPositiveInfinity[];
static const UChar fgNegativeInfinity[];
/**
* Construct a new ChoiceFormat with the limits and the corresponding formats
* based on the pattern.
*
* @param pattern Pattern used to construct object.
* @param status Output param to receive success code. If the
* pattern cannot be parsed, set to failure code.
* @stable
*/
ChoiceFormat(const UnicodeString& newPattern,
UParseError& parseError,
UErrorCode& status);
friend class MessageFormat;
/**
* Each ChoiceFormat divides the range -Inf..+Inf into fCount
* intervals. The intervals are:

View File

@ -27,7 +27,6 @@
#include "unicode/utypes.h"
#include "unicode/numfmt.h"
#include "unicode/locid.h"
class DecimalFormatSymbols;
class DigitList;
@ -249,6 +248,29 @@ public:
DecimalFormatSymbols* symbolsToAdopt,
UErrorCode& status);
/**
* Create a DecimalFormat from the given pattern and symbols.
* Use this constructor when you need to completely customize the
* behavior of the format.
* <P>
* To obtain standard formats for a given
* locale, use the factory methods on NumberFormat such as
* getInstance or getCurrencyInstance. If you need only minor adjustments
* to a standard format, you can modify the format returned by
* a NumberFormat factory method.
*
* @param pattern a non-localized pattern string
* @param symbolsToAdopt the set of symbols to be used. The caller should not
* delete this object after making this call.
* @param parseError Output param to receive errors occured during parsing
* @param status Output param set to success/failure code. If the
* pattern is invalid this will be set to a failure code.
* @stable
*/
DecimalFormat( const UnicodeString& pattern,
DecimalFormatSymbols* symbolsToAdopt,
UParseError& parseError,
UErrorCode& status);
/**
* Create a DecimalFormat from the given pattern and symbols.
* Use this constructor when you need to completely customize the
@ -841,14 +863,28 @@ public:
* In negative patterns, the minimum and maximum counts are ignored;
* these are presumed to be set in the positive pattern.
*
* @param pattern The pattern to be applied.
* @param pattern The pattern to be applied.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @stable
*/
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
/**
* Sets the pattern.
* @param pattern The pattern to be applied.
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @stable
*/
*/
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
UErrorCode& status);
/**
* Apply the given pattern to this Format object. The pattern
@ -879,8 +915,14 @@ public:
* @stable
*/
virtual void applyLocalizedPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
virtual void applyLocalizedPattern(const UnicodeString& pattern,
UErrorCode& status);
/**
* Sets the maximum number of digits allowed in the integer portion of a
* number. This override limits the integer digit count to 309.
@ -950,14 +992,16 @@ public:
private:
static char fgClassID;
static UParseError fParseError;
/**
* Do real work of constructing a new DecimalFormat.
*/
void construct(UErrorCode& status,
UParseError& parseErr,
const UnicodeString* pattern = 0,
DecimalFormatSymbols* symbolsToAdopt = 0,
const Locale& locale = Locale::getDefault());
const Locale& locale = Locale::getDefault()
);
/**
* Does the real work of generating a pattern.
@ -966,16 +1010,18 @@ private:
/**
* Does the real work of applying a pattern.
* @param pattern The pattern to be applied.
* @param localized If true, the pattern is localized; else false.
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @param pattern The pattern to be applied.
* @param localized If true, the pattern is localized; else false.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
*/
void applyPattern(const UnicodeString& pattern,
UBool localized,
UParseError& parseError,
UErrorCode& status);
/**
* Do the work of formatting a number, either a double or a long.
*/

View File

@ -26,7 +26,7 @@
#include "unicode/fmtable.h"
#include "unicode/fieldpos.h"
#include "unicode/parsepos.h"
#include "unicode/parseerr.h"
/**
* Base class for all formats. This is an abstract base class which
* specifies the protocol for classes which convert other objects or
@ -236,6 +236,12 @@ protected:
* @stable
*/
Format& operator=(const Format&); // Does nothing; for subclasses
inline void syntaxError(const UnicodeString& pattern,
int32_t pos,
UParseError& parseError,
UErrorCode& status);
};
#endif // _FORMAT

View File

@ -9,7 +9,7 @@
* Date Name Description
* 02/19/97 aliu Converted from java.
* 03/20/97 helena Finished first cut of implementation.
* 07/22/98 stephen Removed operator!= (defined in Format)
* 07/22/98 stephen Removed operator!= (defined in Format)
********************************************************************************
*/
// *****************************************************************************
@ -22,6 +22,8 @@
#include "unicode/utypes.h"
#include "unicode/format.h"
#include "unicode/locid.h"
#include "unicode/parseerr.h"
class NumberFormat;
/**
@ -189,7 +191,7 @@ class NumberFormat;
*/
class U_I18N_API MessageFormat : public Format {
public:
enum EFormatNumber { kMaxFormat = 10 };
static enum EFormatNumber { kMaxFormat = 10 };
/**
* Construct a new MessageFormat using the given pattern.
*
@ -212,7 +214,20 @@ public:
MessageFormat(const UnicodeString& pattern,
const Locale& newLocale,
UErrorCode& success);
/**
* Constructor that allows locale specification.
* @param pattern Pattern used to construct object.
* @param newLocale The locale to use for formatting dates and numbers.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param to receive success code. If the
* pattern cannot be parsed, set to failure code.
* @stable
*/
MessageFormat(const UnicodeString& pattern,
const Locale& newLocale,
UParseError& parseError,
UErrorCode& success);
/**
* Copy constructor.
* @stable
@ -270,6 +285,19 @@ public:
*/
virtual void applyPattern(const UnicodeString& pattern,
UErrorCode& status);
/**
* Sets the pattern.
* @param pattern The pattern to be applied.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @draft
*/
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status);
/**
* Gets the pattern. See the class description.
@ -480,10 +508,28 @@ public:
* @stable
*/
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
/**
* Returns array of formattable types in the parsed pattern
* for use in C API
* @param count Output parameter to receive the size of array
* @return The array of formattable types in the pattern
* @internal
*/
const Formattable::Type* getFormatTypeList(int32_t& listCount){
listCount=fListCount;
return fFormatTypeList;
}
private:
static char fgClassID;
static NumberFormat* fgNumberFormat;
//static NumberFormat* fgNumberFormat;
/* stores types of formattable objects in the pattern
* is for umsg_* CAPI
*/
Formattable::Type fFormatTypeList[kMaxFormat];
int32_t fListCount;
// fgNumberFormat is held in a cache of one.
@ -537,6 +583,7 @@ private:
void makeFormat( /*int32_t position, */
int32_t offsetNumber,
UnicodeString* segments,
UParseError& parseError,
UErrorCode& success);
/**

View File

@ -23,7 +23,6 @@
#include "unicode/utypes.h"
#include "unicode/unistr.h"
#include "unicode/format.h"
class Locale;
/**
@ -469,6 +468,21 @@ public:
*/
virtual void setMinimumFractionDigits(int32_t newValue);
/**
* Applies the pattern to NumberFormat object. Pure virtual function
* subclasses must implement it
*
* @param pattern The pattern to be applied.
* @param parseError Struct to recieve information on position
* of error if an error is encountered
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @stable
*/
virtual void applyPattern(const UnicodeString& pattern,
UParseError& parseError,
UErrorCode& status)=0;
public:
/**

View File

@ -47,7 +47,7 @@ typedef struct _UParseError {
* Parse engines should define the enum PARSE_ERROR_BASE
* to be 0xNNNN0000.
*/
int32_t code;
//int32_t code;
/**
* The line on which the error occured. If the parse engine

View File

@ -443,7 +443,7 @@ public:
* Parse error codes generated by RuleBasedTransliterator.
* See parseerr.h.
*/
enum {
/*enum {
PARSE_ERROR_BASE = 0x10000,
BAD_VARIABLE_DEFINITION,
MALFORMED_RULE,
@ -467,7 +467,7 @@ public:
UNQUOTED_SPECIAL,
UNTERMINATED_QUOTE
};
*/
private:
/**

View File

@ -1,6 +1,7 @@
/*
*******************************************************************************
* Copyright (c) {1996-2001}, International Business Machines Corporation and others. All Rights Reserved.
* Copyright (c) {1996-2001}, International Business Machines Corporation and others.
* All Rights Reserved.
*******************************************************************************
*/
@ -9,6 +10,7 @@
#include "unicode/utypes.h"
#include "unicode/unorm.h"
#include "unicode/parseerr.h"
/**
* \file
@ -274,16 +276,19 @@ ucol_openVersion(const char *loc,
* @param strength The collation strength; one of UCOL_PRIMARY, UCOL_SECONDARY,
* UCOL_TERTIARY, UCOL_IDENTICAL,UCOL_DEFAULT_STRENGTH
* @param status A pointer to an UErrorCode to receive any errors
* @param parseError A pointer to UParseError to recieve information about errors
* occurred during parsing.
* @return A pointer to a UCollator, or 0 if an error occurred.
* @see ucol_open
* @stable
*/
U_CAPI UCollator*
ucol_openRules( const UChar *rules,
int32_t rulesLength,
UNormalizationMode mode,
UCollationStrength strength,
UErrorCode *status);
ucol_openRules( const UChar *rules,
int32_t rulesLength,
UNormalizationMode mode,
UCollationStrength strength,
UParseError *parseError,
UErrorCode *status);
/**
* Close a UCollator.
@ -659,4 +664,11 @@ void ucol_checkState (const uint8_t *state, UErrorCode *status);
*/
UCollator *ucol_openState(const uint8_t *state, UErrorCode *status);
/********************************* Deprecated API ********************************/
#ifdef U_USE_DEPRECATED_FORMAT_API
#define ucol_openRules_1_9(rules,rulesLength,modes,strength,status) ucol_openRules(rules,rulesLength,modes,strength,NULL,status)
#endif
/********************************* End *******************************************/
#endif

View File

@ -120,7 +120,10 @@ enum UDateFormatStyle {
/** Default style */
UDAT_DEFAULT = UDAT_MEDIUM,
/** No style */
UDAT_NONE = -1
UDAT_NONE = -1,
/** for internal API use only */
UDAT_IGNORE = -2
};
typedef enum UDateFormatStyle UDateFormatStyle;
@ -141,7 +144,7 @@ typedef enum UDateFormatStyle UDateFormatStyle;
* an error occurred.
* @see udat_openPattern
* @draft
*/
* /
U_CAPI UDateFormat*
udat_open(UDateFormatStyle timeStyle,
UDateFormatStyle dateStyle,
@ -162,13 +165,42 @@ udat_open(UDateFormatStyle timeStyle,
* an error occurred.
* @see udat_open
* @draft
*/
* /
U_CAPI UDateFormat*
udat_openPattern( const UChar *pattern,
int32_t patternLength,
const char *locale,
UErrorCode *status);
/**
* Open a new UDateFormat for formatting and parsing dates and times.
* A UDateFormat may be used to format dates in calls to \Ref{udat_format},
* and to parse dates in calls to \Ref{udat_parse}.
* @param timeStyle The style used to format times; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE,
* UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE
* @param dateStyle The style used to format dates; one of UDAT_FULL_STYLE, UDAT_LONG_STYLE,
* UDAT_MEDIUM_STYLE, UDAT_SHORT_STYLE, or UDAT_DEFAULT_STYLE
* @param locale The locale specifying the formatting conventions
* @param tzID A timezone ID specifying the timezone to use. If 0, use
* the default timezone.
* @param tzIDLength The length of tzID, or -1 if null-terminated.
* @param status A pointer to an UErrorCode to receive any errors
* @param pattern A pattern specifying the format to use.
* @param patternLength The number of characters in the pattern, or -1 if null-terminated.
* @param locale The locale specifying the formatting conventions
* @param status A pointer to an UErrorCode to receive any errors
* @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
* an error occurred.
* @draft
*/
U_CAPI UDateFormat*
udat_open(UDateFormatStyle timeStyle,
UDateFormatStyle dateStyle,
const char *locale,
const UChar *tzID,
int32_t tzIDLength,
const UChar *pattern,
int32_t patternLength,
UErrorCode *status);
/**
* Close a UDateFormat.
* Once closed, a UDateFormat may no longer be used.
@ -489,4 +521,14 @@ udat_setSymbols( UDateFormat *format,
int32_t valueLength,
UErrorCode *status);
/********************* Deprecated API ************************************/
#ifdef U_USE_DEPRECATED_FORMAT_API
static UDateFormat*
udat_openPattern(UChar* pattern,int32_t patternLength,const char* locale,UErrorCode *status)
{
return udat_open(UDAT_IGNORE,UDAT_IGNORE,locale,NULL,0,pattern,patternLength,status);
}
#define udat_open_1_9(timeStyle,dateStyle,locale,tzId,tzIdLength,status) udat_open(timeStyle,dateStyle,locale,tzId,tzIdLength,NULL,0,status)
#endif
/********************* End **********************************************/
#endif

View File

@ -2,12 +2,24 @@
*******************************************************************************
* Copyright (C) 1996-2001, International Business Machines Corporation and others. All Rights Reserved.
*******************************************************************************
*
* file name: umsg.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* Change history:
*
* 08/5/2001 Ram Added C wrappers for C++ API.
*
*
*/
#ifndef UMSG_H
#define UMSG_H
#include "unicode/utypes.h"
#include "unicode/parseerr.h"
#include <stdarg.h>
/**
* \file
@ -167,57 +179,165 @@
*/
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments specified
* in pattern.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
* @see u_parseMessage
* @draft should this just be usprintf?
*/
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments specified
* in pattern.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
* @see u_parseMessage
* @draft should this just be usprintf?
*/
U_CAPI int32_t
u_formatMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
UErrorCode *status,
u_formatMessage(const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
UErrorCode *status,
...);
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param ap A variable-length argument list containing the arguments specified
* @param status A pointer to an UErrorCode to receive any errors
* in pattern.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
* @see u_parseMessage
*/
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param ap A variable-length argument list containing the arguments specified
* @param status A pointer to an UErrorCode to receive any errors
* in pattern.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
* @see u_parseMessage
*/
U_CAPI int32_t
u_vformatMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
va_list ap,
UErrorCode *status);
u_vformatMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
va_list ap,
UErrorCode *status);
/**
* Parse a message.
* For numeric arguments, this function will always use doubles. Integer types
* should not be passed.
* This function is not able to parse all output from \Ref{u_formatMessage}.
* @param locale The locale for which the message is formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments
* specified in pattern.
* @see u_formatMessage
* @draft
*/
U_CAPI void
u_parseMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
UErrorCode *status,
...);
/**
* Parse a message.
* For numeric arguments, this function will always use doubles. Integer types
* should not be passed.
* This function is not able to parse all output from \Ref{u_formatMessage}.
* @param locale The locale for which the message is formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param ap A variable-length argument list containing the arguments
* @param status A pointer to an UErrorCode to receive any errors
* specified in pattern.
* @see u_formatMessage
*/
U_CAPI void
u_vparseMessage(const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
va_list ap,
UErrorCode *status);
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments specified
* in pattern.
* @param parseError A pointer to UParseError to receive information about errors
* occurred during parsing.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
* @see u_parseMessage
* @draft
*/
U_CAPI int32_t
u_formatMessageWithError( const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
UParseError *parseError,
UErrorCode *status,
...);
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param locale The locale for which the message will be formatted
* @param pattern The pattern specifying the message's format
* @param patternLength The length of pattern
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param parseError A pointer to UParseError to receive information about errors
* occurred during parsing.
* @param ap A variable-length argument list containing the arguments specified
* @param status A pointer to an UErrorCode to receive any errors
* in pattern.
* @return The total buffer size needed; if greater than resultLength, the
* output was truncated.
*/
U_CAPI int32_t
u_vformatMessageWithError( const char *locale,
const UChar *pattern,
int32_t patternLength,
UChar *result,
int32_t resultLength,
UParseError* parseError,
va_list ap,
UErrorCode *status);
/**
* Parse a message.
* For numeric arguments, this function will always use doubles. Integer types
@ -228,6 +348,8 @@ u_vformatMessage( const char *locale,
* @param patternLength The length of pattern
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param parseError A pointer to UParseError to receive information about errors
* occurred during parsing.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments
* specified in pattern.
@ -235,13 +357,14 @@ u_vformatMessage( const char *locale,
* @draft
*/
U_CAPI void
u_parseMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
UErrorCode *status,
...);
u_parseMessageWithError(const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
UParseError *error,
UErrorCode *status,
...);
/**
* Parse a message.
@ -254,17 +377,204 @@ u_parseMessage( const char *locale,
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param ap A variable-length argument list containing the arguments
* @param parseError A pointer to UParseError to receive information about errors
* occurred during parsing.
* @param status A pointer to an UErrorCode to receive any errors
* specified in pattern.
* @see u_formatMessage
*/
U_CAPI void
u_vparseMessage( const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
va_list ap,
UErrorCode *status);
u_vparseMessageWithError(const char *locale,
const UChar *pattern,
int32_t patternLength,
const UChar *source,
int32_t sourceLength,
va_list ap,
UParseError *error,
UErrorCode* status);
/////////// New experimental API //////////////////////////////////////////////////
typedef void* UMessageFormat;
/**
* Open a message formatter with given pattern and for the given locale.
* @param pattern A pattern specifying the format to use.
* @param patternLength Length of the pattern to use
* @param locale The locale for which the messages are formatted.
* @param parseError A pointer to UParseError struct to receive any errors
* occured during parsing. Can be NULL.
* @param status A pointer to an UErrorCode to receive any errors.
* @return A pointer to a UMessageFormat to use for formatting
* messages, or 0 if an error occurred.
* @draft
*/
U_CAPI UMessageFormat*
umsg_open( const UChar *pattern,
int32_t patternLength,
const char *locale,
UParseError *parseError,
UErrorCode *status);
/**
* Close a UMessageFormat.
* Once closed, a UMessageFormat may no longer be used.
* @param fmt The formatter to close.
* @draft
*/
U_CAPI void
umsg_close(UMessageFormat* format);
/**
* Open a copy of a UMessageFormat.
* This function performs a deep copy.
* @param fmt The formatter to copy
* @param status A pointer to an UErrorCode to receive any errors.
* @return A pointer to a UDateFormat identical to fmt.
* @draft
*/
U_CAPI UMessageFormat
umsg_clone(const UMessageFormat *fmt,
UErrorCode *status);
/**
* Sets the locale. This locale is used for fetching default number or date
* format information.
* @param fmt The formatter to set
* @param locale The locale the formatter should use.
*/
U_CAPI void
umsg_setLocale(UMessageFormat *fmt,
const char* locale);
/**
* Gets the locale. This locale is used for fetching default number or date
* format information.
* @param The formatter to querry
* @draft
*/
U_CAPI const char*
umsg_getLocale(UMessageFormat *fmt);
/**
* Sets the pattern.
* @param fmt The formatter to use
* @param pattern The pattern to be applied.
* @param patternLength Length of the pattern to use
* @param parseError Struct to receive information on position
* of error if an error is encountered.Can be NULL.
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @draft
*/
U_CAPI void
umsg_applyPattern( UMessageFormat *fmt,
const UChar* pattern,
int32_t patternLength,
UParseError* parseError,
UErrorCode* status);
/**
* Gets the pattern.
* @param fmt The formatter to use
* @param result A pointer to a buffer to receive the pattern.
* @param resultLength The maximum size of result.
* @param status Output param set to success/failure code on
* exit. If the pattern is invalid, this will be
* set to a failure result.
* @draft
*/
U_CAPI int32_t
umsg_toPattern(UMessageFormat *fmt,
UChar* result,
int32_t resultLength,
UErrorCode* status);
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param fmt The formatter to use
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments
* specified in pattern.
* @return The total buffer size needed; if greater than resultLength,
* the output was truncated.
* @draft
*/
U_CAPI int32_t
umsg_format( UMessageFormat *fmt,
UChar *result,
int32_t resultLength,
UErrorCode *status,
...);
/**
* Format a message for a locale.
* This function may perform re-ordering of the arguments depending on the
* locale. For all numeric arguments, double is assumed unless the type is
* explicitly integer. All choice format arguments must be of type double.
* @param fmt The formatter to use
* @param result A pointer to a buffer to receive the formatted message.
* @param resultLength The maximum size of result.
* @param ap A variable-length argument list containing the arguments
* @param status A pointer to an UErrorCode to receive any errors
* specified in pattern.
* @return The total buffer size needed; if greater than resultLength,
* the output was truncated.
*/
U_CAPI int32_t
umsg_vformat( UMessageFormat *fmt,
UChar *result,
int32_t resultLength,
va_list ap,
UErrorCode *status);
/**
* Parse a message.
* For numeric arguments, this function will always use doubles. Integer types
* should not be passed.
* This function is not able to parse all output from \Ref{umsg_format}.
* @param fmt The formatter to use
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param count Output param to receive number of elements returned.
* @param status A pointer to an UErrorCode to receive any errors
* @param ... A variable-length argument list containing the arguments
* specified in pattern.
* @draft
*/
U_CAPI void
umsg_parse( UMessageFormat *fmt,
const UChar *source,
int32_t sourceLength,
int32_t *count,
UErrorCode *status,
...);
/**
* Parse a message.
* For numeric arguments, this function will always use doubles. Integer types
* should not be passed.
* This function is not able to parse all output from \Ref{umsg_format}.
* @param fmt The formatter to use
* @param source The text to parse.
* @param sourceLength The length of source, or -1 if null-terminated.
* @param count Output param to receive number of elements returned.
* @param ap A variable-length argument list containing the arguments
* @param status A pointer to an UErrorCode to receive any errors
* specified in pattern.
* @see u_formatMessage
*/
U_CAPI void
umsg_vparse(UMessageFormat *fmt,
const UChar *source,
int32_t sourceLength,
int32_t *count,
va_list ap,
UErrorCode *status);
#endif

View File

@ -13,7 +13,7 @@
#include "unicode/utypes.h"
#include "unicode/umisc.h"
#include "unicode/parseerr.h"
/**
* \file
* \brief C API: NumberFormat
@ -115,8 +115,9 @@ typedef void* UNumberFormat;
/** The possible number format styles. */
enum UNumberFormatStyle {
UNUM_IGNORE=0,
/** Decimal format */
UNUM_DECIMAL,
UNUM_DECIMAL=1,
/** Currency format */
UNUM_CURRENCY,
/** Percent format */
@ -159,7 +160,8 @@ typedef enum UNumberFormatPadPosition UNumberFormatPadPosition;
* an error occurred.
* @see unum_openPattern
* @stable
*/
* @deprecated
* /
U_CAPI UNumberFormat*
unum_open(UNumberFormatStyle style,
const char* locale,
@ -176,14 +178,38 @@ unum_open(UNumberFormatStyle style,
* @return A pointer to a UNumberFormat to use for formatting numbers, or 0 if
* an error occurred.
* @see unum_open
* @draft
*/
* @deprecated
* /
U_CAPI UNumberFormat*
unum_openPattern( const UChar* pattern,
int32_t patternLength,
const char* locale,
UErrorCode* status);
/**
* Open a new UNumberFormat for formatting and parsing numbers.
* A UNumberFormat may be used to format numbers in calls to \Ref{unum_format},
* and to parse numbers in calls to \Ref{unum_parse}.
* @param style The type of number format to open: one of UNUM_DECIMAL, UNUM_CURRENCY,
* UNUM_PERCENT, UNUM_SPELLOUT, or UNUM_DEFAULT
* @param pattern A pattern specifying the format to use.
* @param patternLength The number of characters in the pattern, or -1 if null-terminated.
* @param locale The locale specifying the formatting conventions
* @param status A pointer to an UErrorCode to receive any errors
* @return A pointer to a UNumberFormat to use for formatting numbers, or 0 if
* an error occurred.
* @see unum_open
* @draft
*/
U_CAPI UNumberFormat*
unum_open( UNumberFormatStyle style,
const UChar* pattern,
int32_t patternLength,
const char* locale,
UParseError* parseErr,
UErrorCode* status);
/**
* Close a UNumberFormat.
* Once closed, a UNumberFormat may no longer be used.
@ -312,12 +338,36 @@ unum_parseDouble( const UNumberFormat* fmt,
* @param patternLength The length of pattern, or -1 if null-terminated.
* @see unum_toPattern
* @draft
* /
U_CAPI void
unum_applyPattern( UNumberFormat *format,
UBool localized,
const UChar *pattern,
int32_t patternLength
);
/**
* Set the pattern used by an UNumberFormat.
* The pattern should follow the pattern syntax rules.
* @param fmt The formatter to set.
* @param localized TRUE if the pattern is localized, FALSE otherwise.
* @param pattern The new pattern
* @param parseError A pointer to UParseError to recieve information about errors
* occurred during parsing.
* @param patternLength The length of pattern, or -1 if null-terminated.
* @see unum_toPattern
* @draft
*/
U_CAPI void
unum_applyPattern( UNumberFormat *format,
UBool localized,
const UChar *pattern,
int32_t patternLength);
int32_t patternLength,
UParseError *parseError,
UErrorCode *status
);
/**
* Get a locale for which number formatting patterns are available.
* A UNumberFormat in a locale returned by this function will perform the correct
@ -694,4 +744,20 @@ unum_setSymbol(UNumberFormat *fmt,
int32_t length,
UErrorCode *status);
/******************* Deprecated API ***************************/
#ifdef U_USE_DEPRECATED_FORMAT_API
static UNumberFormat*
unum_openPattern(UChar* pattern, int32_t patternLength,char* locale,UErrorCode* status)
{
return unum_open(0,pattern,patternLength,locale,NULL,status);
}
#define unum_open_1_9(style,locale,status) unum_open(style, NULL, 0, locale, NULL, status)
#define unum_applyPattern_1_9(format,localized,pattern,patternLength) unum_applyPattern(format,localized,pattern,patternLength,NULL,NULL)
#endif
/******************** End ************************************/
#endif