mirror of
https://github.com/netwide-assembler/nasm.git
synced 2025-04-06 18:30:21 +08:00
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:
parent
9ccabd2922
commit
c7e8f1bf6f
36
nasmlib.c
36
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user