LCOV - code coverage report
Current view: top level - intl/icu/source/i18n - udatpg.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 115 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // © 2016 and later: Unicode, Inc. and others.
       2             : // License & terms of use: http://www.unicode.org/copyright.html
       3             : /*
       4             : *******************************************************************************
       5             : *
       6             : *   Copyright (C) 2009-2015, International Business Machines
       7             : *   Corporation and others.  All Rights Reserved.
       8             : *
       9             : *******************************************************************************
      10             : *   file name:  udatpg.cpp
      11             : *   encoding:   UTF-8
      12             : *   tab size:   8 (not used)
      13             : *   indentation:4
      14             : *
      15             : *   created on: 2007jul30
      16             : *   created by: Markus W. Scherer
      17             : */
      18             : 
      19             : #include "unicode/utypes.h"
      20             : 
      21             : #if !UCONFIG_NO_FORMATTING
      22             : 
      23             : #include "unicode/udatpg.h"
      24             : #include "unicode/uenum.h"
      25             : #include "unicode/strenum.h"
      26             : #include "unicode/dtptngen.h"
      27             : #include "ustrenum.h"
      28             : 
      29             : U_NAMESPACE_USE
      30             : 
      31             : U_CAPI UDateTimePatternGenerator * U_EXPORT2
      32           0 : udatpg_open(const char *locale, UErrorCode *pErrorCode) {
      33           0 :     if(locale==NULL) {
      34           0 :         return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(*pErrorCode);
      35             :     } else {
      36           0 :         return (UDateTimePatternGenerator *)DateTimePatternGenerator::createInstance(Locale(locale), *pErrorCode);
      37             :     }
      38             : }
      39             : 
      40             : U_CAPI UDateTimePatternGenerator * U_EXPORT2
      41           0 : udatpg_openEmpty(UErrorCode *pErrorCode) {
      42           0 :     return (UDateTimePatternGenerator *)DateTimePatternGenerator::createEmptyInstance(*pErrorCode);
      43             : }
      44             : 
      45             : U_CAPI void U_EXPORT2
      46           0 : udatpg_close(UDateTimePatternGenerator *dtpg) {
      47           0 :     delete (DateTimePatternGenerator *)dtpg;
      48           0 : }
      49             : 
      50             : U_CAPI UDateTimePatternGenerator * U_EXPORT2
      51           0 : udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
      52           0 :     if(U_FAILURE(*pErrorCode)) {
      53           0 :         return NULL;
      54             :     }
      55           0 :     return (UDateTimePatternGenerator *)(((const DateTimePatternGenerator *)dtpg)->clone());
      56             : }
      57             : 
      58             : U_CAPI int32_t U_EXPORT2
      59           0 : udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
      60             :                       const UChar *skeleton, int32_t length,
      61             :                       UChar *bestPattern, int32_t capacity,
      62             :                       UErrorCode *pErrorCode) {
      63             :     return udatpg_getBestPatternWithOptions(dtpg, skeleton, length,
      64             :                                             UDATPG_MATCH_NO_OPTIONS,
      65           0 :                                             bestPattern, capacity, pErrorCode);
      66             : }
      67             : 
      68             : U_CAPI int32_t U_EXPORT2
      69           0 : udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
      70             :                                  const UChar *skeleton, int32_t length,
      71             :                                  UDateTimePatternMatchOptions options,
      72             :                                  UChar *bestPattern, int32_t capacity,
      73             :                                  UErrorCode *pErrorCode) {
      74           0 :     if(U_FAILURE(*pErrorCode)) {
      75           0 :         return 0;
      76             :     }
      77           0 :     if(skeleton==NULL && length!=0) {
      78           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
      79           0 :         return 0;
      80             :     }
      81           0 :     UnicodeString skeletonString((UBool)(length<0), skeleton, length);
      82           0 :     UnicodeString result=((DateTimePatternGenerator *)dtpg)->getBestPattern(skeletonString, options, *pErrorCode);
      83           0 :     return result.extract(bestPattern, capacity, *pErrorCode);
      84             : }
      85             : 
      86             : U_CAPI int32_t U_EXPORT2
      87           0 : udatpg_getSkeleton(UDateTimePatternGenerator * /* dtpg */,
      88             :                    const UChar *pattern, int32_t length,
      89             :                    UChar *skeleton, int32_t capacity,
      90             :                    UErrorCode *pErrorCode) {
      91           0 :     if(U_FAILURE(*pErrorCode)) {
      92           0 :         return 0;
      93             :     }
      94           0 :     if(pattern==NULL && length!=0) {
      95           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
      96           0 :         return 0;
      97             :     }
      98           0 :     UnicodeString patternString((UBool)(length<0), pattern, length);
      99             :     UnicodeString result=DateTimePatternGenerator::staticGetSkeleton(
     100           0 :             patternString, *pErrorCode);
     101           0 :     return result.extract(skeleton, capacity, *pErrorCode);
     102             : }
     103             : 
     104             : U_CAPI int32_t U_EXPORT2
     105           0 : udatpg_getBaseSkeleton(UDateTimePatternGenerator * /* dtpg */,
     106             :                        const UChar *pattern, int32_t length,
     107             :                        UChar *skeleton, int32_t capacity,
     108             :                        UErrorCode *pErrorCode) {
     109           0 :     if(U_FAILURE(*pErrorCode)) {
     110           0 :         return 0;
     111             :     }
     112           0 :     if(pattern==NULL && length!=0) {
     113           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
     114           0 :         return 0;
     115             :     }
     116           0 :     UnicodeString patternString((UBool)(length<0), pattern, length);
     117             :     UnicodeString result=DateTimePatternGenerator::staticGetBaseSkeleton(
     118           0 :             patternString, *pErrorCode);
     119           0 :     return result.extract(skeleton, capacity, *pErrorCode);
     120             : }
     121             : 
     122             : U_CAPI UDateTimePatternConflict U_EXPORT2
     123           0 : udatpg_addPattern(UDateTimePatternGenerator *dtpg,
     124             :                   const UChar *pattern, int32_t patternLength,
     125             :                   UBool override,
     126             :                   UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
     127             :                   UErrorCode *pErrorCode) {
     128           0 :     if(U_FAILURE(*pErrorCode)) {
     129           0 :         return UDATPG_NO_CONFLICT;
     130             :     }
     131           0 :     if(pattern==NULL && patternLength!=0) {
     132           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
     133           0 :         return UDATPG_NO_CONFLICT;
     134             :     }
     135           0 :     UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
     136           0 :     UnicodeString conflictingPatternString;
     137             :     UDateTimePatternConflict result=((DateTimePatternGenerator *)dtpg)->
     138           0 :             addPattern(patternString, override, conflictingPatternString, *pErrorCode);
     139           0 :     int32_t length=conflictingPatternString.extract(conflictingPattern, capacity, *pErrorCode);
     140           0 :     if(pLength!=NULL) {
     141           0 :         *pLength=length;
     142             :     }
     143           0 :     return result;
     144             : }
     145             : 
     146             : U_CAPI void U_EXPORT2
     147           0 : udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
     148             :                            UDateTimePatternField field,
     149             :                            const UChar *value, int32_t length) {
     150           0 :     UnicodeString valueString((UBool)(length<0), value, length);
     151           0 :     ((DateTimePatternGenerator *)dtpg)->setAppendItemFormat(field, valueString);
     152           0 : }
     153             : 
     154             : U_CAPI const UChar * U_EXPORT2
     155           0 : udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
     156             :                            UDateTimePatternField field,
     157             :                            int32_t *pLength) {
     158           0 :     const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemFormat(field);
     159           0 :     if(pLength!=NULL) {
     160           0 :         *pLength=result.length();
     161             :     }
     162           0 :     return result.getBuffer();
     163             : }
     164             : 
     165             : U_CAPI void U_EXPORT2
     166           0 : udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
     167             :                          UDateTimePatternField field,
     168             :                          const UChar *value, int32_t length) {
     169           0 :     UnicodeString valueString((UBool)(length<0), value, length);
     170           0 :     ((DateTimePatternGenerator *)dtpg)->setAppendItemName(field, valueString);
     171           0 : }
     172             : 
     173             : U_CAPI const UChar * U_EXPORT2
     174           0 : udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
     175             :                          UDateTimePatternField field,
     176             :                          int32_t *pLength) {
     177           0 :     const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getAppendItemName(field);
     178           0 :     if(pLength!=NULL) {
     179           0 :         *pLength=result.length();
     180             :     }
     181           0 :     return result.getBuffer();
     182             : }
     183             : 
     184             : U_CAPI void U_EXPORT2
     185           0 : udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
     186             :                          const UChar *dtFormat, int32_t length) {
     187           0 :     UnicodeString dtFormatString((UBool)(length<0), dtFormat, length);
     188           0 :     ((DateTimePatternGenerator *)dtpg)->setDateTimeFormat(dtFormatString);
     189           0 : }
     190             : 
     191             : U_CAPI const UChar * U_EXPORT2
     192           0 : udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
     193             :                          int32_t *pLength) {
     194           0 :     const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDateTimeFormat();
     195           0 :     if(pLength!=NULL) {
     196           0 :         *pLength=result.length();
     197             :     }
     198           0 :     return result.getBuffer();
     199             : }
     200             : 
     201             : U_CAPI void U_EXPORT2
     202           0 : udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
     203             :                   const UChar *decimal, int32_t length) {
     204           0 :     UnicodeString decimalString((UBool)(length<0), decimal, length);
     205           0 :     ((DateTimePatternGenerator *)dtpg)->setDecimal(decimalString);
     206           0 : }
     207             : 
     208             : U_CAPI const UChar * U_EXPORT2
     209           0 : udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
     210             :                   int32_t *pLength) {
     211           0 :     const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getDecimal();
     212           0 :     if(pLength!=NULL) {
     213           0 :         *pLength=result.length();
     214             :     }
     215           0 :     return result.getBuffer();
     216             : }
     217             : 
     218             : U_CAPI int32_t U_EXPORT2
     219           0 : udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
     220             :                          const UChar *pattern, int32_t patternLength,
     221             :                          const UChar *skeleton, int32_t skeletonLength,
     222             :                          UChar *dest, int32_t destCapacity,
     223             :                          UErrorCode *pErrorCode) {
     224             :     return udatpg_replaceFieldTypesWithOptions(dtpg, pattern, patternLength, skeleton, skeletonLength,
     225             :                                                UDATPG_MATCH_NO_OPTIONS,
     226           0 :                                                dest, destCapacity, pErrorCode);
     227             : }
     228             : 
     229             : U_CAPI int32_t U_EXPORT2
     230           0 : udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg,
     231             :                                     const UChar *pattern, int32_t patternLength,
     232             :                                     const UChar *skeleton, int32_t skeletonLength,
     233             :                                     UDateTimePatternMatchOptions options,
     234             :                                     UChar *dest, int32_t destCapacity,
     235             :                                     UErrorCode *pErrorCode) {
     236           0 :     if(U_FAILURE(*pErrorCode)) {
     237           0 :         return 0;
     238             :     }
     239           0 :     if((pattern==NULL && patternLength!=0) || (skeleton==NULL && skeletonLength!=0)) {
     240           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
     241           0 :         return 0;
     242             :     }
     243           0 :     UnicodeString patternString((UBool)(patternLength<0), pattern, patternLength);
     244           0 :     UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
     245           0 :     UnicodeString result=((DateTimePatternGenerator *)dtpg)->replaceFieldTypes(patternString, skeletonString, options, *pErrorCode);
     246           0 :     return result.extract(dest, destCapacity, *pErrorCode);
     247             : }
     248             : 
     249             : U_CAPI UEnumeration * U_EXPORT2
     250           0 : udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
     251           0 :     return uenum_openFromStringEnumeration(
     252             :                 ((DateTimePatternGenerator *)dtpg)->getSkeletons(*pErrorCode),
     253           0 :                 pErrorCode);
     254             : }
     255             : 
     256             : U_CAPI UEnumeration * U_EXPORT2
     257           0 : udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode) {
     258           0 :     return uenum_openFromStringEnumeration(
     259             :                 ((DateTimePatternGenerator *)dtpg)->getBaseSkeletons(*pErrorCode),
     260           0 :                 pErrorCode);
     261             : }
     262             : 
     263             : U_CAPI const UChar * U_EXPORT2
     264           0 : udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
     265             :                              const UChar *skeleton, int32_t skeletonLength,
     266             :                              int32_t *pLength) {
     267           0 :     UnicodeString skeletonString((UBool)(skeletonLength<0), skeleton, skeletonLength);
     268           0 :     const UnicodeString &result=((const DateTimePatternGenerator *)dtpg)->getPatternForSkeleton(skeletonString);
     269           0 :     if(pLength!=NULL) {
     270           0 :         *pLength=result.length();
     271             :     }
     272           0 :     return result.getBuffer();
     273             : }
     274             : 
     275             : #endif

Generated by: LCOV version 1.13