PostgreSQL Source Code git master
ts_locale.h File Reference
#include <ctype.h>
#include <limits.h>
#include <wctype.h>
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
#include "utils/pg_locale.h"
Include dependency graph for ts_locale.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  tsearch_readline_state
 

Macros

#define TOUCHAR(x)   (*((const unsigned char *) (x)))
 
#define t_iseq(x, c)   (TOUCHAR(x) == (unsigned char) (c))
 
#define COPYCHAR(d, s)   memcpy(d, s, pg_mblen(s))
 

Functions

int t_isalpha (const char *ptr)
 
int t_isalnum (const char *ptr)
 
bool tsearch_readline_begin (tsearch_readline_state *stp, const char *filename)
 
char * tsearch_readline (tsearch_readline_state *stp)
 
void tsearch_readline_end (tsearch_readline_state *stp)
 

Macro Definition Documentation

◆ COPYCHAR

#define COPYCHAR (   d,
 
)    memcpy(d, s, pg_mblen(s))

Definition at line 40 of file ts_locale.h.

◆ t_iseq

#define t_iseq (   x,
  c 
)    (TOUCHAR(x) == (unsigned char) (c))

Definition at line 38 of file ts_locale.h.

◆ TOUCHAR

#define TOUCHAR (   x)    (*((const unsigned char *) (x)))

Definition at line 35 of file ts_locale.h.

Function Documentation

◆ t_isalnum()

int t_isalnum ( const char *  ptr)

Definition at line 40 of file ts_locale.c.

41{
42 pg_wchar wstr[WC_BUF_LEN];
43 int wlen pg_attribute_unused();
44
45 wlen = pg_mb2wchar_with_len(ptr, wstr, pg_mblen(ptr));
46 Assert(wlen <= 1);
47
48 /* pass single character, or NUL if empty */
49 return pg_iswalnum(wstr[0], pg_database_locale());
50}
#define pg_attribute_unused()
Definition: c.h:137
Assert(PointerIsAligned(start, uint64))
unsigned int pg_wchar
Definition: mbprint.c:31
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
Definition: mbutils.c:987
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1024
bool pg_iswalnum(pg_wchar wc, pg_locale_t locale)
Definition: pg_locale.c:1510
pg_locale_t pg_database_locale(void)
Definition: pg_locale.c:1172
#define WC_BUF_LEN
Definition: ts_locale.c:24

References Assert(), pg_attribute_unused, pg_database_locale(), pg_iswalnum(), pg_mb2wchar_with_len(), pg_mblen(), and WC_BUF_LEN.

Referenced by parse_or_operator().

◆ t_isalpha()

int t_isalpha ( const char *  ptr)

Definition at line 27 of file ts_locale.c.

28{
29 pg_wchar wstr[WC_BUF_LEN];
30 int wlen pg_attribute_unused();
31
32 wlen = pg_mb2wchar_with_len(ptr, wstr, pg_mblen(ptr));
33 Assert(wlen <= 1);
34
35 /* pass single character, or NUL if empty */
36 return pg_iswalpha(wstr[0], pg_database_locale());
37}
bool pg_iswalpha(pg_wchar wc, pg_locale_t locale)
Definition: pg_locale.c:1500

References Assert(), pg_attribute_unused, pg_database_locale(), pg_iswalpha(), pg_mb2wchar_with_len(), pg_mblen(), and WC_BUF_LEN.

Referenced by parse_affentry(), RS_compile(), and RS_isRegis().

◆ tsearch_readline()

char * tsearch_readline ( tsearch_readline_state stp)

Definition at line 100 of file ts_locale.c.

