summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTingPing <TingPing@users.noreply.github.com>2013-09-24 19:57:37 -0400
committerTingPing <TingPing@users.noreply.github.com>2013-09-24 19:57:37 -0400
commitf198581a09f12df2b816243168a6ef25027c7c08 (patch)
treef0da019483ae7a15237c7a6fcbbc63c2120c0037
parent4c9b193b45a78d0e15de5273143f559a74f6be06 (diff)
Split long messages at spaces
-rw-r--r--src/common/outbound.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/common/outbound.c b/src/common/outbound.c
index 936e0ede..cd0cd021 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -2569,7 +2569,8 @@ cmd_load (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 char *
 split_up_text(struct session *sess, char *text, int cmd_length, char *split_text)
 {
-	unsigned int max;
+	unsigned int max, space_offset;
+	char *space;
 
 	/* maximum allowed text */
 	/* :nickname!username@host.com cmd_length */
@@ -2602,6 +2603,17 @@ split_up_text(struct session *sess, char *text, int cmd_length, char *split_text
 		}
 		max = i;
 
+		/* Try splitting at last space */
+		space = g_utf8_strrchr (text, max, ' ');
+		if (space)
+		{
+			space_offset = g_utf8_pointer_to_offset (text, space);
+
+			/* Only split if last word is of sane length */
+			if (max != space_offset && max - space_offset < 20)
+				max = space_offset + 1;
+		}
+
 		split_text = g_strdup_printf ("%.*s", max, text);
 
 		return split_text;