#include "postgres.h"
#include "catalog/pg_type.h"
+#include "common/string.h"
#include "funcapi.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
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)
{
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")));
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")));
#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"
#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
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)
* 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;
* 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),
#endif
#include "common/saslprep.h"
+#include "common/string.h"
#include "common/unicode_norm.h"
#include "mb/pg_wchar.h"
static int codepoint_range_cmp(const void *a, const void *b);
static bool is_code_in_table(pg_wchar code, const pg_wchar *map, int mapsize);
static int pg_utf8_string_len(const char *source);
-static bool pg_is_ascii_string(const char *p);
/*
* Stringprep Mapping Tables.
return num_chars;
}
-/*
- * Returns true if the input string is pure ASCII.
- */
-static bool
-pg_is_ascii_string(const char *p)
-{
- while (*p)
- {
- if (IS_HIGHBIT_SET(*p))
- return false;
- p++;
- }
- return true;
-}
-
/*
* pg_saslprep - Normalize a password with SASLprep.
* Quick check if the input is pure ASCII. An ASCII string requires no
* further processing.
*/
- if (pg_is_ascii_string(input))
+ if (pg_is_ascii(input))
{
*output = STRDUP(input);
if (!(*output))
}
+/*
+ * 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
*
int base);
extern void pg_clean_ascii(char *str);
extern int pg_strip_crlf(char *str);
+extern bool pg_is_ascii(const char *str);
/* functions in src/common/pg_get_line.c */
extern char *pg_get_line(FILE *stream);