aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/collationcmds.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-12-21 09:37:11 +0900
committerMichael Paquier <michael@paquier.xyz>2020-12-21 09:37:11 +0900
commit93e8ff8701a65a70ea8826bdde7fdbbd9c285477 (patch)
tree70afa5868c3b27609fe50097204bba45a21092d6 /src/backend/commands/collationcmds.c
parent4e1ee79e3182256d9c8ddbc1ce9c4e8419c611ff (diff)
downloadpostgresql-93e8ff8701a65a70ea8826bdde7fdbbd9c285477.tar.gz
postgresql-93e8ff8701a65a70ea8826bdde7fdbbd9c285477.zip
Refactor logic to check for ASCII-only characters in string
The same logic was present for collation commands, SASLprep and pgcrypto, so this removes some code. Author: Michael Paquier Reviewed-by: Stephen Frost, Heikki Linnakangas Discussion: https://postgr.es/m/X9womIn6rne6Gud2@paquier.xyz
Diffstat (limited to 'src/backend/commands/collationcmds.c')
-rw-r--r--src/backend/commands/collationcmds.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index 32b2183598d..d62c8defbab 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -27,6 +27,7 @@
#include "commands/comment.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
+#include "common/string.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/acl.h"
@@ -286,23 +287,6 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
#define READ_LOCALE_A_OUTPUT
#endif
-#if defined(READ_LOCALE_A_OUTPUT) || defined(USE_ICU)
-/*
- * Check a string to see if it is pure ASCII
- */
-static bool
-is_all_ascii(const char *str)
-{
- while (*str)
- {
- if (IS_HIGHBIT_SET(*str))
- return false;
- str++;
- }
- return true;
-}
-#endif /* READ_LOCALE_A_OUTPUT || USE_ICU */
-
#ifdef READ_LOCALE_A_OUTPUT
/*
* "Normalize" a libc locale name, stripping off encoding tags such as
@@ -396,7 +380,7 @@ get_icu_locale_comment(const char *localename)
if (U_FAILURE(status))
return NULL; /* no good reason to raise an error */
- /* Check for non-ASCII comment (can't use is_all_ascii for this) */
+ /* Check for non-ASCII comment (can't use pg_is_ascii for this) */
for (i = 0; i < len_uchar; i++)
{
if (displayname[i] > 127)
@@ -477,7 +461,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
* interpret the non-ASCII characters. We can't do much with
* those, so we filter them out.
*/
- if (!is_all_ascii(localebuf))
+ if (!pg_is_ascii(localebuf))
{
elog(DEBUG1, "locale name has non-ASCII characters, skipped: \"%s\"", localebuf);
continue;
@@ -623,7 +607,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
* Be paranoid about not allowing any non-ASCII strings into
* pg_collation
*/
- if (!is_all_ascii(langtag) || !is_all_ascii(collcollate))
+ if (!pg_is_ascii(langtag) || !pg_is_ascii(collcollate))
continue;
collid = CollationCreate(psprintf("%s-x-icu", langtag),