michael@0: /* michael@0: ******************************************************************************* michael@0: * Copyright (C) 2009-2011, International Business Machines Corporation and michael@0: * others. All Rights Reserved. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Time zone rule classes michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "zrule.h" michael@0: #include "unicode/tzrule.h" michael@0: #include "cmemory.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/parsepos.h" michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: /********************************************************************* michael@0: * ZRule API michael@0: *********************************************************************/ michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: zrule_close(ZRule* rule) { michael@0: delete (TimeZoneRule*)rule; michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: zrule_equals(const ZRule* rule1, const ZRule* rule2) { michael@0: return *(const TimeZoneRule*)rule1 == *(const TimeZoneRule*)rule2; michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: zrule_getName(ZRule* rule, UChar* name, int32_t nameLength) { michael@0: UnicodeString s(nameLength==-1, name, nameLength); michael@0: s = ((TimeZoneRule*)rule)->TimeZoneRule::getName(s); michael@0: nameLength = s.length(); michael@0: memcpy(name, s.getBuffer(), nameLength); michael@0: return; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: zrule_getRawOffset(ZRule* rule) { michael@0: return ((TimeZoneRule*)rule)->TimeZoneRule::getRawOffset(); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: zrule_getDSTSavings(ZRule* rule) { michael@0: return ((TimeZoneRule*)rule)->TimeZoneRule::getDSTSavings(); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: zrule_isEquivalentTo(ZRule* rule1, ZRule* rule2) { michael@0: return ((TimeZoneRule*)rule1)->TimeZoneRule::isEquivalentTo(*(TimeZoneRule*)rule2); michael@0: } michael@0: michael@0: /********************************************************************* michael@0: * IZRule API michael@0: *********************************************************************/ michael@0: michael@0: U_CAPI IZRule* U_EXPORT2 michael@0: izrule_open(const UChar* name, int32_t nameLength, int32_t rawOffset, int32_t dstSavings) { michael@0: UnicodeString s(nameLength==-1, name, nameLength); michael@0: return (IZRule*) new InitialTimeZoneRule(s, rawOffset, dstSavings); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: izrule_close(IZRule* rule) { michael@0: delete (InitialTimeZoneRule*)rule; michael@0: } michael@0: michael@0: U_CAPI IZRule* U_EXPORT2 michael@0: izrule_clone(IZRule *rule) { michael@0: return (IZRule*) (((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::clone()); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_equals(const IZRule* rule1, const IZRule* rule2) { michael@0: return *(const InitialTimeZoneRule*)rule1 == *(const InitialTimeZoneRule*)rule2; michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: izrule_getName(IZRule* rule, UChar* & name, int32_t & nameLength) { michael@0: // UnicodeString s(nameLength==-1, name, nameLength); michael@0: UnicodeString s; michael@0: ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getName(s); michael@0: nameLength = s.length(); michael@0: name = (UChar*)uprv_malloc(nameLength); michael@0: memcpy(name, s.getBuffer(), nameLength); michael@0: return; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: izrule_getRawOffset(IZRule* rule) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getRawOffset(); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: izrule_getDSTSavings(IZRule* rule) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDSTSavings(); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_isEquivalentTo(IZRule* rule1, IZRule* rule2) { michael@0: return ((InitialTimeZoneRule*)rule1)->InitialTimeZoneRule::isEquivalentTo(*(InitialTimeZoneRule*)rule2); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_getFirstStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, michael@0: UDate& result) { michael@0: return ((const InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFirstStart(prevRawOffset, prevDSTSavings, result); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_getFinalStart(IZRule* rule, int32_t prevRawOffset, int32_t prevDSTSavings, michael@0: UDate& result) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getFinalStart(prevRawOffset, prevDSTSavings, result); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_getNextStart(IZRule* rule, UDate base, int32_t prevRawOffset, michael@0: int32_t prevDSTSavings, UBool inclusive, UDate& result) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getNextStart(base, prevRawOffset, prevDSTSavings, inclusive, result); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: izrule_getPreviousStart(IZRule* rule, UDate base, int32_t prevRawOffset, michael@0: int32_t prevDSTSavings, UBool inclusive, UDate& result) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getPreviousStart(base, prevRawOffset, prevDSTSavings, inclusive, result); michael@0: } michael@0: michael@0: U_CAPI UClassID U_EXPORT2 michael@0: izrule_getStaticClassID(IZRule* rule) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getStaticClassID(); michael@0: } michael@0: michael@0: U_CAPI UClassID U_EXPORT2 michael@0: izrule_getDynamicClassID(IZRule* rule) { michael@0: return ((InitialTimeZoneRule*)rule)->InitialTimeZoneRule::getDynamicClassID(); michael@0: } michael@0: michael@0: #endif