From 79dff42fe11d4130b23d838471422daf0cd3f57d Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Sun, 19 Aug 2012 02:52:22 +0200 Subject: [PATCH] strtrim -> strtrim_end --- dunst.c | 16 ++++++++++------ utils.c | 8 +------- utils.h | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/dunst.c b/dunst.c index ea21159..ed3294a 100644 --- a/dunst.c +++ b/dunst.c @@ -365,7 +365,7 @@ void update_lists() /* TODO get draw_txt_buf as argument */ int do_word_wrap(char *source, int max_width) { - strtrim(source); + strtrim_end(source); if (!source || source == '\0' || strcmp(source, "") == 0) return 0; @@ -406,9 +406,14 @@ int do_word_wrap(char *source, int max_width) void update_draw_txt_buf(notification * n, int max_width) { + strtrim_end(n->msg); + char *msg = n->msg; + while(isspace(*msg)) + msg++; + if (!n->draw_txt_buf.txt) { int dup_len = strlen(" () ") + digit_count(INT_MAX); - int msg_len = strlen(n->msg) + 2; /* 2 == surrounding spaces */ + int msg_len = strlen(msg) + 2; /* 2 == surrounding spaces */ int age_len = strlen(" ( h 60m 60s old ) ") + digit_count(INT_MAX); /* could be INT_MAX hours */ int line_length = dup_len + msg_len + age_len; @@ -432,7 +437,7 @@ void update_draw_txt_buf(notification * n, int max_width) } /* print msg */ - strncat(buf, n->msg, bufsize - strlen(buf)); + strncat(buf, msg, bufsize - strlen(buf)); next = buf + strlen(buf); /* print age */ @@ -825,7 +830,6 @@ int init_notification(notification * n, int id) n->msg = string_replace("%b", n->body, n->msg); n->msg = fix_markup(n->msg); - n->msg = strtrim(n->msg); n->dup_count = 0; n->draw_txt_buf.txt = NULL; @@ -980,10 +984,10 @@ void init_shortcut(keyboard_shortcut * ks) str++; *str = '\0'; str++; - strtrim(mod); + strtrim_end(mod); ks->mask = ks->mask | string_to_mask(mod); } - strtrim(str); + strtrim_end(str); ks->sym = XStringToKeysym(str); ks->code = XKeysymToKeycode(dc->dpy, ks->sym); diff --git a/utils.c b/utils.c index 43cad77..82575b4 100644 --- a/utils.c +++ b/utils.c @@ -7,20 +7,14 @@ #include "dunst.h" -char *strtrim(char *str) +void strtrim_end(char *str) { char *end; - while (isspace(*str)) - str++; - end = str + strlen(str) - 1; while (isspace(*end)) { *end = '\0'; end--; } - - return str; - } char *string_replace(const char *needle, const char *replacement, diff --git a/utils.h b/utils.h index 4f76fa1..e403b31 100644 --- a/utils.h +++ b/utils.h @@ -1,7 +1,7 @@ #ifndef UTIL_H #define UTIL_H /* remove spaces before and after str */ -char *strtrim(char *str); +void strtrim_end(char *str); /* replace needle with replacement in haystack */ char *string_replace(const char *needle, const char *replacement,