From 35359d85413780ee62aa7de1b6e9cbae203b49af Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 6 Aug 2024 19:47:04 +0000 Subject: Clean up of the ICU code and tests --- generic/tclIcu.c | 35 +++++++++++++++++++++++++---------- tests/icu.test | 49 +++++++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/generic/tclIcu.c b/generic/tclIcu.c index b6355ee..dd7e82f 100644 --- a/generic/tclIcu.c +++ b/generic/tclIcu.c @@ -577,11 +577,19 @@ TclIcuInit( } #endif -#define ICUUC_SYM(name) \ - strcpy(symbol, #name ); \ - strcat(symbol, icuversion); \ - icu_fns._##name = (fn_ ## name) \ - Tcl_FindSymbol(NULL, icu_fns.libs[0], symbol) + /* Try for symbol without version (Windows, FreeBSD), then with version */ +#define ICUUC_SYM(name) \ + do { \ + strcpy(symbol, #name); \ + icu_fns._##name = \ + (fn_##name)Tcl_FindSymbol(NULL, icu_fns.libs[0], symbol); \ + if (icu_fns._##name == NULL) { \ + strcat(symbol, icuversion); \ + icu_fns._##name = \ + (fn_##name)Tcl_FindSymbol(NULL, icu_fns.libs[0], symbol); \ + } \ + } while (0) + if (icu_fns.libs[0] != NULL) { ICUUC_SYM(u_cleanup); ICUUC_SYM(u_errorName); @@ -606,11 +614,18 @@ TclIcuInit( #undef ICUUC_SYM } -#define ICUIN_SYM(name) \ - strcpy(symbol, #name ); \ - strcat(symbol, icuversion); \ - icu_fns._##name = (fn_ ## name) \ - Tcl_FindSymbol(NULL, icu_fns.libs[1], symbol) +#define ICUIN_SYM(name) \ + do { \ + strcpy(symbol, #name); \ + icu_fns._##name = \ + (fn_##name)Tcl_FindSymbol(NULL, icu_fns.libs[1], symbol); \ + if (icu_fns._##name == NULL) { \ + strcat(symbol, icuversion); \ + icu_fns._##name = \ + (fn_##name)Tcl_FindSymbol(NULL, icu_fns.libs[1], symbol); \ + } \ + } while (0) + if (icu_fns.libs[1] != NULL) { ICUIN_SYM(ucsdet_close); ICUIN_SYM(ucsdet_detect); diff --git a/tests/icu.test b/tests/icu.test index 522ed53..eabe3df 100644 --- a/tests/icu.test +++ b/tests/icu.test @@ -7,45 +7,54 @@ if {"::tcltest" ni [namespace children]} { # Force late loading of ICU if present catch {::tcl::unsupported::icu} -testConstraint icu [expr {[info commands ::tcl::unsupported::icu::detect] ne ""}] +testConstraint icu [llength [info commands ::tcl::unsupported::icu::detect]] namespace eval icu { + namespace path {::tcl::unsupported ::tcl::mathop} + test icu-detect-0 {Return list of ICU encodings} -constraints icu -body { - set encoders [::tcl::unsupported::icu detect] - list [::tcl::mathop::in UTF-8 $encoders] [::tcl::mathop::in ISO-8859-1 $encoders] + set encoders [icu detect] + list [in UTF-8 $encoders] [in ISO-8859-1 $encoders] } -result {1 1} - test icu-detect-1 {Guess encoding} -constraints icu -body { - ::tcl::unsupported::icu detect [readFile [info script]] + icu detect [readFile [info script]] } -result ISO-8859-1 - test icu-detect-2 {Get all possible encodings} -constraints icu -body { - set encodings [::tcl::unsupported::icu detect [readFile [info script]] -all] - list [::tcl::mathop::in UTF-8 $encodings] [::tcl::mathop::in ISO-8859-1 $encodings] + set encodings [icu detect [readFile [info script]] -all] + list [in UTF-8 $encodings] [in ISO-8859-1 $encodings] } -result {1 1} + test icu-detect-3 {error case} -constraints icu -returnCodes error -body { + icu detect gorp gorp gorp + } -result {wrong # args: should be "icu detect ?bytes ?-all??"} test icu-tclToIcu-0 {Map Tcl encoding} -constraints icu -body { - # tis-620 because it is ambiguous in ICU on some platforms - # but should return the preferred encoding - list [::tcl::unsupported::icu tclToIcu utf-8] [::tcl::unsupported::icu tclToIcu tis-620] [::tcl::unsupported::icu tclToIcu shiftjis] + # tis-620 because it is ambiguous in ICU on some platforms + # but should return the preferred encoding + lmap enc {utf-8 tis-620 shiftjis} { + icu tclToIcu $enc + } } -result {UTF-8 TIS-620 ibm-943_P15A-2003} - test icu-tclToIcu-1 {Map Tcl encoding - no map} -constraints icu -body { - # Should not raise an error - ::tcl::unsupported::icu tclToIcu dummy + # Should not raise an error + icu tclToIcu dummy } -result {} + test icu-tclToIcu-2 {error case} -constraints icu -returnCodes error -body { + icu tclToIcu gorp gorp + } -result {wrong # args: should be "icu tclToIcu tclName"} test icu-icuToTcl-0 {Map ICU encoding} -constraints icu -body { - list [::tcl::unsupported::icu icuToTcl UTF-8] [::tcl::unsupported::icu icuToTcl TIS-620] [::tcl::unsupported::icu icuToTcl ibm-943_P15A-2003] + lmap enc {UTF-8 TIS-620 ibm-943_P15A-2003} { + icu icuToTcl $enc + } } -result {utf-8 tis-620 cp932} - test icu-icuToTcl-1 {Map ICU encoding - no map} -constraints icu -body { - # Should not raise an error - ::tcl::unsupported::icu icuToTcl dummy + # Should not raise an error + icu icuToTcl dummy } -result {} - + test icu-icuToTcl-2 {error case} -constraints icu -returnCodes error -body { + icu icuToTcl gorp gorp + } -result {wrong # args: should be "icu icuToTcl icuName"} } - namespace delete icu ::tcltest::cleanupTests -- cgit v0.12