From c7e8f1bf6faff60c16dbbc920c3a36c2251ab3ab Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 11 Oct 2009 16:51:31 +0400 Subject: [PATCH] nasmlib: introduce string helpers To make code more compact we introduce the following string helpers: 1) nasm_scip_spaces - skip leading spaces 2) nasm_skip_word - skip leading non-spaces 3) nasm_zap_spaces - zap leading spaces with zero 4) nasm_zap_spaces_rev - zap spaces in reverse order Signed-off-by: Cyrill Gorcunov --- nasmlib.c | 36 ++++++++++++++++++++++++++++++++++++ nasmlib.h | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/nasmlib.c b/nasmlib.c index 35aa505..79935ad 100644 --- a/nasmlib.c +++ b/nasmlib.c @@ -653,3 +653,39 @@ char *nasm_strcat(const char *one, const char *two) strcpy(rslt + l1, two); return rslt; } + +/* skip leading spaces */ +char *nasm_skip_spaces(const char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + p++; + return (char *)p; +} + +/* skip leading non-spaces */ +char *nasm_skip_word(const char *p) +{ + if (p) + while (*p && !nasm_isspace(*p)) + p++; + return (char *)p; +} + +/* zap leading spaces with zero */ +char *nasm_zap_spaces(char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + *p++ = 0x0; + return p; +} + +/* zap spaces with zero in reverse order */ +char *nasm_zap_spaces_rev(char *p) +{ + if (p) + while (*p && nasm_isspace(*p)) + *p-- = 0x0; + return p; +} diff --git a/nasmlib.h b/nasmlib.h index 441ea20..f3128b5 100644 --- a/nasmlib.h +++ b/nasmlib.h @@ -377,6 +377,11 @@ int src_get(int32_t *xline, char **xname); char *nasm_strcat(const char *one, const char *two); +char *nasm_skip_spaces(const char *p); +char *nasm_skip_word(const char *p); +char *nasm_zap_spaces(char *p); +char *nasm_zap_spaces_rev(char *p); + const char *prefix_name(int); #define ZERO_BUF_SIZE 4096 -- 2.7.4