From aca0c53ac2418c9c1d6e6f9d7063d67c5c6bf268 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Mon, 22 May 2000 22:24:51 +0000 Subject: [PATCH] ICU-397 make u_versionFrom/ToString() public X-SVN-Rev: 1437 --- icu4c/source/common/putil.c | 52 ++++++++++++++++++++++++++-- icu4c/source/common/uchar.c | 4 --- icu4c/source/test/cintltst/cucdtst.c | 18 +++------- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/icu4c/source/common/putil.c b/icu4c/source/common/putil.c index 98dc749984..171b03a55b 100644 --- a/icu4c/source/common/putil.c +++ b/icu4c/source/common/putil.c @@ -1645,7 +1645,6 @@ u_UCharsToChars(const UChar *us, char *cs, UTextOffset length) { } } -/* this function will become public */ U_CFUNC void u_versionFromString(UVersionInfo versionArray, const char *versionString) { char *end; @@ -1670,11 +1669,58 @@ u_versionFromString(UVersionInfo versionArray, const char *versionString) { } } -/* also, need U_CAPI void U_EXPORT2 u_versionToString(UVersionInfo versionArray, char *versionString) { + uint16_t count, part; + uint8_t field; + + if(versionString==NULL) { + return; + } + + if(versionArray==NULL) { + versionString[0]=0; + } + + /* count how many fields need to be written */ + for(count=4; count>0 && versionArray[count-1]==0; --count) {} + + if(count>0) { + /* write the first part */ + /* write the decimal field value */ + field=versionArray[0]; + if(field>=100) { + *versionString++='0'+field/100; + field%=100; + } + if(field>=10) { + *versionString++='0'+field/10; + field%=10; + } + *versionString++='0'+field; + + /* write the following parts */ + for(part=1; part=100) { + *versionString++='0'+field/100; + field%=100; + } + if(field>=10) { + *versionString++='0'+field/10; + field%=10; + } + *versionString++='0'+field; + } + } + + /* NUL-terminate */ + *versionString=0; } -*/ U_CAPI void U_EXPORT2 u_getVersion(UVersionInfo versionArray) { diff --git a/icu4c/source/common/uchar.c b/icu4c/source/common/uchar.c index 22038be085..4209a76848 100644 --- a/icu4c/source/common/uchar.c +++ b/icu4c/source/common/uchar.c @@ -878,10 +878,6 @@ u_charCellWidth(UChar32 ch) } } -/* ### this function will become public */ -U_CFUNC void -u_versionFromString(UVersionInfo versionArray, const char *versionString); - void u_getUnicodeVersion(UVersionInfo versionArray) { if(versionArray!=NULL) { uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH); diff --git a/icu4c/source/test/cintltst/cucdtst.c b/icu4c/source/test/cintltst/cucdtst.c index 62cea08de0..67a6c5b065 100644 --- a/icu4c/source/test/cintltst/cucdtst.c +++ b/icu4c/source/test/cintltst/cucdtst.c @@ -229,7 +229,7 @@ void TestMisc() FULL_WIDTH, NEUTRAL}; int i; - char icuVersion[U_MAX_VERSION_STRING_LENGTH], temp[U_MAX_VERSION_LENGTH]; + char icuVersion[U_MAX_VERSION_STRING_LENGTH]; UVersionInfo realVersion; memset(icuVersion, 0, U_MAX_VERSION_STRING_LENGTH); @@ -274,18 +274,7 @@ void TestMisc() } /* Tests the ICU version #*/ u_getVersion(realVersion); - for (i = 0; i < U_MAX_VERSION_LENGTH; i++ ) - { - int len = 0; - T_CString_integerToString(temp, realVersion[i], 10); - strcat(icuVersion, temp); - len = strlen(icuVersion); - if (i != U_MAX_VERSION_LENGTH-1) - { - icuVersion[len] = U_VERSION_DELIMITER; - icuVersion[len + 1] = 0; - } - } + u_versionToString(realVersion, icuVersion); if (strncmp(icuVersion, U_ICU_VERSION, MIN(strlen(icuVersion), strlen(U_ICU_VERSION))) != 0) { log_err("ICU version test failed. Header says=%s, got=%s \n", U_ICU_VERSION, icuVersion); @@ -387,7 +376,7 @@ void TestUnicodeData() const char *expectVersion = U_UNICODE_VERSION; /* NOTE: this purposely breaks to force the tests to stay in sync with the unicodedata */ /* expectVersionArray must be filled from u_versionFromString(expectVersionArray, U_UNICODE_VERSION) once this function is public. */ - UVersionInfo expectVersionArray = {0x03, 0x00, 0x00, 0x00}; + UVersionInfo expectVersionArray; UVersionInfo versionArray; char expectString[256]; @@ -396,6 +385,7 @@ void TestUnicodeData() strcat(newPath, expectVersion); strcat(newPath, ".txt"); + u_versionFromString(expectVersionArray, expectVersion); strcpy(expectString, "Unicode Version "); strcat(expectString, expectVersion); u_getUnicodeVersion(versionArray);