Hi. Thank you for the comments.

The revised version is attaced.

 - A typo is fixed in the comment for PQmblen().
 - Do the same fix to PQdsplen().



At Thu, 5 Nov 2015 18:32:59 +0900, Amit Langote <langote_amit...@lab.ntt.co.jp> 
wrote in <563b224b.3020...@lab.ntt.co.jp>
> On 2015/11/05 18:10, Kyotaro HORIGUCHI wrote:
> > Hello. I don't know whether this is a bug fix or improvement,
> 
> Would it be 50-50? :-)

Yeah, honestly saying, I doubt that this is valuable but feel
uneasy to see some of the candidates vanish as completon proceeds
for no persuasive reason.

> In the following change,
> 
> - * returns the byte length of the word beginning s, using the
> - * specified encoding.
> + * returns the byte length of the character beginning s, using the specified
> + * encoding.
> 
> 
> Just a minor nitpick -
> 
> ... character beginning *at* s ...?
> 
> If so, there would be one more instance to fix.

I think so.  I overlooked both of them. And as you mention,
PQdsplen has the same kind of typo. It returns display length of
the *character* beginning *at* s, too.

regards,

-- 
Kyotaro Horiguchi
NTT Open Source Software Center
>From 5a4bd365f6353f72198cb59bdf390d2968a03e36 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyot...@lab.ntt.co.jp>
Date: Mon, 2 Nov 2015 12:46:45 +0900
Subject: [PATCH] Fix identifier completion of multibyte characters.

_copletion_from_query took the byte length of the given text as its
character length. This should be counted in the environmental
encoding.

This patch also fixes a comment for PQmblen and PQdsplen.
---
 src/bin/psql/tab-complete.c    | 13 ++++++++++---
 src/interfaces/libpq/fe-misc.c |  6 +++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 0e8d395..e6e22c4 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -4283,8 +4283,8 @@ complete_from_schema_query(const char *text, int state)
 static char *
 _complete_from_query(int is_schema_query, const char *text, int state)
 {
-	static int	list_index,
-				string_length;
+	static int	list_index;
+	int 		string_length = 0;
 	static PGresult *result = NULL;
 
 	/*
@@ -4297,9 +4297,16 @@ _complete_from_query(int is_schema_query, const char *text, int state)
 		char	   *e_text;
 		char	   *e_info_charp;
 		char	   *e_info_charp2;
+		const char *pstr = text;
 
 		list_index = 0;
-		string_length = strlen(text);
+
+		/* count length as a multibyte text */
+		while (*pstr)
+		{
+			string_length++;
+			pstr += PQmblen(pstr, pset.encoding);
+		}
 
 		/* Free any prior result */
 		PQclear(result);
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 0dbcf73..950634a 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -1,4 +1,4 @@
-/*-------------------------------------------------------------------------
+m/*-------------------------------------------------------------------------
  *
  *	 FILE
  *		fe-misc.c
@@ -1179,7 +1179,7 @@ pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
  */
 
 /*
- * returns the byte length of the word beginning s, using the
+ * returns the byte length of the character beginning at s, using the
  * specified encoding.
  */
 int
@@ -1189,7 +1189,7 @@ PQmblen(const char *s, int encoding)
 }
 
 /*
- * returns the display length of the word beginning s, using the
+ * returns the display length of the character beginning at s, using the
  * specified encoding.
  */
 int
-- 
1.8.3.1

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to