+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (c) 2003-2008, International Business Machines
#include "cstring.h"
#include "uassert.h"
-#if defined(U_DEBUG_CALDATA)
-#include <stdio.h>
-#endif
-
U_NAMESPACE_BEGIN
int32_t ClockMath::floorDivide(int32_t numerator, int32_t denominator) {
numerator / denominator : ((numerator + 1) / denominator) - 1;
}
+int64_t ClockMath::floorDivide(int64_t numerator, int64_t denominator) {
+ return (numerator >= 0) ?
+ numerator / denominator : ((numerator + 1) / denominator) - 1;
+}
+
int32_t ClockMath::floorDivide(double numerator, int32_t denominator,
int32_t& remainder) {
double quotient;
return weekInMonth;
}
-/* ---- CalendarData ------ */
-
-#define U_CALENDAR_KEY "calendar"
-#define U_GREGORIAN_KEY "gregorian"
-#define U_FORMAT_KEY "format"
-#define U_DEFAULT_KEY "default"
-#define U_CALENDAR_DATA ((char*)0)
-
-
-// CalendarData::CalendarData(const Locale& loc, UErrorCode& status)
-// : fFillin(NULL), fBundle(NULL), fFallback(NULL) {
-// initData(loc.getBaseName(), (char*) "???", status);
-// }
-
-CalendarData::CalendarData(const Locale& loc, const char *type, UErrorCode& status)
- : fFillin(NULL), fOtherFillin(NULL), fBundle(NULL), fFallback(NULL) {
- initData(loc.getBaseName(), type, status);
-}
-
-void CalendarData::initData(const char *locale, const char *type, UErrorCode& status) {
- fOtherFillin = ures_open(U_CALENDAR_DATA, locale, &status);
- fFillin = ures_getByKey(fOtherFillin, U_CALENDAR_KEY, fFillin, &status);
-
- if((type != NULL) &&
- (*type != '\0') &&
- (uprv_strcmp(type, U_GREGORIAN_KEY)))
- {
- fBundle = ures_getByKeyWithFallback(fFillin, type, NULL, &status);
- fFallback = ures_getByKeyWithFallback(fFillin, U_GREGORIAN_KEY, NULL, &status);
-
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: CalendarData(%s, %s, %s) -> main(%p, %s)=%s, fallback(%p, %s)=%s\n",
- this, locale, type, u_errorName(status), fBundle, type, fBundle?ures_getLocale(fBundle, &status):"",
- fFallback, U_GREGORIAN_KEY, fFallback?ures_getLocale(fFallback, &status):"");
-#endif
-
- } else {
- fBundle = ures_getByKeyWithFallback(fFillin, U_GREGORIAN_KEY, NULL, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: CalendarData(%s, %s, %s) -> main(%p, %s)=%s, fallback = NULL\n",
- this, locale, type, u_errorName(status), fBundle, U_GREGORIAN_KEY, fBundle?ures_getLocale(fBundle, &status):"" );
-#endif
- }
-}
-
-CalendarData::~CalendarData() {
- ures_close(fFillin);
- ures_close(fBundle);
- ures_close(fFallback);
- ures_close(fOtherFillin);
-}
-
-UResourceBundle*
-CalendarData::getByKey(const char *key, UErrorCode& status) {
- if(U_FAILURE(status)) {
- return NULL;
- }
-
- if(fBundle) {
- fFillin = ures_getByKeyWithFallback(fBundle, key, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s -> %s - from MAIN %s\n",this, key, u_errorName(status), ures_getLocale(fFillin, &status));
-#endif
- }
- if(fFallback && (status == U_MISSING_RESOURCE_ERROR)) {
- status = U_ZERO_ERROR; // retry with fallback (gregorian)
- fFillin = ures_getByKeyWithFallback(fFallback, key, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s -> %s - from FALLBACK %s\n",this, key, u_errorName(status), ures_getLocale(fFillin, &status));
-#endif
- }
- return fFillin;
-}
-
-UResourceBundle* CalendarData::getByKey2(const char *key, const char *subKey, UErrorCode& status) {
- if(U_FAILURE(status)) {
- return NULL;
- }
-
- if(fBundle) {
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: //\n");
-#endif
- fFillin = ures_getByKeyWithFallback(fBundle, key, fFillin, &status);
- fOtherFillin = ures_getByKeyWithFallback(fFillin, U_FORMAT_KEY, fOtherFillin, &status);
- fFillin = ures_getByKeyWithFallback(fOtherFillin, subKey, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s/format/%s -> %s - from MAIN %s\n", this, key, subKey, u_errorName(status), ures_getLocale(fFillin, &status));
-#endif
- }
- if(fFallback && (status == U_MISSING_RESOURCE_ERROR)) {
- status = U_ZERO_ERROR; // retry with fallback (gregorian)
- fFillin = ures_getByKeyWithFallback(fFallback, key, fFillin, &status);
- fOtherFillin = ures_getByKeyWithFallback(fFillin, U_FORMAT_KEY, fOtherFillin, &status);
- fFillin = ures_getByKeyWithFallback(fOtherFillin, subKey, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s/format/%s -> %s - from FALLBACK %s\n",this, key, subKey, u_errorName(status), ures_getLocale(fFillin,&status));
-#endif
- }
-
-//// handling of 'default' keyword on failure: Commented out for 3.0.
-// if((status == U_MISSING_RESOURCE_ERROR) &&
-// uprv_strcmp(subKey,U_DEFAULT_KEY)) { // avoid recursion
-// #if defined (U_DEBUG_CALDATA)
-// fprintf(stderr, "%p: - attempting fallback -\n", this);
-// fflush(stderr);
-// #endif
-// UErrorCode subStatus = U_ZERO_ERROR;
-// int32_t len;
-// char kwBuf[128] = "";
-// const UChar *kw;
-// /* fFillin = */ getByKey2(key, U_DEFAULT_KEY, subStatus);
-// kw = ures_getString(fFillin, &len, &subStatus);
-// if(len>126) { // too big
-// len = 0;
-// }
-// if(U_SUCCESS(subStatus) && (len>0)) {
-// u_UCharsToChars(kw, kwBuf, len+1);
-// if(*kwBuf && uprv_strcmp(kwBuf,subKey)) {
-// #if defined (U_DEBUG_CALDATA)
-// fprintf(stderr, "%p: trying %s/format/default -> \"%s\"\n",this, key, kwBuf);
-// #endif
-// // now try again with the default
-// status = U_ZERO_ERROR;
-// /* fFillin = */ getByKey2(key, kwBuf, status);
-// }
-// #if defined (U_DEBUG_CALDATA)
-// } else {
-// fprintf(stderr, "%p: could not load %s/format/default - fail out (%s)\n",this, key, kwBuf, u_errorName(status));
-// #endif
-// }
-// }
-
- return fFillin;
-}
-
-UResourceBundle* CalendarData::getByKey3(const char *key, const char *contextKey, const char *subKey, UErrorCode& status) {
- if(U_FAILURE(status)) {
- return NULL;
- }
-
- if(fBundle) {
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: //\n");
-#endif
- fFillin = ures_getByKeyWithFallback(fBundle, key, fFillin, &status);
- fOtherFillin = ures_getByKeyWithFallback(fFillin, contextKey, fOtherFillin, &status);
- fFillin = ures_getByKeyWithFallback(fOtherFillin, subKey, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s/%s/%s -> %s - from MAIN %s\n", this, key, contextKey, subKey, u_errorName(status), ures_getLocale(fFillin, &status));
-#endif
- }
- if(fFallback && (status == U_MISSING_RESOURCE_ERROR)) {
- status = U_ZERO_ERROR; // retry with fallback (gregorian)
- fFillin = ures_getByKeyWithFallback(fFallback, key, fFillin, &status);
- fOtherFillin = ures_getByKeyWithFallback(fFillin, contextKey, fOtherFillin, &status);
- fFillin = ures_getByKeyWithFallback(fOtherFillin, subKey, fFillin, &status);
-#if defined (U_DEBUG_CALDATA)
- fprintf(stderr, "%p: get %s/%s/%s -> %s - from FALLBACK %s\n",this, key, contextKey, subKey, u_errorName(status), ures_getLocale(fFillin,&status));
-#endif
- }
-
- return fFillin;
-}
-
U_NAMESPACE_END
#endif