ICU-5720 Add data version API.

X-SVN-Rev: 26490
This commit is contained in:
Michael Ow 2009-08-13 17:21:33 +00:00
parent 406bb9dff0
commit da54f7cdee
8 changed files with 188 additions and 2 deletions

View file

@ -87,7 +87,7 @@ rbbi.o rbbidata.o rbbinode.o rbbirb.o rbbiscan.o rbbisetb.o rbbistbl.o rbbitblb.
serv.o servnotf.o servls.o servlk.o servlkf.o servrbf.o servslkf.o \
uidna.o usprep.o punycode.o \
util.o util_props.o parsepos.o locbased.o cwchar.o wintz.o mutex.o dtintrv.o ucnvsel.o propsvec.o \
ulist.o uloc_tag.o
ulist.o uloc_tag.o icudataver.o
## Header files to install
HEADERS = $(srcdir)/unicode/*.h unicode/*.h

View file

@ -0,0 +1,80 @@
/*
******************************************************************************
*
* Copyright (C) 2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
*/
#include "unicode/utypes.h"
#include "unicode/icudataver.h"
#include "unicode/uversion.h"
#include "unicode/ures.h"
/*
* Determines if icustd is in the data.
*/
UBool hasICUSTDBundle();
U_CAPI void U_EXPORT2 u_getDataVersion(UVersionInfo *dataVersionFillin, UErrorCode *status) {
UResourceBundle *icudatares = NULL;
if (U_FAILURE(*status)) {
return;
}
if (dataVersionFillin != NULL) {
icudatares = ures_openDirect(NULL, U_ICU_VERSION_BUNDLE , status);
if (U_SUCCESS(*status)) {
ures_getVersionByKey(icudatares, U_ICU_DATA_KEY, dataVersionFillin, status);
}
}
}
U_CAPI UBool U_EXPORT2 u_isDataOlder(UVersionInfo *dataVersionFillin, UBool *isModifiedFillin, UErrorCode *status) {
UBool result = TRUE;
UVersionInfo dataVersion;
UVersionInfo wiredVersion;
if (U_FAILURE(*status)) {
return result;
}
u_getDataVersion(&dataVersion, status);
if (U_SUCCESS(*status)) {
u_versionFromString(wiredVersion, U_ICU_DATA_VERSION);
if (u_versionCompare(dataVersion, wiredVersion) != -1) {
result = FALSE;
}
if (dataVersionFillin != NULL) {
u_versionCopy(dataVersionFillin, dataVersion);
}
if (hasICUSTDBundle()) {
*isModifiedFillin = FALSE;
} else {
*isModifiedFillin = TRUE;
}
}
return result;
}
UBool hasICUSTDBundle() {
UErrorCode status = U_ZERO_ERROR;
UBool result = TRUE;
UResourceBundle *icustdbundle = ures_openDirect(NULL, U_ICU_STD_BUNDLE, &status);
if (U_SUCCESS(status)) {
result = TRUE;
} else {
result = FALSE;
}
ures_close(icustdbundle);
return result;
}

View file

@ -1912,6 +1912,32 @@ u_getVersion(UVersionInfo versionArray) {
u_versionFromString(versionArray, U_ICU_VERSION);
}
U_CAPI int32_t U_EXPORT2
u_versionCompare(UVersionInfo version1, UVersionInfo version2) {
int32_t result = 0;
int i;
for (i = 0; i < U_MAX_VERSION_LENGTH; i++) {
if (version1[i] != version2[i]) {
if (version1[i] < version2[i]) {
result = -1;
} else {
result = 1;
}
break;
}
}
return result;
}
U_CAPI void U_EXPORT2
u_versionCopy(UVersionInfo versionDest, UVersionInfo versionSrc) {
int i;
for (i = 0; i < U_MAX_VERSION_LENGTH; i++) {
versionDest[i] = versionSrc[i];
}
}
/*
* Hey, Emacs, please set the following:
*

View file

@ -0,0 +1,47 @@
/*
******************************************************************************
*
* Copyright (C) 2009, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
*/
#ifndef __ICU_DATA_VER_H__
#define __ICU_DATA_VER_H__
#include "unicode/utypes.h"
#define U_ICU_VERSION_BUNDLE "icuver"
#define U_ICU_STD_BUNDLE "icustd"
#define U_ICU_DATA_KEY "DataVersion"
/**
* This function loads up icuver and compares the data version to the wired-in U_ICU_DATA_VERSION.
* If icuver shows something less than U_ICU_DATA_VERSION it returns TRUE, else FALSE. The version
* found will be returned in the first fillin parameter (if non-null), and *isModified will be set
* to TRUE if "icustd" is NOT found. Thus, if the data has been repackaged or modified, "icustd"
* (standard ICU) will be missing, and the function will alert the caller that the data is not standard.
*
* @param dataVersionFillin icuver data version information to be filled in if not-null
* @param isModifiedFillin if the data is not standard if not-null
* @param status stores the error code from the calls to resource bundle
*
* @return TRUE if U_ICU_DATA_VERSION is newer than icuver, else FALSE
*
* @draft ICU 4.4
*/
U_CAPI UBool U_EXPORT2 u_isDataOlder(UVersionInfo *dataVersionFillin, UBool *isModifiedFillin, UErrorCode *status);
/**
* Retrieves the data version from icuver and stores it in dataVersionFillin.
*
* @param dataVersionFillin icuver data version information to be filled in if not-null
* @param status stores the error code from the calls to resource bundle
*
* @draft ICU 4.4
*/
U_CAPI void U_EXPORT2 u_getDataVersion(UVersionInfo *dataVersionFillin, UErrorCode *status);
#endif

View file

@ -124,6 +124,11 @@
*/
typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH];
/** Data version in ICU4C.
* @draft ICU 4.4
*/
#define U_ICU_DATA_VERSION "4.3.2"
/*===========================================================================*/
/* C++ namespace if supported. Versioned unless versioning is disabled. */
/*===========================================================================*/
@ -246,6 +251,14 @@ u_versionToString(UVersionInfo versionArray, char *versionString);
U_STABLE void U_EXPORT2
u_getVersion(UVersionInfo versionArray);
/* TODO: Add description */
U_CAPI int32_t U_EXPORT2
u_versionCompare(UVersionInfo version1, UVersionInfo version2);
/* TODO: Add description */
U_CAPI void U_EXPORT2
u_versionCopy(UVersionInfo versionDest, UVersionInfo versionSrc);
/*===========================================================================
* ICU collation framework version information

View file

@ -0,0 +1,9 @@
// ***************************************************************************
// *
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// *
// ***************************************************************************
icustd:table(nofallback){
StandardICU{}
}

View file

@ -0,0 +1,11 @@
// ***************************************************************************
// *
// * Copyright (C) 2009 International Business Machines
// * Corporation and others. All Rights Reserved.
// *
// ***************************************************************************
icuver:table(nofallback){
DataVersion { "4.3.2.0" }
ICUVersion { "4.3.2.0" }
}

View file

@ -23,4 +23,4 @@
#
MISC_SOURCE = \
zoneinfo.txt supplementalData.txt metazoneInfo.txt likelySubtags.txt plurals.txt numberingSystems.txt
zoneinfo.txt supplementalData.txt metazoneInfo.txt likelySubtags.txt plurals.txt numberingSystems.txt icuver.txt icustd.txt