string: implement strspn, strcspn, atol
Change-Id: Id8fa880357124b620bde8884949bd8ffff7d0762 Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/34450 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
parent
e2c24f783d
commit
6b212d8fcf
@ -32,6 +32,9 @@ char *strncpy(char *to, const char *from, int count);
|
|||||||
char *strcpy(char *dst, const char *src);
|
char *strcpy(char *dst, const char *src);
|
||||||
int strcmp(const char *s1, const char *s2);
|
int strcmp(const char *s1, const char *s2);
|
||||||
int strncmp(const char *s1, const char *s2, int maxlen);
|
int strncmp(const char *s1, const char *s2, int maxlen);
|
||||||
|
int strspn(const char *str, const char *spn);
|
||||||
|
int strcspn(const char *str, const char *spn);
|
||||||
|
long atol(const char *str);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a character in a string.
|
* Find a character in a string.
|
||||||
|
@ -132,3 +132,55 @@ unsigned int skip_atoi(char **s)
|
|||||||
i = i*10 + *((*s)++) - '0';
|
i = i*10 + *((*s)++) - '0';
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strspn(const char *str, const char *spn)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
while (*str != 0) {
|
||||||
|
const char *p;
|
||||||
|
for (p = spn; *str != *p; p++)
|
||||||
|
if (*p == '\0')
|
||||||
|
return ret;
|
||||||
|
ret++;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int strcspn(const char *str, const char *spn)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
while (*str != 0) {
|
||||||
|
const char *p;
|
||||||
|
for (p = spn; *p != '\0'; p++)
|
||||||
|
if (*p == *str)
|
||||||
|
return ret;
|
||||||
|
ret++;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
long atol(const char *str)
|
||||||
|
{
|
||||||
|
long ret = 0;
|
||||||
|
long sign = 1;
|
||||||
|
|
||||||
|
str += strspn(str, " \t\n\r\f\v");
|
||||||
|
|
||||||
|
if (*str == '+') {
|
||||||
|
sign = 1;
|
||||||
|
str++;
|
||||||
|
} else if (*str == '-') {
|
||||||
|
sign = -1;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (isdigit(*str)) {
|
||||||
|
ret *= 10;
|
||||||
|
ret += *str++ - '0';
|
||||||
|
}
|
||||||
|
return ret * sign;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user