summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValentin Batz <senneth@irssi.org>2006-01-29 22:37:24 +0000
committervb <vb@dbcabf3a-b0e7-0310-adc4-f8d773084564>2006-01-29 22:37:24 +0000
commit0d10e2cc06d952472cc3ce1487180c41762479ca (patch)
treeec094c0c0db15d85ffac97094f91125ec2ca2a5a /src
parenta975788d15f34ad56c82bcc8c08bb4f9de8bbdd8 (diff)
downloadirssi-0d10e2cc06d952472cc3ce1487180c41762479ca.zip
Fixed a bug where tab-complete didn't worked with utf8/big5 multibyte characters properly
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4229 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/utf8.c18
-rw-r--r--src/fe-common/core/utf8.h4
-rw-r--r--src/fe-text/gui-entry.c41
-rw-r--r--src/fe-text/gui-entry.h1
-rw-r--r--src/fe-text/gui-readline.c8
5 files changed, 66 insertions, 6 deletions
diff --git a/src/fe-common/core/utf8.c b/src/fe-common/core/utf8.c
index ae235d34..eaa77674 100644
--- a/src/fe-common/core/utf8.c
+++ b/src/fe-common/core/utf8.c
@@ -182,6 +182,24 @@ void utf16_to_utf8(const unichar *str, char *out)
*out = '\0';
}
+void utf16_to_utf8_with_pos(const unichar *str, int spos, char *out, int *opos)
+{
+ int len;
+ const unichar *sstart = str;
+ char *ostart = out;
+
+ *opos = 0;
+ while (*str != '\0') {
+ len = utf16_char_to_utf8(*str, out);
+ out += len;
+
+ str++;
+ if(str - sstart == spos)
+ *opos = out - ostart;
+ }
+ *out = '\0';
+}
+
static const unichar wcc[] = {
0x0, 0x300, 0x34F, 0x360, 0x363, 0x483, 0x487, 0x488, 0x48A, 0x591,
0x5A2, 0x5A3, 0x5BA, 0x5BB, 0x5BE, 0x5BF, 0x5C0, 0x5C1, 0x5C3, 0x5C4,
diff --git a/src/fe-common/core/utf8.h b/src/fe-common/core/utf8.h
index 996f51f3..f9e3e59e 100644
--- a/src/fe-common/core/utf8.h
+++ b/src/fe-common/core/utf8.h
@@ -18,6 +18,10 @@ int utf16_char_to_utf8(unichar c, char *outbuf);
Make sure out is at least 6 x length of str. */
void utf16_to_utf8(const unichar *str, char *out);
+/* unichar -> UTF-8 string with position transformed. The NUL is copied as well.
+ Make sure out is at least 6 x length of str. */
+void utf16_to_utf8_with_pos(const unichar *str, int spos, char *out, int *opos);
+
/* XXX I didn't check the encoding range of big5+. This is standard big5. */
#define is_big5_los(lo) (0x40 <= (lo) && (lo) <= 0x7E) /* standard */
#define is_big5_lox(lo) (0x80 <= (lo) && (lo) <= 0xFE) /* extended */
diff --git a/src/fe-text/gui-entry.c b/src/fe-text/gui-entry.c
index 6fc5eb18..f63d8269 100644
--- a/src/fe-text/gui-entry.c
+++ b/src/fe-text/gui-entry.c
@@ -97,6 +97,24 @@ int strlen_big5(const unsigned char *str)
return len;
}
+void unichars_to_big5_with_pos(const unichar *str, int spos, char *out, int *opos)
+{
+ const unichar *sstart = str;
+ char *ostart = out;
+
+ *opos = 0;
+ while(*str != '\0')
+ {
+ if(*str > 0xff)
+ *out ++ = (*str >> 8) & 0xff;
+ *out ++ = *str & 0xff;
+ str ++;
+ if(str - sstart == spos)
+ *opos = out - ostart;
+ }
+ *out = '\0';
+}
+
void big5_to_unichars(const char *str, unichar *out)
{
const unsigned char *p = (const unsigned char *) str;
@@ -371,6 +389,29 @@ char *gui_entry_get_text(GUI_ENTRY_REC *entry)
return buf;
}
+char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos)
+{
+ char *buf;
+ int i;
+
+ g_return_val_if_fail(entry != NULL, NULL);
+
+ buf = g_malloc(entry->text_len*6 + 1);
+ if (entry->utf8)
+ utf16_to_utf8_with_pos(entry->text, entry->pos, buf, pos);
+ else {
+ if(term_type==TERM_TYPE_BIG5)
+ unichars_to_big5_with_pos(entry->text, entry->pos, buf, pos);
+ else
+ {
+ for (i = 0; i <= entry->text_len; i++)
+ buf[i] = entry->text[i];
+ *pos = entry->pos;
+ }
+ }
+ return buf;
+}
+
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str)
{
unichar chr;
diff --git a/src/fe-text/gui-entry.h b/src/fe-text/gui-entry.h
index 0c65aae7..e5ab672a 100644
--- a/src/fe-text/gui-entry.h
+++ b/src/fe-text/gui-entry.h
@@ -34,6 +34,7 @@ void gui_entry_set_utf8(GUI_ENTRY_REC *entry, int utf8);
void gui_entry_set_text(GUI_ENTRY_REC *entry, const char *str);
char *gui_entry_get_text(GUI_ENTRY_REC *entry);
+char *gui_entry_get_text_and_pos(GUI_ENTRY_REC *entry, int *pos);
void gui_entry_insert_text(GUI_ENTRY_REC *entry, const char *str);
void gui_entry_insert_char(GUI_ENTRY_REC *entry, unichar chr);
diff --git a/src/fe-text/gui-readline.c b/src/fe-text/gui-readline.c
index d7f8190b..8c1e75db 100644
--- a/src/fe-text/gui-readline.c
+++ b/src/fe-text/gui-readline.c
@@ -778,9 +778,7 @@ static void key_completion(int erase)
char *text, *line;
int pos;
- pos = gui_entry_get_pos(active_entry);
-
- text = gui_entry_get_text(active_entry);
+ text = gui_entry_get_text_and_pos(active_entry, &pos);
line = word_complete(active_win, text, &pos, erase);
g_free(text);
@@ -806,9 +804,7 @@ static void key_check_replaces(void)
char *text, *line;
int pos;
- pos = gui_entry_get_pos(active_entry);
-
- text = gui_entry_get_text(active_entry);
+ text = gui_entry_get_text_and_pos(active_entry, &pos);
line = auto_word_complete(text, &pos);
g_free(text);