summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/wee-command.c4
-rw-r--r--src/core/wee-debug.c60
-rw-r--r--src/core/wee-debug.h2
3 files changed, 60 insertions, 6 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 7dbb0d729..c74ac1625 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -2032,7 +2032,7 @@ COMMAND_CALLBACK(debug)
result = eval_expression (argv_eol[2], NULL, NULL, NULL);
if (result)
{
- debug_unicode_string (result);
+ debug_unicode (result);
free (result);
}
return WEECHAT_RC_OK;
@@ -7696,7 +7696,7 @@ command_init ()
" windows: display windows tree\n"
" time: measure time to execute a command or to send text to "
"the current buffer\n"
- " unicode: display information about unicode chars in string "
+ " unicode: display information about string and unicode chars "
"(evaluated, see /help eval)\n"
"\n"
"Examples:\n"
diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c
index 279a8171a..924de8894 100644
--- a/src/core/wee-debug.c
+++ b/src/core/wee-debug.c
@@ -762,7 +762,7 @@ debug_display_time_elapsed (struct timeval *time1, struct timeval *time2,
}
/*
- * Display information about a unicode codepoint.
+ * Display unicode information for a codepoint.
*/
void
@@ -813,16 +813,71 @@ debug_unicode_char (unsigned int codepoint)
}
/*
- * Display information about all unicode chars of a string.
+ * Display unicode information for a string.
*/
void
debug_unicode_string (const char *string)
{
+ int num_char, width;
+ wchar_t *wstring;
+
+ num_char = mbstowcs (NULL, string, 0) + 1;
+ wstring = malloc ((num_char + 1) * sizeof (wstring[0]));
+ if (!wstring)
+ return;
+
+ if (mbstowcs (wstring, string, num_char) == (size_t)(-1))
+ {
+ free (wstring);
+ return;
+ }
+
+ width = wcswidth (wstring, num_char);
+
+ gui_chat_printf (NULL,
+ "\t \"%s\": %d %s/%s %d, %d %s/%s %d, %d, %d",
+ string,
+ strlen (string),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ utf8_strlen (string),
+ gui_chat_strlen (string),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ width,
+ utf8_strlen_screen (string),
+ gui_chat_strlen_screen (string));
+
+ free (wstring);
+}
+
+/*
+ * Display information about all unicode chars of a string.
+ */
+
+void
+debug_unicode (const char *string)
+{
const char *ptr_string;
if (!string || !string[0])
return;
+ /* info about string */
+ gui_chat_printf (NULL, "");
+ gui_chat_printf (NULL,
+ _("Unicode: \"string\": "
+ "strlen %s/%s "
+ "utf8_strlen, gui_chat_strlen %s/%s "
+ "wcswidth, utf8_strlen_screen, "
+ "gui_chat_strlen_screen:"),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT),
+ GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
+ GUI_COLOR(GUI_COLOR_CHAT));
+ debug_unicode_string (string);
+
+ /* info about chars in string */
gui_chat_printf (NULL, "");
gui_chat_printf (NULL,
_("Unicode: \"char\" "
@@ -835,7 +890,6 @@ debug_unicode_string (const char *string)
GUI_COLOR(GUI_COLOR_CHAT),
GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS),
GUI_COLOR(GUI_COLOR_CHAT));
-
ptr_string = string;
while (ptr_string && ptr_string[0])
{
diff --git a/src/core/wee-debug.h b/src/core/wee-debug.h
index 16351482a..ade3cac9b 100644
--- a/src/core/wee-debug.h
+++ b/src/core/wee-debug.h
@@ -36,7 +36,7 @@ extern void debug_display_time_elapsed (struct timeval *time1,
struct timeval *time2,
const char *message,
int display);
-extern void debug_unicode_string (const char *string);
+extern void debug_unicode (const char *string);
extern void debug_init ();
extern void debug_end ();