101{
102 char *recoded;
103
104 /* Advance line number to use in error reports */
105 stp->lineno++;
106
107 /* Clear curline, it's no longer relevant */
108 if (stp->curline)
109 {
110 if (stp->curline != stp->buf.data)
111 pfree(stp->curline);
112 stp->curline = NULL;
113 }
114
115 /* Collect next line, if there is one */
116 if (!pg_get_line_buf(stp->fp, &stp->buf))
117 return NULL;
118
119 /* Validate the input as UTF-8, then convert to DB encoding if needed */
120 recoded = pg_any_to_server(stp->buf.data, stp->buf.len, PG_UTF8);
121
122 /* Save the correctly-encoded string for possible error reports */
123 stp->curline = recoded; /* might be equal to buf.data */
124
125 /*
126 * We always return a freshly pstrdup'd string. This is clearly necessary
127 * if pg_any_to_server() returned buf.data, and we need a second copy even
128 * if encoding conversion did occur. The caller is entitled to pfree the
129 * returned string at any time, which would leave curline pointing to
130 * recycled storage, causing problems if an error occurs after that point.
131 * (It's preferable to return the result of pstrdup instead of the output
132 * of pg_any_to_server, because the conversion result tends to be
133 * over-allocated. Since callers might save the result string directly
134 * into a long-lived dictionary structure, we don't want it to be a larger
135 * palloc chunk than necessary. We'll reclaim the conversion result on
136 * the next call.)
137 */
138 return pstrdup(recoded);
139}
char * pg_any_to_server(const char *s, int len, int encoding)
Definition: mbutils.c:677
char * pstrdup(const char *in)
Definition: mcxt.c:1759
void pfree(void *pointer)
Definition: mcxt.c:1594
bool pg_get_line_buf(FILE *stream, StringInfo buf)
Definition: pg_get_line.c:95
@ PG_UTF8
Definition: pg_wchar.h:232
StringInfoData buf
Definition: ts_locale.h:29

References tsearch_readline_state::buf, tsearch_readline_state::curline, StringInfoData::data, tsearch_readline_state::fp, StringInfoData::len, tsearch_readline_state::lineno, pfree(), pg_any_to_server(), pg_get_line_buf(), PG_UTF8, and pstrdup().

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().

◆ tsearch_readline_begin()

bool tsearch_readline_begin ( tsearch_readline_state stp,
const char *  filename 
)

Definition at line 77 of file ts_locale.c.

79{
80 if ((stp->fp = AllocateFile(filename, "r")) == NULL)
81 return false;
82 stp->filename = filename;
83 stp->lineno = 0;
84 initStringInfo(&stp->buf);
85 stp->curline = NULL;
86 /* Setup error traceback support for ereport() */
88 stp->cb.arg = stp;
90 error_context_stack = &stp->cb;
91 return true;
92}
ErrorContextCallback * error_context_stack
Definition: elog.c:95
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2641
static char * filename
Definition: pg_dumpall.c:120
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
struct ErrorContextCallback * previous
Definition: elog.h:297
void(* callback)(void *arg)
Definition: elog.h:298
ErrorContextCallback cb
Definition: ts_locale.h:32
const char * filename
Definition: ts_locale.h:27
static void tsearch_readline_callback(void *arg)
Definition: ts_locale.c:168

References AllocateFile(), ErrorContextCallback::arg, tsearch_readline_state::buf, ErrorContextCallback::callback, tsearch_readline_state::cb, tsearch_readline_state::curline, error_context_stack, filename, tsearch_readline_state::filename, tsearch_readline_state::fp, initStringInfo(), tsearch_readline_state::lineno, ErrorContextCallback::previous, and tsearch_readline_callback().

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().

◆ tsearch_readline_end()

void tsearch_readline_end ( tsearch_readline_state stp)

Definition at line 145 of file ts_locale.c.

146{
147 /* Suppress use of curline in any error reported below */
148 if (stp->curline)
149 {
150 if (stp->curline != stp->buf.data)
151 pfree(stp->curline);
152 stp->curline = NULL;
153 }
154
155 /* Release other resources */
156 pfree(stp->buf.data);
157 FreeFile(stp->fp);
158
159 /* Pop the error context stack */
161}
int FreeFile(FILE *file)
Definition: fd.c:2840

References tsearch_readline_state::buf, tsearch_readline_state::cb, tsearch_readline_state::curline, StringInfoData::data, error_context_stack, tsearch_readline_state::fp, FreeFile(), pfree(), and ErrorContextCallback::previous.

Referenced by dsynonym_init(), initTrie(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().