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 <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov 2009-10-11 16:51:31 +04:00
parent 9ccabd2922
commit c7e8f1bf6f
2 changed files with 41 additions and 0 deletions

View File

@ -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;
}

View File

@ -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