#include <ctype.h>#include <limits.h>#include "utils/pg_locale.h"#include "mb/pg_wchar.h"

Go to the source code of this file.
Data Structures | |
| struct | tsearch_readline_state |
Defines | |
| #define | TOUCHAR(x) (*((const unsigned char *) (x))) |
| #define | t_isdigit(x) isdigit(TOUCHAR(x)) |
| #define | t_isspace(x) isspace(TOUCHAR(x)) |
| #define | t_isalpha(x) isalpha(TOUCHAR(x)) |
| #define | t_isprint(x) isprint(TOUCHAR(x)) |
| #define | t_iseq(x, c) (TOUCHAR(x) == (unsigned char) (c)) |
| #define | COPYCHAR(d, s) (*((unsigned char *) (d)) = TOUCHAR(s)) |
Functions | |
| char * | lowerstr (const char *str) |
| char * | lowerstr_with_len (const char *str, int len) |
| 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) |
| char * | t_readline (FILE *fp) |
| #define COPYCHAR | ( | d, | ||
| s | ||||
| ) | (*((unsigned char *) (d)) = TOUCHAR(s)) |
Definition at line 63 of file ts_locale.h.
Referenced by gettoken_tsvector(), infix(), parse_affentry(), and RS_compile().
| #define t_isalpha | ( | x | ) | isalpha(TOUCHAR(x)) |
Definition at line 59 of file ts_locale.h.
Referenced by parse_affentry(), RS_compile(), and RS_isRegis().
| #define t_isdigit | ( | x | ) | isdigit(TOUCHAR(x)) |
Definition at line 57 of file ts_locale.h.
Referenced by gettoken_tsvector(), and lquery_in().
Definition at line 61 of file ts_locale.h.
Referenced by findchar(), findwrd(), get_modifiers(), getlexeme(), gettoken_query(), gettoken_tsvector(), infix(), lquery_in(), ltree_in(), NIImportOOAffixes(), parse_affentry(), RS_compile(), RS_isRegis(), thesaurusRead(), and tsvectorout().
| #define t_isprint | ( | x | ) | isprint(TOUCHAR(x)) |
Definition at line 60 of file ts_locale.h.
Referenced by NIImportDictionary().
| #define t_isspace | ( | x | ) | isspace(TOUCHAR(x)) |
Definition at line 58 of file ts_locale.h.
Referenced by addFlagValue(), find_word(), findwrd(), gettoken_query(), gettoken_tsvector(), initSuffixTree(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), parse_affentry(), readstoplist(), and thesaurusRead().
| #define TOUCHAR | ( | x | ) | (*((const unsigned char *) (x))) |
Definition at line 42 of file ts_locale.h.
Referenced by lowerstr_with_len().
| char* lowerstr | ( | const char * | str | ) |
Definition at line 234 of file ts_locale.c.
References lowerstr_with_len().
Referenced by convertPgWchar(), dispell_init(), dsimple_init(), dsnowball_init(), dsynonym_init(), dxsyn_lexize(), lowerstr_ctx(), NIImportAffixes(), and read_dictionary().
{
return lowerstr_with_len(str, strlen(str));
}
| char* lowerstr_with_len | ( | const char * | str, | |
| int | len | |||
| ) |
Definition at line 247 of file ts_locale.c.
References Assert, ereport, errcode(), errmsg(), ERROR, lc_ctype_is_c(), palloc(), pfree(), pg_database_encoding_max_length(), pstrdup(), and TOUCHAR.
Referenced by dispell_lexize(), dsimple_lexize(), dsnowball_lexize(), dsynonym_lexize(), generate_trgm(), generate_wildcard_trgm(), and lowerstr().
{
char *out;
#ifdef USE_WIDE_UPPER_LOWER
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
pg_locale_t mylocale = 0; /* TODO */
#endif
if (len == 0)
return pstrdup("");
#ifdef USE_WIDE_UPPER_LOWER
/*
* Use wide char code only when max encoding length > 1 and ctype != C.
* Some operating systems fail with multi-byte encodings and a C locale.
* Also, for a C locale there is no need to process as multibyte. From
* backend/utils/adt/oracle_compat.c Teodor
*/
if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c(collation))
{
wchar_t *wstr,
*wptr;
int wlen;
/*
* alloc number of wchar_t for worst case, len contains number of
* bytes >= number of characters and alloc 1 wchar_t for 0, because
* wchar2char wants zero-terminated string
*/
wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len + 1));
wlen = char2wchar(wstr, len + 1, str, len, mylocale);
Assert(wlen <= len);
while (*wptr)
{
*wptr = towlower((wint_t) *wptr);
wptr++;
}
/*
* Alloc result string for worst case + '\0'
*/
len = pg_database_encoding_max_length() * wlen + 1;
out = (char *) palloc(len);
wlen = wchar2char(out, wstr, len, mylocale);
pfree(wstr);
if (wlen < 0)
ereport(ERROR,
(errcode(ERRCODE_CHARACTER_NOT_IN_REPERTOIRE),
errmsg("conversion from wchar_t to server encoding failed: %m")));
Assert(wlen < len);
}
else
#endif /* USE_WIDE_UPPER_LOWER */
{
const char *ptr = str;
char *outptr;
outptr = out = (char *) palloc(sizeof(char) * (len + 1));
while ((ptr - str) < len && *ptr)
{
*outptr++ = tolower(TOUCHAR(ptr));
ptr++;
}
*outptr = '\0';
}
return out;
}
| char* t_readline | ( | FILE * | fp | ) |
Definition at line 197 of file ts_locale.c.
References buf, GetDatabaseEncoding(), NULL, pg_do_encoding_conversion(), PG_UTF8, pg_verify_mbstr(), and pnstrdup().
Referenced by tsearch_readline().
{
int len;
char *recoded;
char buf[4096]; /* lines must not be longer than this */
if (fgets(buf, sizeof(buf), fp) == NULL)
return NULL;
len = strlen(buf);
/* Make sure the input is valid UTF-8 */
(void) pg_verify_mbstr(PG_UTF8, buf, len, false);
/* And convert */
recoded = (char *) pg_do_encoding_conversion((unsigned char *) buf,
len,
PG_UTF8,
GetDatabaseEncoding());
if (recoded == buf)
{
/*
* conversion didn't pstrdup, so we must. We can use the length of the
* original string, because no conversion was done.
*/
recoded = pnstrdup(recoded, len);
}
return recoded;
}
| char* tsearch_readline | ( | tsearch_readline_state * | stp | ) |
Definition at line 138 of file ts_locale.c.
References tsearch_readline_state::curline, tsearch_readline_state::fp, tsearch_readline_state::lineno, and t_readline().
Referenced by dsynonym_init(), initSuffixTree(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().
{
char *result;
stp->lineno++;
stp->curline = NULL;
result = t_readline(stp->fp);
stp->curline = result;
return result;
}
| bool tsearch_readline_begin | ( | tsearch_readline_state * | stp, | |
| const char * | filename | |||
| ) |
Definition at line 116 of file ts_locale.c.
References AllocateFile(), ErrorContextCallback::arg, ErrorContextCallback::callback, tsearch_readline_state::cb, tsearch_readline_state::curline, error_context_stack, tsearch_readline_state::filename, tsearch_readline_state::fp, tsearch_readline_state::lineno, NULL, and ErrorContextCallback::previous.
Referenced by dsynonym_init(), initSuffixTree(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().
{
if ((stp->fp = AllocateFile(filename, "r")) == NULL)
return false;
stp->filename = filename;
stp->lineno = 0;
stp->curline = NULL;
/* Setup error traceback support for ereport() */
stp->cb.callback = tsearch_readline_callback;
stp->cb.arg = (void *) stp;
stp->cb.previous = error_context_stack;
error_context_stack = &stp->cb;
return true;
}
| void tsearch_readline_end | ( | tsearch_readline_state * | stp | ) |
Definition at line 153 of file ts_locale.c.
References tsearch_readline_state::cb, error_context_stack, tsearch_readline_state::fp, FreeFile(), and ErrorContextCallback::previous.
Referenced by dsynonym_init(), initSuffixTree(), NIImportAffixes(), NIImportDictionary(), NIImportOOAffixes(), read_dictionary(), readstoplist(), and thesaurusRead().
{
FreeFile(stp->fp);
/* Pop the error context stack */
error_context_stack = stp->cb.previous;
}
1.7.1