Commit e8c32050 authored by Tatsuo Ishii's avatar Tatsuo Ishii

Add PQmbdsplen() which returns the "display length" of a character.

Still some works needed:
- UTF-8, MULE_INTERNAL always returns 1
parent 1bc2d544
......@@ -4,7 +4,7 @@
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
*
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.45 2003/11/29 19:52:02 pgsql Exp $
* $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.46 2004/03/15 10:41:25 ishii Exp $
*/
#include "postgres.h"
......@@ -463,6 +463,13 @@ pg_mblen(const unsigned char *mbstr)
return ((*pg_wchar_table[DatabaseEncoding->encoding].mblen) (mbstr));
}
/* returns the display length of a multibyte word */
int
pg_dsplen(const unsigned char *mbstr)
{
return ((*pg_wchar_table[DatabaseEncoding->encoding].dsplen) (mbstr));
}
/* returns the length (counted as a wchar) of a multibyte string */
int
pg_mbstrlen(const unsigned char *mbstr)
......
This diff is collapsed.
......@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.83 2004/03/14 04:25:17 tgl Exp $
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.84 2004/03/15 10:41:26 ishii Exp $
*/
#include "postgres_fe.h"
#include "common.h"
......@@ -410,7 +410,7 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query)
{
qidx[i] = qoffset;
scridx[i] = scroffset;
scroffset += 1; /* XXX fix me when we have screen width info */
scroffset += PQdsplen(&query[qoffset], pset.encoding);
qoffset += PQmblen(&query[qoffset], pset.encoding);
}
qidx[i] = qoffset;
......@@ -526,7 +526,7 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query)
scroffset = 0;
for (i = 0; i < msg.len; i += PQmblen(&msg.data[i], pset.encoding))
{
scroffset += 1; /* XXX fix me when we have screen width info */
scroffset += PQdsplen(&msg.data[i], pset.encoding);
}
/* Finish and emit the message. */
......
/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.49 2003/11/29 22:41:04 pgsql Exp $ */
/* $PostgreSQL: pgsql/src/include/mb/pg_wchar.h,v 1.50 2004/03/15 10:41:26 ishii Exp $ */
#ifndef PG_WCHAR_H
#define PG_WCHAR_H
......@@ -248,11 +248,14 @@ typedef int (*mb2wchar_with_len_converter) (const unsigned char *from,
int len);
typedef int (*mblen_converter) (const unsigned char *mbstr);
typedef int (*mbdisplaylen_converter) (const unsigned char *mbstr);
typedef struct
{
mb2wchar_with_len_converter mb2wchar_with_len; /* convert a multibyte
* string to a wchar */
mblen_converter mblen; /* returns the length of a multibyte char */
mbdisplaylen_converter dsplen; /* returns the lenghth of a display length */
int maxmblen; /* max bytes for a char in this charset */
} pg_wchar_tbl;
......@@ -283,7 +286,9 @@ extern int pg_wchar_strncmp(const pg_wchar *s1, const pg_wchar *s2, size_t n);
extern int pg_char_and_wchar_strncmp(const char *s1, const pg_wchar *s2, size_t n);
extern size_t pg_wchar_strlen(const pg_wchar *wstr);
extern int pg_mblen(const unsigned char *mbstr);
extern int pg_dsplen(const unsigned char *mbstr);
extern int pg_encoding_mblen(int encoding, const unsigned char *mbstr);
extern int pg_encoding_dsplen(int encoding, const unsigned char *mbstr);
extern int pg_mule_mblen(const unsigned char *mbstr);
extern int pg_mic_mblen(const unsigned char *mbstr);
extern int pg_mbstrlen(const unsigned char *mbstr);
......
......@@ -23,7 +23,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.104 2003/11/29 19:52:12 pgsql Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.105 2004/03/15 10:41:26 ishii Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -1095,6 +1095,16 @@ PQmblen(const unsigned char *s, int encoding)
return (pg_encoding_mblen(encoding, s));
}
/*
* returns the display length of the word beginning s, using the
* specified encoding.
*/
int
PQdsplen(const unsigned char *s, int encoding)
{
return (pg_encoding_dsplen(encoding, s));
}
/*
* Get encoding id from environment variable PGCLIENTENCODING.
*/
......
......@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.102 2004/01/09 02:02:43 momjian Exp $
* $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.103 2004/03/15 10:41:26 ishii Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -447,6 +447,9 @@ extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
/* Determine length of multibyte encoded char at *s */
extern int PQmblen(const unsigned char *s, int encoding);
/* Determine display length of multibyte encoded char at *s */
extern int PQdsplen(const unsigned char *s, int encoding);
/* Get encoding id from environment variable PGCLIENTENCODING */
extern int PQenv2encoding(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment