From 5a55772201829dc0055cc8d3022cc475ccbc2643 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Sun, 8 Feb 2009 11:09:55 +0000 Subject: Small code reuse improvement git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19943 a1c6a512-1295-4272-9138-f99709370657 --- apps/cuesheet.c | 9 --------- apps/metadata/metadata_common.c | 15 +++------------ apps/misc.c | 16 ++++++++++++---- apps/misc.h | 2 +- apps/replaygain.c | 5 +---- 5 files changed, 17 insertions(+), 30 deletions(-) (limited to 'apps') diff --git a/apps/cuesheet.c b/apps/cuesheet.c index 0a7521bbc5..1acb9af5cf 100644 --- a/apps/cuesheet.c +++ b/apps/cuesheet.c @@ -108,15 +108,6 @@ bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path) return true; } -static char *skip_whitespace(char* buf) -{ - char *r = buf; - while (*r && isspace(*r)) - r++; - return r; -} - - static char *get_string(const char *line) { char *start, *end; diff --git a/apps/metadata/metadata_common.c b/apps/metadata/metadata_common.c index 94ff212cea..09f0f94a88 100644 --- a/apps/metadata/metadata_common.c +++ b/apps/metadata/metadata_common.c @@ -29,6 +29,7 @@ #include "metadata_common.h" #include "metadata_parsers.h" #include "replaygain.h" +#include "misc.h" /* Skip an ID3v2 tag if it can be found. We assume the tag is located at the * start of the file, which should be true in all cases where we need to skip it. @@ -173,16 +174,6 @@ long get_slong(void* buf) return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); } -static char* skip_space(char* str) -{ - while (isspace(*str)) - { - str++; - } - - return str; -} - unsigned long get_itunes_int32(char* value, int count) { static const char hexdigits[] = "0123456789ABCDEF"; @@ -191,7 +182,7 @@ unsigned long get_itunes_int32(char* value, int count) while (count-- > 0) { - value = skip_space(value); + value = skip_whitespace(value); while (*value && !isspace(*value)) { @@ -199,7 +190,7 @@ unsigned long get_itunes_int32(char* value, int count) } } - value = skip_space(value); + value = skip_whitespace(value); while (*value && ((c = strchr(hexdigits, toupper(*value))) != NULL)) { diff --git a/apps/misc.c b/apps/misc.c index 1410d47244..6e871acd3b 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -605,8 +605,7 @@ bool settings_parseline(char* line, char** name, char** value) { char* ptr; - while ( isspace(*line) ) - line++; + line = skip_whitespace(line); if ( *line == '#' ) return false; @@ -618,8 +617,7 @@ bool settings_parseline(char* line, char** name, char** value) *name = line; *ptr = 0; ptr++; - while (isspace(*ptr)) - ptr++; + ptr = skip_whitespace(ptr); *value = ptr; return true; } @@ -1123,6 +1121,16 @@ char* strrsplt(char* str, int c) return s; } +char* skip_whitespace(char* const str) +{ + char *s = str; + + while (isspace(*s)) + s++; + + return s; +} + /* Test file existence, using dircache of possible */ bool file_exists(const char *file) { diff --git a/apps/misc.h b/apps/misc.h index 6a6e847a16..22ae4849a4 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -124,7 +124,7 @@ int hex_to_rgb(const char* hex, int* color); #endif char* strrsplt(char* str, int c); - +char* skip_whitespace(char* const str); bool file_exists(const char *file); bool dir_exists(const char *path); diff --git a/apps/replaygain.c b/apps/replaygain.c index e0bfc8e64e..93bf384539 100644 --- a/apps/replaygain.c +++ b/apps/replaygain.c @@ -224,10 +224,7 @@ static long fp_atof(const char* s, int precision) long sign = 1; bool point = false; - while ((*s != '\0') && isspace(*s)) - { - s++; - } + s = skip_whitespace(s); if (*s == '-') { -- cgit v1.2.3