1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

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
This commit is contained in:
Michael Paquier
2020-12-21 09:37:11 +09:00
parent 4e1ee79e31
commit 93e8ff8701
5 changed files with 26 additions and 52 deletions

View File

@ -32,6 +32,7 @@
#include "postgres.h"
#include "catalog/pg_type.h"
#include "common/string.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
@ -92,19 +93,6 @@ convert_to_utf8(text *src)
return convert_charset(src, GetDatabaseEncoding(), PG_UTF8);
}
static bool
string_is_ascii(const char *str)
{
const char *p;
for (p = str; *p; p++)
{
if (IS_HIGHBIT_SET(*p))
return false;
}
return true;
}
static void
clear_and_pfree(text *p)
{
@ -814,7 +802,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
v = TextDatumGetCString(key_datums[i]);
if (!string_is_ascii(v))
if (!pg_is_ascii(v))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("header key must not contain non-ASCII characters")));
@ -836,7 +824,7 @@ parse_key_value_arrays(ArrayType *key_array, ArrayType *val_array,
v = TextDatumGetCString(val_datums[i]);
if (!string_is_ascii(v))
if (!pg_is_ascii(v))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("header value must not contain non-ASCII characters")));