Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Functions

ts_locale.h File Reference

#include <ctype.h>
#include <limits.h>
#include "utils/pg_locale.h"
#include "mb/pg_wchar.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

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 Documentation

#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().

#define t_iseq (   x,
  c 
)    (TOUCHAR(x) == (unsigned char) (c))
#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))
#define TOUCHAR (   x  )     (*((const unsigned char *) (x)))

Definition at line 42 of file ts_locale.h.

Referenced by lowerstr_with_len().


Function Documentation

char* lowerstr ( const char *  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  ) 
bool tsearch_readline_begin ( tsearch_readline_state stp,
const char *  filename 
)
void tsearch_readline_end ( tsearch_readline_state stp  )