@@ -678,14 +678,30 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
678678 */
679679 for (i = -1 ; i < ucol_countAvailable (); i ++ )
680680 {
681+ /*
682+ * In ICU 4.2, ucol_getKeywordsForLocale() sometimes returns
683+ * values that will not be accepted by uloc_toLanguageTag(). Skip
684+ * loading keyword variants in that version. (Both
685+ * ucol_getKeywordValuesForLocale() and uloc_toLanguageTag() are
686+ * new in ICU 4.2, so older versions are not supported at all.)
687+ *
688+ * XXX We have no information about ICU 4.3 through 4.7, but we
689+ * know the code below works with 4.8.
690+ */
691+ #if U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM > 2 )
692+ #define LOAD_ICU_KEYWORD_VARIANTS
693+ #endif
694+
681695 const char * name ;
682696 char * langtag ;
683697 char * icucomment ;
684698 const char * collcollate ;
699+ Oid collid ;
700+ #ifdef LOAD_ICU_KEYWORD_VARIANTS
685701 UEnumeration * en ;
686702 UErrorCode status ;
687703 const char * val ;
688- Oid collid ;
704+ #endif
689705
690706 if (i == -1 )
691707 name = "" ; /* ICU root locale */
@@ -721,18 +737,9 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
721737 }
722738
723739 /*
724- * Add keyword variants
725- *
726- * In ICU 4.2, ucol_getKeywordsForLocale() sometimes returns
727- * values that will not be accepted by uloc_toLanguageTag(). Skip
728- * loading keyword variants in that version. (Both
729- * ucol_getKeywordValuesForLocale() and uloc_toLanguageTag() are
730- * new in ICU 4.2, so older versions are not supported at all.)
731- *
732- * XXX We have no information about ICU 4.3 through 4.7, but we
733- * know the below works with 4.8.
740+ * Add keyword variants, if enabled.
734741 */
735- #if U_ICU_VERSION_MAJOR_NUM > 4 || ( U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM > 2 )
742+ #ifdef LOAD_ICU_KEYWORD_VARIANTS
736743 status = U_ZERO_ERROR ;
737744 en = ucol_getKeywordValuesForLocale ("collation" , name , TRUE, & status );
738745 if (U_FAILURE (status ))
@@ -779,7 +786,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
779786 (errmsg ("could not get keyword values for locale \"%s\": %s" ,
780787 name , u_errorName (status ))));
781788 uenum_close (en );
782- #endif /* ICU >4.2 */
789+ #endif /* LOAD_ICU_KEYWORD_VARIANTS */
783790 }
784791 }
785792#endif /* USE_ICU */
0 commit comments