From 33528bd690d5e663fb4ae5f0d544ea9a38ed118c Mon Sep 17 00:00:00 2001 From: dequis Date: Thu, 7 May 2015 16:53:58 -0300 Subject: twitter: split length check function into twitter_message_len Mostly to be able to test twitter_message_len externally against the twitter-text conformance tests (the current version definitely fails - it doesn't do utf8 normalization) --- protocols/twitter/twitter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'protocols/twitter/twitter.c') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 421a0552..4debc08a 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -482,17 +482,24 @@ int twitter_url_len_diff(gchar *msg, unsigned int target_len) return url_len_diff; } -static gboolean twitter_length_check(struct im_connection *ic, gchar * msg) +int twitter_message_len(gchar *msg, int target_len) { - int max = set_getint(&ic->acc->set, "message_length"), len; - int target_len = set_getint(&ic->acc->set, "target_url_length"); int url_len_diff = 0; if (target_len > 0) { url_len_diff = twitter_url_len_diff(msg, target_len); } - if (max == 0 || (len = g_utf8_strlen(msg, -1) + url_len_diff) <= max) { + return g_utf8_strlen(msg, -1) + url_len_diff; +} + +static gboolean twitter_length_check(struct im_connection *ic, gchar * msg) +{ + int max = set_getint(&ic->acc->set, "message_length"); + int target_len = set_getint(&ic->acc->set, "target_url_length"); + int len = twitter_message_len(msg, target_len); + + if (max == 0 || len <= max) { return TRUE; } -- cgit v1.2.3