From e5dbc33b2959cc07e95133a8571ce735d83ab2f7 Mon Sep 17 00:00:00 2001 From: Albert Cahalan Date: Tue, 23 Nov 2004 18:37:59 +0000 Subject: [PATCH] simplify strip_trailing_whitespace, now O(n) --- docs/CHANGES.txt | 4 ++++ src/tuxpaint.c | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index 74d66a8d3..f0c8f9e21 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -7,6 +7,10 @@ bill@newbreedsoftware.com http://www.newbreedsoftware.com/tuxpaint/ +2004.November.23 (0.9.15) + * simplify strip_trailing_whitespace, now O(n) + Albert Cahalan + 2004.November.22 (0.9.15) * Enable more compuler warnings, and update code to prevent them. Albert Cahalan diff --git a/src/tuxpaint.c b/src/tuxpaint.c index 53fb9c116..d5656e8e5 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -8249,11 +8249,11 @@ static Mix_Chunk * loadsound(const char * const fname) static void strip_trailing_whitespace( char *buf ) { - while (buf[strlen(buf) - 1] == ' ' || - buf[strlen(buf) - 1] == '\r' || - buf[strlen(buf) - 1] == '\n') + unsigned i = strlen(buf); + while(i--) { - buf[strlen(buf) - 1] = '\0'; + if(!isspace(buf[i])) break; + buf[i] = '\0'; } }