PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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   ts_copychar_cstr
 
#define GENERATE_T_ISCLASS_DECL(character_class)
 

Functions

static int ts_copychar_with_len (void *dest, const void *src, int length)
 
static int ts_copychar_cstr (void *dest, const void *src)
 
 GENERATE_T_ISCLASS_DECL (alnum)
 
 GENERATE_T_ISCLASS_DECL (alpha)
 
bool tsearch_readline_begin (tsearch_readline_state *stp, const char *filename)
 
chartsearch_readline (tsearch_readline_state *stp)
 
void tsearch_readline_end (tsearch_readline_state *stp)
 

Macro Definition Documentation

◆ COPYCHAR

#define COPYCHAR   ts_copychar_cstr

Definition at line 56 of file ts_locale.h.

◆ GENERATE_T_ISCLASS_DECL

#define GENERATE_T_ISCLASS_DECL (   character_class)
Value:
extern int t_is##character_class##_with_len(const char *ptr, int len); \
extern int t_is##character_class##_cstr(const char *ptr); \
extern int t_is##character_class##_unbounded(const char *ptr); \
\
/* deprecated */ \
extern int t_is##character_class(const char *ptr);
const void size_t len
static int fb(int x)

Definition at line 58 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

◆ GENERATE_T_ISCLASS_DECL() [1/2]

GENERATE_T_ISCLASS_DECL ( alnum  )

◆ GENERATE_T_ISCLASS_DECL() [2/2]

GENERATE_T_ISCLASS_DECL ( alpha  )

◆ ts_copychar_cstr()

static int ts_copychar_cstr ( void dest,
const void src 
)
inlinestatic

Definition at line 50 of file ts_locale.h.

51{
52 return ts_copychar_with_len(dest, src, pg_mblen_cstr((const char *) src));
53}
int pg_mblen_cstr(const char *mbstr)
Definition mbutils.c:1045
static int ts_copychar_with_len(void *dest, const void *src, int length)
Definition ts_locale.h:42

References pg_mblen_cstr(), and ts_copychar_with_len().

Referenced by addCompoundAffixFlagValue(), getNextFlagFromString(), gettoken_tsvector(), infix(), and RS_compile().

◆ ts_copychar_with_len()

static int ts_copychar_with_len ( void dest,
const void src,
int  length 
)
inlinestatic

Definition at line 42 of file ts_locale.h.

43{
44 memcpy(dest, src, length);
45 return length;
46}

References fb().

Referenced by get_nextfield(), parse_affentry(), and ts_copychar_cstr().

◆ tsearch_readline()

char * tsearch_readline ( tsearch_readline_state stp)
extern

Definition at line 108 of file ts_locale.c.

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

References fb(), 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 
)
extern

Definition at line 85 of file ts_locale.c.

87{
88 if ((stp->fp = AllocateFile(filename, "r")) == NULL)
89 return false;
90 stp->filename = filename;
91 stp->lineno = 0;
92 initStringInfo(&stp->buf);
93 stp->curline = NULL;
94 /* Setup error traceback support for ereport() */
95 stp->cb.callback = tsearch_readline_callback;
96 stp->cb.arg = stp;
97 stp->cb.previous = error_context_stack;
99 return true;
100}
ErrorContextCallback * error_context_stack
Definition elog.c:99
FILE * AllocateFile(const char *name, const char *mode)
Definition fd.c:2627
static char * filename
Definition pg_dumpall.c:132
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
static void tsearch_readline_callback(void *arg)
Definition ts_locale.c:176

References AllocateFile(), error_context_stack, fb(), filename, initStringInfo(), 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)
extern

Definition at line 153 of file ts_locale.c.

154{
155 /* Suppress use of curline in any error reported below */
156 if (stp->curline)
157 {
158 if (stp->curline != stp->buf.data)
159 pfree(stp->curline);
160 stp->curline = NULL;
161 }
162
163 /* Release other resources */
164 pfree(stp->buf.data);
165 FreeFile(stp->fp);
166
167 /* Pop the error context stack */
169}
int FreeFile(FILE *file)
Definition fd.c:2826
struct ErrorContextCallback * previous
Definition elog.h:297

References error_context_stack, fb(), FreeFile(), pfree(), and ErrorContextCallback::previous.

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