]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/dtptngen_impl.h
ICU-59180.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / dtptngen_impl.h
index 0cfa88ab4d437ab20224515b8d5eba2ed2d4c1a5..38afd5ff5a8d7fc2086d21a3982b100afcef9e63 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 * Copyright (C) 2007-2016, International Business Machines Corporation and
@@ -13,6 +15,9 @@
 #define __DTPTNGEN_IMPL_H__
 
 #include "unicode/udatpg.h"
+
+#include "unicode/strenum.h"
+#include "unicode/unistr.h"
 #include "uvector.h"
 
 // TODO(claireho): Split off Builder class.
@@ -112,17 +117,56 @@ typedef struct dtTypeElem {
     int16_t                weight;
 }dtTypeElem;
 
+// A compact storage mechanism for skeleton field strings.  Several dozen of these will be created
+// for a typical DateTimePatternGenerator instance.
+class SkeletonFields : public UMemory {
+public:
+    SkeletonFields();
+    void clear();
+    void copyFrom(const SkeletonFields& other);
+    void clearField(int32_t field);
+    UChar getFieldChar(int32_t field) const;
+    int32_t getFieldLength(int32_t field) const;
+    void populate(int32_t field, const UnicodeString& value);
+    void populate(int32_t field, UChar repeatChar, int32_t repeatCount);
+    UBool isFieldEmpty(int32_t field) const;
+    UnicodeString& appendTo(UnicodeString& string) const;
+    UnicodeString& appendFieldTo(int32_t field, UnicodeString& string) const;
+    UChar getFirstChar() const;
+    inline UBool operator==(const SkeletonFields& other) const;
+    inline UBool operator!=(const SkeletonFields& other) const;
+
+private:
+    int8_t chars[UDATPG_FIELD_COUNT];
+    int8_t lengths[UDATPG_FIELD_COUNT];
+};
+
+inline UBool SkeletonFields::operator==(const SkeletonFields& other) const {
+    return (uprv_memcmp(chars, other.chars, sizeof(chars)) == 0
+        && uprv_memcmp(lengths, other.lengths, sizeof(lengths)) == 0);
+}
+
+inline UBool SkeletonFields::operator!=(const SkeletonFields& other) const {
+    return (! operator==(other));
+}
+
 class PtnSkeleton : public UMemory {
 public:
     int32_t type[UDATPG_FIELD_COUNT];
-    UnicodeString original[UDATPG_FIELD_COUNT];
-    UnicodeString baseOriginal[UDATPG_FIELD_COUNT];
+    SkeletonFields original;
+    SkeletonFields baseOriginal;
 
     PtnSkeleton();
     PtnSkeleton(const PtnSkeleton& other);
-    UBool equals(const PtnSkeleton& other);
-    UnicodeString getSkeleton();
-    UnicodeString getBaseSkeleton();
+    void copyFrom(const PtnSkeleton& other);
+    void clear();
+    UBool equals(const PtnSkeleton& other) const;
+    UnicodeString getSkeleton() const;
+    UnicodeString getBaseSkeleton() const;
+    UChar getFirstChar() const;
+
+    // TODO: Why is this virtual, as well as the other destructors in this file? We don't want
+    // vtables when we don't use class objects polymorphically.
     virtual ~PtnSkeleton();
 };
 
@@ -183,7 +227,7 @@ class DateTimeMatcher: public UMemory {
 public:
     PtnSkeleton skeleton;
 
-    void getBasePattern(UnicodeString &basePattern);
+    void getBasePattern(UnicodeStringbasePattern);
     UnicodeString getPattern();
     void set(const UnicodeString& pattern, FormatParser* fp);
     void set(const UnicodeString& pattern, FormatParser* fp, PtnSkeleton& skeleton);