]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/udatpg.cpp
ICU-64243.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / udatpg.cpp
index 02a843a32fd024911cac1d0625fc376d20a14b16..0c5342a15cdca9a21a10e4d885a70431cb07704a 100644 (file)
@@ -1,12 +1,14 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2009-2012,2014 International Business Machines
+*   Copyright (C) 2009-2015, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
 *   file name:  udatpg.cpp
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -85,7 +87,7 @@ udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
 }
 
 U_CAPI int32_t U_EXPORT2
-udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
+udatpg_getSkeleton(UDateTimePatternGenerator * /* dtpg */,
                    const UChar *pattern, int32_t length,
                    UChar *skeleton, int32_t capacity,
                    UErrorCode *pErrorCode) {
@@ -97,12 +99,13 @@ udatpg_getSkeleton(UDateTimePatternGenerator *dtpg,
         return 0;
     }
     UnicodeString patternString((UBool)(length<0), pattern, length);
-    UnicodeString result=((DateTimePatternGenerator *)dtpg)->getSkeleton(patternString, *pErrorCode);
+    UnicodeString result=DateTimePatternGenerator::staticGetSkeleton(
+            patternString, *pErrorCode);
     return result.extract(skeleton, capacity, *pErrorCode);
 }
 
 U_CAPI int32_t U_EXPORT2
-udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
+udatpg_getBaseSkeleton(UDateTimePatternGenerator * /* dtpg */,
                        const UChar *pattern, int32_t length,
                        UChar *skeleton, int32_t capacity,
                        UErrorCode *pErrorCode) {
@@ -114,7 +117,8 @@ udatpg_getBaseSkeleton(UDateTimePatternGenerator *dtpg,
         return 0;
     }
     UnicodeString patternString((UBool)(length<0), pattern, length);
-    UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBaseSkeleton(patternString, *pErrorCode);
+    UnicodeString result=DateTimePatternGenerator::staticGetBaseSkeleton(
+            patternString, *pErrorCode);
     return result.extract(skeleton, capacity, *pErrorCode);
 }
 
@@ -180,6 +184,25 @@ udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
     return result.getBuffer();
 }
 
+U_CAPI int32_t U_EXPORT2
+udatpg_getFieldDisplayName(const UDateTimePatternGenerator *dtpg,
+                           UDateTimePatternField field,
+                           UDateTimePGDisplayWidth width,
+                           UChar *fieldName, int32_t capacity,
+                           UErrorCode *pErrorCode) {
+    if (U_FAILURE(*pErrorCode))
+        return -1;
+    if (fieldName == NULL ? capacity != 0 : capacity < 0) {
+        *pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
+        return -1;
+    }
+    UnicodeString result = ((const DateTimePatternGenerator *)dtpg)->getFieldDisplayName(field,width);
+    if (fieldName == NULL) {
+        return result.length();
+    }
+    return result.extract(fieldName, capacity, *pErrorCode);
+}
+
 U_CAPI void U_EXPORT2
 udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
                          const UChar *dtFormat, int32_t length) {
@@ -284,7 +307,7 @@ _doReplaceAndReturnAdj( UDateTimePatternGenerator *dtpg, uint32_t options, UBool
     if (U_FAILURE(*pErrorCode)) {
         return 0;
     }
-    UnicodeString stringForOrigSkeleton=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeleton, (UDateTimePatternMatchOptions)options, *pErrorCode);
+    UnicodeString stringForOrigSkeleton=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeleton, UDATPG_MATCH_ALL_FIELDS_LENGTH, *pErrorCode); // match orig field lengths
     if (U_SUCCESS(*pErrorCode)) {
         int32_t index = patternString.indexOf(stringForOrigSkeleton);
         if (index >= 0) {
@@ -373,7 +396,7 @@ uadatpg_remapPatternWithOptions(UDateTimePatternGenerator *dtpg,
         int32_t timeNonHourStart = -1;
         int32_t timeNonHourLimit = 0;
         UnicodeString skeleton, otherCycSkeleton;
-        UnicodeString timePatChars(":ahHKkmsSzZOvVXx", -1, US_INV); // all pattern chars for times
+        UnicodeString timePatChars("abBhHKkmsSzZOvVXx", -1, US_INV); // all pattern chars for times
         int32_t numForcedH = 0;
         int32_t patPos, patLen = patternString.length();
 
@@ -437,7 +460,7 @@ uadatpg_remapPatternWithOptions(UDateTimePatternGenerator *dtpg,
                 }
                 if (inTimePat && !u_isWhitespace(patChr)) {
                     timePatLimit = patPos + 1;
-                    if (timeNonHourStart >= 0 && patChr!=LOW_A) { // NonHour portion should not include 'a'
+                    if (timeNonHourStart >= 0 && patChr!=LOW_A && patChr!=LOW_B && patChr!=CAP_B) { // NonHour portion should not include 'a','b','B'
                         timeNonHourLimit = timePatLimit;
                     }
                 }