[pacman-dev] [PATCH] Refactor strtrim function

Silvan Jegen s.jegen at gmail.com
Mon Nov 9 17:43:40 UTC 2015


Signed-off-by: Silvan Jegen <s.jegen at gmail.com>
---
 src/common/util-common.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/common/util-common.c b/src/common/util-common.c
index 542dcfd..0b67d85 100644
--- a/src/common/util-common.c
+++ b/src/common/util-common.c
@@ -144,17 +144,13 @@ size_t strtrim(char *str)
 	}
 	if(pch != str) {
 		size_t len = strlen(pch);
-		if(len) {
-			memmove(str, pch, len + 1);
-			pch = str;
-		} else {
+		/* check if there wasn't anything but whitespace in the string. */
+		if(len == 0) {
 			*str = '\0';
+			return 0;
 		}
-	}
-
-	/* check if there wasn't anything but whitespace in the string. */
-	if(*str == '\0') {
-		return 0;
+		memmove(str, pch, len + 1);
+		pch = str;
 	}
 
 	end = (str + strlen(str) - 1);
-- 
2.6.2


More information about the pacman-dev mailing list