1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/zrule.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* 1.5 +******************************************************************************* 1.6 +* Copyright (C) 2009-2011, International Business Machines Corporation and 1.7 +* others. All Rights Reserved. 1.8 +******************************************************************************* 1.9 +*/ 1.10 + 1.11 +/** 1.12 + * \file 1.13 + * \brief C API: Time zone rule classes 1.14 + */ 1.15 + 1.16 +#include "unicode/utypes.h" 1.17 + 1.18 +#if !UCONFIG_NO_FORMATTING 1.19 + 1.20 +#include "unicode/uobject.h" 1.21 +#include "zrule.h" 1.22 +#include "unicode/tzrule.h" 1.23 +#include "cmemory.h" 1.24 +#include "unicode/ustring.h" 1.25 +#include "unicode/parsepos.h" 1.26 + 1.27 +U_NAMESPACE_USE 1.28 + 1.29 +/********************************************************************* 1.30 + * ZRule API 1.31 + *********************************************************************/ 1.32 + 1.33 +U_CAPI void U_EXPORT2 1.34 +zrule_close(ZRule* rule) { 1.35 + delete (TimeZoneRule*)rule; 1.36 +} 1.37 + 1.38 +U_CAPI UBool U_EXPORT2 1.39 +zrule_equals(const ZRule* rule1, const ZRule* rule2) { 1.40 + return *(const TimeZoneRule*)rule1 == *(const TimeZoneRule*)rule2; 1.41 +} 1.42 + 1.43 +U_CAPI void U_EXPORT2 1.44 +zrule_getName(ZRule* rule, UChar* name, int32_t nameLength) { 1.45 + UnicodeString s(nameLength==-1, name, nameLength); 1.46 + s = ((TimeZoneRule*)rule)->TimeZoneRule::getName(s); 1.47 + nameLength = s.length(); 1.48 + memcpy(name, s.getBuffer(), nameLength); 1.49 + return; 1.50 +} 1.51 + 1.52 +U_CAPI int32_t U_EXPORT2 1.53 +zrule_getRawOffset(ZRule* rule) { 1.54 + return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset(); 1.55 +} 1.56 + 1.57 +U_CAPI int32_t U_EXPORT2 1.58 +zrule_getDSTSavings(ZRule* rule) { 1.59 + return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings(); 1.60 +} 1.61 + 1.62 +U_CAPI UBool U_EXPORT2 1.63 +zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2) { 1.64 + return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2); 1.65 +} 1.66 + 1.67 +/********************************************************************* 1.68 + * IZRule API 1.69 + *********************************************************************/ 1.70 + 1.71 +U_CAPI IZRule* U_EXPORT2 1.72 +izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) { 1.73 + UnicodeString s(nameLength==-1, name, nameLength); 1.74 + return (IZRule*) new InitialTimeZoneRule(s, rawOffset, dstSavings); 1.75 +} 1.76 + 1.77 +U_CAPI void U_EXPORT2 1.78 +izrule_close(IZRule* rule) { 1.79 + delete (InitialTimeZoneRule*)rule; 1.80 +} 1.81 + 1.82 +U_CAPI IZRule* U_EXPORT2 1.83 +izrule_clone(IZRule *rule) { 1.84 + return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone()); 1.85 +} 1.86 + 1.87 +U_CAPI UBool U_EXPORT2 1.88 +izrule_equals(const IZRule* rule1, const IZRule* rule2) { 1.89 + return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2; 1.90 +} 1.91 + 1.92 +U_CAPI void U_EXPORT2 1.93 +izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength) { 1.94 + // UnicodeString s(nameLength==-1, name, nameLength); 1.95 + UnicodeString s; 1.96 + ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s); 1.97 + nameLength = s.length(); 1.98 + name = (UChar*)uprv_malloc(nameLength); 1.99 + memcpy(name, s.getBuffer(), nameLength); 1.100 + return; 1.101 +} 1.102 + 1.103 +U_CAPI int32_t U_EXPORT2 1.104 +izrule_getRawOffset(IZRule* rule) { 1.105 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset(); 1.106 +} 1.107 + 1.108 +U_CAPI int32_t U_EXPORT2 1.109 +izrule_getDSTSavings(IZRule* rule) { 1.110 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings(); 1.111 +} 1.112 + 1.113 +U_CAPI UBool U_EXPORT2 1.114 +izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2) { 1.115 + return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2); 1.116 +} 1.117 + 1.118 +U_CAPI UBool U_EXPORT2 1.119 +izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, 1.120 + UDate& result) { 1.121 + return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result); 1.122 +} 1.123 + 1.124 +U_CAPI UBool U_EXPORT2 1.125 +izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, 1.126 + UDate& result) { 1.127 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result); 1.128 +} 1.129 + 1.130 +U_CAPI UBool U_EXPORT2 1.131 +izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset, 1.132 + int32_t prevDSTSavings, UBool inclusive, UDate& result) { 1.133 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getNextStart(base, prevRawOffset, prevDSTSavings, inclusive, result); 1.134 +} 1.135 + 1.136 +U_CAPI UBool U_EXPORT2 1.137 +izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset, 1.138 + int32_t prevDSTSavings, UBool inclusive, UDate& result) { 1.139 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getPreviousStart(base, prevRawOffset, prevDSTSavings, inclusive, result); 1.140 +} 1.141 + 1.142 +U_CAPI UClassID U_EXPORT2 1.143 +izrule_getStaticClassID(IZRule* rule) { 1.144 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID(); 1.145 +} 1.146 + 1.147 +U_CAPI UClassID U_EXPORT2 1.148 +izrule_getDynamicClassID(IZRule* rule) { 1.149 + return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID(); 1.150 +} 1.151 + 1.152 +#endif