Refactor pg_set_regex_collation() for clarity.
authorJeff Davis <[email protected]>
Sun, 28 Jul 2024 23:55:17 +0000 (16:55 -0700)
committerJeff Davis <[email protected]>
Sun, 28 Jul 2024 23:55:17 +0000 (16:55 -0700)
Discussion: https://postgr.es/m/63409030-2746-462e-beac-759bd43032ce@proxel.se
Reviewed-by: Andreas Karlsson
src/backend/regex/regc_pg_locale.c

index 85f3238eb071a379c33d4efe9e533f756160e554..9d98d10a285098eae05b3054eb83b2cd4e517ad7 100644 (file)
@@ -261,29 +261,33 @@ pg_set_regex_collation(Oid collation)
                    (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                     errmsg("nondeterministic collations are not supported for regular expressions")));
 
+       if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
+       {
+           Assert(GetDatabaseEncoding() == PG_UTF8);
+           pg_regex_strategy = PG_REGEX_BUILTIN;
+       }
 #ifdef USE_ICU
-       if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
+       else if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
+       {
            pg_regex_strategy = PG_REGEX_LOCALE_ICU;
-       else
+       }
 #endif
-       if (GetDatabaseEncoding() == PG_UTF8)
+       else
        {
-           if (pg_regex_locale)
+           if (GetDatabaseEncoding() == PG_UTF8)
            {
-               if (pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
-                   pg_regex_strategy = PG_REGEX_BUILTIN;
-               else
+               if (pg_regex_locale)
                    pg_regex_strategy = PG_REGEX_LOCALE_WIDE_L;
+               else
+                   pg_regex_strategy = PG_REGEX_LOCALE_WIDE;
            }
            else
-               pg_regex_strategy = PG_REGEX_LOCALE_WIDE;
-       }
-       else
-       {
-           if (pg_regex_locale)
-               pg_regex_strategy = PG_REGEX_LOCALE_1BYTE_L;
-           else
-               pg_regex_strategy = PG_REGEX_LOCALE_1BYTE;
+           {
+               if (pg_regex_locale)
+                   pg_regex_strategy = PG_REGEX_LOCALE_1BYTE_L;
+               else
+                   pg_regex_strategy = PG_REGEX_LOCALE_1BYTE;
+           }
        }
 
        pg_regex_collation = collation;