ICU 78.1  78.1
dtitvinf.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  * Copyright (C) 2008-2016, International Business Machines Corporation and
6  * others. All Rights Reserved.
7  *******************************************************************************
8  *
9  * File DTITVINF.H
10  *
11  *******************************************************************************
12  */
13 
14 #ifndef __DTITVINF_H__
15 #define __DTITVINF_H__
16 
17 #include "unicode/utypes.h"
18 
19 #if U_SHOW_CPLUSPLUS_API
20 
26 #if !UCONFIG_NO_FORMATTING
27 
28 #include "unicode/udat.h"
29 #include "unicode/locid.h"
30 #include "unicode/ucal.h"
31 #include "unicode/dtptngen.h"
32 
33 U_NAMESPACE_BEGIN
34 
154 class U_I18N_API DateIntervalInfo final : public UObject {
155 public:
170 
171 
179  DateIntervalInfo(const Locale& locale, UErrorCode& status);
180 
181 
187 
193 
201 
207 
208 
216  bool operator==(const DateIntervalInfo& other) const;
217 
225  bool operator!=(const DateIntervalInfo& other) const;
226 
227 
228 
261  void setIntervalPattern(const UnicodeString& skeleton,
262  UCalendarDateFields lrgDiffCalUnit,
263  const UnicodeString& intervalPattern,
264  UErrorCode& status);
265 
277  UCalendarDateFields field,
278  UnicodeString& result,
279  UErrorCode& status) const;
280 
288 
289 
303  void setFallbackIntervalPattern(const UnicodeString& fallbackPattern,
304  UErrorCode& status);
305 
306 
314 
315 
321  virtual UClassID getDynamicClassID() const override;
322 
328  static UClassID U_EXPORT2 getStaticClassID();
329 
330 
331 private:
340  friend class DateIntervalFormat;
341 
345  struct U_HIDDEN DateIntervalSink;
346 
352  enum IntervalPatternIndex
353  {
354  kIPI_ERA,
355  kIPI_YEAR,
356  kIPI_MONTH,
357  kIPI_DATE,
358  kIPI_AM_PM,
359  kIPI_HOUR,
360  kIPI_MINUTE,
361  kIPI_SECOND,
362  kIPI_MILLISECOND,
363  kIPI_MAX_INDEX
364  };
365 public:
366 #ifndef U_HIDE_INTERNAL_API
371  enum {
372  kMaxIntervalPatternIndex = kIPI_MAX_INDEX
373  };
374 #endif /* U_HIDE_INTERNAL_API */
375 private:
376 
377 
383  void initializeData(const Locale& locale, UErrorCode& status);
384 
385 
386  /* Set Interval pattern.
387  *
388  * It sets interval pattern into the hash map.
389  *
390  * @param skeleton skeleton on which the interval pattern based
391  * @param lrgDiffCalUnit the largest different calendar unit.
392  * @param intervalPattern the interval pattern on the largest different
393  * calendar unit.
394  * @param status output param set to success/failure code on exit
395  */
396  void setIntervalPatternInternally(const UnicodeString& skeleton,
397  UCalendarDateFields lrgDiffCalUnit,
398  const UnicodeString& intervalPattern,
399  UErrorCode& status);
400 
401 
420  const UnicodeString* getBestSkeleton(const UnicodeString& skeleton,
421  int8_t& bestMatchDistanceInfo) const;
422 
423 
431  static void U_EXPORT2 parseSkeleton(const UnicodeString& skeleton,
432  int32_t* skeletonFieldWidth);
433 
434 
446  static UBool U_EXPORT2 stringNumeric(int32_t fieldWidth,
447  int32_t anotherFieldWidth,
448  char patternLetter);
449 
450 
464  static IntervalPatternIndex U_EXPORT2 calendarFieldToIntervalIndex(
465  UCalendarDateFields field,
466  UErrorCode& status);
467 
468 
474  void deleteHash(Hashtable* hTable);
475 
476 
483  Hashtable* initHash(UErrorCode& status);
484 
485 
486 
494  void copyHash(const Hashtable* source, Hashtable* target, UErrorCode& status);
495 
496 
497  // data members
498  // fallback interval pattern
499  UnicodeString fFallbackIntervalPattern;
500  // default order
501  UBool fFirstDateInPtnIsLaterDate;
502 
503  // HashMap<UnicodeString, UnicodeString[kIPI_MAX_INDEX]>
504  // HashMap( skeleton, pattern[largest_different_field] )
505  Hashtable* fIntervalPatterns;
506 
507 };// end class DateIntervalInfo
508 
509 
510 inline bool
512  return !operator==(other);
513 }
514 
515 
516 U_NAMESPACE_END
517 
518 #endif
519 
520 #endif /* U_SHOW_CPLUSPLUS_API */
521 
522 #endif
523 
DateIntervalFormat is a class for formatting and parsing date intervals in a language-independent man...
Definition: dtitvfmt.h:300
DateIntervalInfo is a public class for encapsulating localizable date time interval patterns.
Definition: dtitvinf.h:154
void setIntervalPattern(const UnicodeString &skeleton, UCalendarDateFields lrgDiffCalUnit, const UnicodeString &intervalPattern, UErrorCode &status)
Provides a way for client to build interval patterns.
DateIntervalInfo * clone() const
Clone this object polymorphically.
bool operator==(const DateIntervalInfo &other) const
Return true if another object is semantically equal to this one.
UnicodeString & getIntervalPattern(const UnicodeString &skeleton, UCalendarDateFields field, UnicodeString &result, UErrorCode &status) const
Get the interval pattern given skeleton and the largest different calendar field.
UBool getDefaultOrder() const
Get default order – whether the first date in pattern is later date or not.
DateIntervalInfo & operator=(const DateIntervalInfo &)
Assignment operator.
void setFallbackIntervalPattern(const UnicodeString &fallbackPattern, UErrorCode &status)
Re-set the fallback interval pattern.
DateIntervalInfo(const DateIntervalInfo &)
Copy constructor.
DateIntervalInfo(const Locale &locale, UErrorCode &status)
Construct DateIntervalInfo for the given locale,.
~DateIntervalInfo()
Destructor.
static UClassID getStaticClassID()
ICU "poor man's RTTI", returns a UClassID for this class.
virtual UClassID getDynamicClassID() const override
ICU "poor man's RTTI", returns a UClassID for the actual class.
DateIntervalInfo(UErrorCode &status)
Default constructor.
UnicodeString & getFallbackIntervalPattern(UnicodeString &result) const
Get the fallback interval pattern.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:303
C++ API: Date/Time Pattern Generator.
C++ API: Locale ID object.
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
bool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:346
#define U_HIDDEN
This is used to mark internal structs declared within external classes, to prevent the internal struc...
Definition: platform.h:814
C API: Calendar.
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
C API: DateFormat.
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316