From 93e8ff8701a65a70ea8826bdde7fdbbd9c285477 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 21 Dec 2020 09:37:11 +0900 Subject: 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 --- src/common/string.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common/string.c') diff --git a/src/common/string.c b/src/common/string.c index bcbbfb813db..3e76e2c59fb 100644 --- a/src/common/string.c +++ b/src/common/string.c @@ -92,6 +92,22 @@ pg_clean_ascii(char *str) } +/* + * pg_is_ascii -- Check if string is made only of ASCII characters + */ +bool +pg_is_ascii(const char *str) +{ + while (*str) + { + if (IS_HIGHBIT_SET(*str)) + return false; + str++; + } + return true; +} + + /* * pg_strip_crlf -- Remove any trailing newline and carriage return * -- cgit v1.2.3