1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
/*
*****************************************************************************************
* Copyright (C) 2014 Apple Inc. All Rights Reserved.
*****************************************************************************************
*/
#ifndef UATIMEUNITFORMAT_H
#define UATIMEUNITFORMAT_H
#include <_foundation_unicode/utypes.h>
#if !UCONFIG_NO_FORMATTING
#ifndef U_HIDE_DRAFT_API
#include <_foundation_unicode/localpointer.h>
#include <_foundation_unicode/unum.h>
/**
* \file
* \brief C API: Support functions for formatting time units or portions thereof.
*
* These are somewhat temporary Apple-only functions to support NSDateComponentsFormatter.
*/
/**
* Opaque UATimeUnitFormat object for use in C programs.
* @draft ICU 53
*/
struct UATimeUnitFormat;
typedef struct UATimeUnitFormat UATimeUnitFormat; /**< C typedef for struct UATimeUnitFormat. @draft ICU 53 */
/**
* TimeUnit format styles
* @draft ICU 53
*/
typedef enum UATimeUnitStyle {
/**
* full style, e.g. "1.0 minutes"
* @draft ICU 53 */
UATIMEUNITSTYLE_FULL,
/**
* abbreviated/short style, e.g. "1.0 min"
* @draft ICU 53 */
UATIMEUNITSTYLE_ABBREVIATED,
/**
* narrow style, e.g. "1.0 m"
* @draft ICU 53 */
UATIMEUNITSTYLE_NARROW,
/**
* shorter style,between abbreviated and narrow"
* @draft ICU 57 */
UATIMEUNITSTYLE_SHORTER,
/** @draft ICU 53 */
UATIMEUNITSTYLE_COUNT
} UATimeUnitStyle;
/**
* TimeUnit fields
* @draft ICU 53
*/
typedef enum UATimeUnitField {
/** @draft ICU 53 */
UATIMEUNITFIELD_YEAR,
/** @draft ICU 53 */
UATIMEUNITFIELD_MONTH,
/** @draft ICU 53 */
UATIMEUNITFIELD_DAY,
/** @draft ICU 53 */
UATIMEUNITFIELD_WEEK,
/** @draft ICU 53 */
UATIMEUNITFIELD_HOUR,
/** @draft ICU 53 */
UATIMEUNITFIELD_MINUTE,
/** @draft ICU 53 */
UATIMEUNITFIELD_SECOND,
/** @draft ICU 63 */
UATIMEUNITFIELD_MILLISECOND,
/** @draft ICU 63 */
UATIMEUNITFIELD_MICROSECOND,
/** @draft ICU 63 */
UATIMEUNITFIELD_NANOSECOND,
#ifndef U_HIDE_DEPRECATED_API
/** @deprecated The numeric value may change over time */
UATIMEUNITFIELD_COUNT
#endif /* U_HIDE_DEPRECATED_API */
} UATimeUnitField;
/**
* Open a new UATimeUnitFormat object for a given locale using the specified style,
* using the default decimal formatter.
* @param locale
* The locale
* @param style
* The style (width) - full, abbreviated, etc.
* @param status
* A pointer to a UErrorCode to receive any errors.
* @return
* A pointer to a UATimeUnitFormat object for the specified locale,
* or NULL if an error occurred.
* @draft ICU 53
*/
U_DRAFT UATimeUnitFormat* U_EXPORT2
uatmufmt_open(const char* locale,
UATimeUnitStyle style,
UErrorCode* status);
/**
* Open a new UATimeUnitFormat object for a given locale using the specified style,
* along with the number formatter to use for the numeric part of the time unit,
* e.g. "1 min", "1.0 min", etc.
* @param locale
* The locale
* @param style
* The style (width) - full, abbreviated, etc.
* @param nfToAdopt
* A number formatter to set for this UATimeUnitFormat object (instead of
* the default decimal formatter). Ownership of this UNumberFormat object
* will pass to the UATimeUnitFormat object (the UATimeUnitFormat adopts the
* UNumberFormat), which becomes responsible for closing it. If the caller
* wishes to retain ownership of the UNumberFormat object, the caller must
* clone it (with unum_clone) and pass the clone to
* uatmufmt_openWithNumberFormat. May be NULL to use the default decimal
* formatter.
* @param status
* A pointer to a UErrorCode to receive any errors.
* @return
* A pointer to a UATimeUnitFormat object for the specified locale,
* or NULL if an error occurred.
* @draft ICU 53
*/
U_DRAFT UATimeUnitFormat* U_EXPORT2
uatmufmt_openWithNumberFormat(const char* locale,
UATimeUnitStyle style,
UNumberFormat* nfToAdopt,
UErrorCode* status);
/**
* Close a UATimeUnitFormat object. Once closed it may no longer be used.
* @param tufmt
* The UATimeUnitFormat object to close.
* @draft ICU 53
*/
U_DRAFT void U_EXPORT2
uatmufmt_close(UATimeUnitFormat *tufmt);
#if U_SHOW_CPLUSPLUS_API
U_NAMESPACE_BEGIN
/**
* \class LocalUDateIntervalFormatPointer
* "Smart pointer" class, closes a UATimeUnitFormat via uatmufmt_close().
* For most methods see the LocalPointerBase base class.
*
* @see LocalPointerBase
* @see LocalPointer
* @draft ICU 53
*/
U_DEFINE_LOCAL_OPEN_POINTER(LocalUATimeUnitFormatPointer, UATimeUnitFormat, uatmufmt_close);
U_NAMESPACE_END
#endif // U_SHOW_CPLUSPLUS_API
/**
* Set the number formatter to use for the numeric part of the time unit,
* e.g. "1 min", "1.0 min", etc.
* DO NOT USE - use uatmufmt_openWithNumberFormat instead, this will be
* removed soon.
* @param tufmt
* The UATimeUnitFormat object specifying the format conventions.
* @param numfmt
* The number formatter to set for this UATimeUnitFormat object;
* uatmufmt_setNumberFormat clones this for its own use, so the
* caller retains ownership of the passed-in UNumberFormat object.
* @param status
* A pointer to a UErrorCode to receive any errors.
* @deprecated ICU 53, use uatmufmt_openWithNumberFormat
*/
U_DEPRECATED void U_EXPORT2
uatmufmt_setNumberFormat(UATimeUnitFormat* tufmt,
UNumberFormat* numfmt,
UErrorCode* status);
/**
* Format a value like 1.0 and a field like UATIMEUNIT_MINUTE to e.g. "1.0 minutes".
* @param tufmt
* The UATimeUnitFormat object specifying the format conventions.
* @param value
* The numeric value to format
* @param field
* The time field to format with the specified numeric value
* @param result
* A pointer to a buffer to receive the formatted result.
* @param resultCapacity
* The maximum size of result.
* @param status
* A pointer to a UErrorCode to receive any errors. In case of error status,
* the contents of result are undefined.
* @return
* The length of the formatted result; may be greater than resultCapacity,
* in which case an error is returned.
* @draft ICU 53
*/
U_DRAFT int32_t U_EXPORT2
uatmufmt_format(const UATimeUnitFormat* tufmt,
double value,
UATimeUnitField field,
UChar* result,
int32_t resultCapacity,
UErrorCode* status);
/**
* Parse a single formatted time unit like "1.0 minutes" into a numeric value and unit type.
* NOT CURRENTLY SUPPORTED, sets status to U_UNSUPPORTED_ERROR and returns 0.0.
* @param tufmt
* The UATimeUnitFormat object specifying the format conventions.
* @param text
* The text to parse
* @param textLength
* The length of text, or -1 if null-terminated
* @param parsePos
* A pointer to an offset index into text at which to begin parsing. On output,
* *parsePos will point after the last parsed character. This parameter may be
* NULL, in which case parsing begins at offset 0.
* @param field
* A pointer to a UATimeUnitField to be set to the parsed firled type.
* @param status
* A pointer to a UErrorCode to receive any errors.
* @return
* The parsed double value.
* @draft ICU 53
*/
U_DRAFT double U_EXPORT2
uatmufmt_parse( const UATimeUnitFormat* tufmt,
const UChar* text,
int32_t textLength,
int32_t* parsePos,
UATimeUnitField* field,
UErrorCode* status);
/**
* TimeUnit time duration positional pattern types
* @draft ICU 53
*/
typedef enum UATimeUnitTimePattern {
/**
* e.g. "h:mm"
* @draft ICU 53 */
UATIMEUNITTIMEPAT_HM,
/**
* e.g. "h:mm:ss"
* @draft ICU 53 */
UATIMEUNITTIMEPAT_HMS,
/**
* e.g. "m:ss"
* @draft ICU 53 */
UATIMEUNITTIMEPAT_MS,
/** @draft ICU 53 */
UATIMEUNITTIMEPAT_COUNT
} UATimeUnitTimePattern;
/**
* Get a localized pattern for positional duration style, e.g. "h:mm:ss".
* This comes from the durationUnits CLDR data in ICU, e.g.
* durationUnits{
* hm{"h:mm"}
* hms{"h:mm:ss"}
* ms{"m:ss"}
* }
* For usage see CLDR documentation on durationUnit under
* <a href="http://www.unicode.org/reports/tr35/tr35-general.html#Unit_Elements">Unit Elements</a>.
*
* @param locale
* The locale
* @param type
* The type of time pattern to get (hm, hms, ms)
* @param result
* A pointer to a buffer to receive the formatted result.
* @param resultCapacity
* The maximum size of result.
* @param status
* A pointer to a UErrorCode to receive any errors. In case of error status,
* the contents of result are undefined.
* @return
* The length of the formatted result; may be greater than resultCapacity,
* in which case an error is returned.
* @draft ICU 53
*/
U_DRAFT int32_t U_EXPORT2
uatmufmt_getTimePattern(const char* locale,
UATimeUnitTimePattern type,
UChar* result,
int32_t resultCapacity,
UErrorCode* status);
/**
* TimeUnit list pattern types
* @draft ICU 53
*/
typedef enum UATimeUnitListPattern {
/**
* for two only, e.g. "{0} and {1}"
* @draft ICU 53 */
UATIMEUNITLISTPAT_TWO_ONLY,
/**
* for end of list with 3 or more, e.g. "{0}, and {1}"
* @draft ICU 53 */
UATIMEUNITLISTPAT_END_PIECE,
/**
* for middle of list with 3 or more, e.g. "{0}, {1}"
* @draft ICU 53 */
UATIMEUNITLISTPAT_MIDDLE_PIECE,
/**
* for start of list with 3 or more, e.g. "{0}, {1}"
* @draft ICU 53 */
UATIMEUNITLISTPAT_START_PIECE,
/** @draft ICU 53 */
UATIMEUNITLISTPAT_COUNT
} UATimeUnitListPattern;
/**
* Get a localized pattern for combining units in a list, e.g. "3 min, 42 sec".
* This comes from the listPattern/unit* CLDR data in ICU, e.g.
* listPattern{
* unit{
* .. use short if not present
* }
* unit-short{
* 2{"{0}, {1}"}
* end{"{0}, {1}"}
* middle{"{0}, {1}"}
* start{"{0}, {1}"}
* }
* unit-narrow{
* .. use short if not present
* }
* }
* For usage see CLDR documentation on
* <a href="http://www.unicode.org/reports/tr35/tr35-general.html#ListPatterns">List Patterns</a>.
*
* @param locale
* The locale
* @param style
* The style (width) - full, abbreviated, etc.
* @param type
* The type of list pattern to get (for two items, end part for >= 3 items, etc.)
* @param result
* A pointer to a buffer to receive the formatted result.
* @param resultCapacity
* The maximum size of result.
* @param status
* A pointer to a UErrorCode to receive any errors. In case of error status,
* the contents of result are undefined.
* @return
* The length of the formatted result; may be greater than resultCapacity,
* in which case an error is returned.
* @draft ICU 53
*/
U_DRAFT int32_t U_EXPORT2
uatmufmt_getListPattern(const char* locale,
UATimeUnitStyle style,
UATimeUnitListPattern type,
UChar* result,
int32_t resultCapacity,
UErrorCode* status);
#endif /* U_HIDE_DRAFT_API */
#endif /* #if !UCONFIG_NO_FORMATTING */
#endif /* #ifndef UATIMEUNITFORMAT_H */
|