From 0367d94aad98534aa4d997c7cb9fb85b44063c74 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 19 Aug 2016 05:06:45 -0700 Subject: [PATCH] Util: Add rtrim --- CHANGES | 1 + src/util/string.c | 11 +++++++++++ src/util/string.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/CHANGES b/CHANGES index b6a5b67ff..d8a31f1cf 100644 --- a/CHANGES +++ b/CHANGES @@ -62,6 +62,7 @@ Misc: - Qt: Remove default autofire mappings - PSP2: Allow UTF-8 filenames - Util: Add Vector GetConstPointer + - Util: Add rtrim 0.4.1: (2016-07-11) Bugfixes: diff --git a/src/util/string.c b/src/util/string.c index 438a1b683..6d7795f77 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -340,3 +340,14 @@ const char* hex4(const char* line, uint8_t* out) { *out = value; return line; } + +void rtrim(char* string) { + if (!*string) { + return; + } + char* end = string + strlen(string) - 1; + while (isspace((int) *end) && end >= string) { + *end = '\0'; + --end; + } +} diff --git a/src/util/string.h b/src/util/string.h index 44ee79a35..5c4f8bb43 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -33,4 +33,6 @@ const char* hex12(const char* line, uint16_t* out); const char* hex8(const char* line, uint8_t* out); const char* hex4(const char* line, uint8_t* out); +void rtrim(char* string); + #endif