#include "postgres.h"#include "catalog/pg_collation.h"#include "storage/fd.h"#include "tsearch/ts_locale.h"#include "tsearch/ts_public.h"
Go to the source code of this file.
Functions | |
| static void | tsearch_readline_callback (void *arg) |
| 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) |
| char * | lowerstr (const char *str) |
| char * | lowerstr_with_len (const char *str, int 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;
}
| static void tsearch_readline_callback | ( | void * | arg | ) | [static] |
Definition at line 165 of file ts_locale.c.
References tsearch_readline_state::curline, errcontext, tsearch_readline_state::filename, and tsearch_readline_state::lineno.
{
tsearch_readline_state *stp = (tsearch_readline_state *) arg;
/*
* We can't include the text of the config line for errors that occur
* during t_readline() itself. This is only partly a consequence of our
* arms-length use of that routine: the major cause of such errors is
* encoding violations, and we daren't try to print error messages
* containing badly-encoded data.
*/
if (stp->curline)
errcontext("line %d of configuration file \"%s\": \"%s\"",
stp->lineno,
stp->filename,
stp->curline);
else
errcontext("line %d of configuration file \"%s\"",
stp->lineno,
stp->filename);
}
| 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