tree-wide: add global ascii_isdigit() + ascii_isalpha()
We now have a local implementation in string-util-fundamental.c, but
it's useful at a lot of other places, hence let's give it a more
expressive name and share it across the tree.
Follow-up for: 8d9156660d
This commit is contained in:
@@ -521,7 +521,7 @@ static int parse_component_decimal(const char **p, bool usec, int *res) {
|
||||
const char *e = NULL;
|
||||
int r;
|
||||
|
||||
if (!isdigit(**p))
|
||||
if (!ascii_isdigit(**p))
|
||||
return -EINVAL;
|
||||
|
||||
r = parse_one_number(*p, &e, &value);
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "device-nodes.h"
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
int allow_listed_char_for_devnode(char c, const char *white) {
|
||||
return
|
||||
(c >= '0' && c <= '9') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
ascii_isdigit(c) ||
|
||||
ascii_isalpha(c) ||
|
||||
strchr("#+-.:=@_", c) ||
|
||||
(white && strchr(white, c));
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ static int make_partition_devname(
|
||||
if (isempty(whole_devname)) /* Make sure there *is* a last char */
|
||||
return -EINVAL;
|
||||
|
||||
need_p = strchr(DIGITS, whole_devname[strlen(whole_devname)-1]); /* Last char a digit? */
|
||||
need_p = ascii_isdigit(whole_devname[strlen(whole_devname)-1]); /* Last char a digit? */
|
||||
|
||||
return asprintf(ret, "%s%s%i", whole_devname, need_p ? "p" : "", nr);
|
||||
}
|
||||
|
||||
@@ -236,9 +236,8 @@ int dns_label_escape(const char *p, size_t l, char *dest, size_t sz) {
|
||||
sz -= 2;
|
||||
|
||||
} else if (IN_SET(*p, '_', '-') ||
|
||||
(*p >= '0' && *p <= '9') ||
|
||||
(*p >= 'a' && *p <= 'z') ||
|
||||
(*p >= 'A' && *p <= 'Z')) {
|
||||
ascii_isdigit(*p) ||
|
||||
ascii_isalpha(*p)) {
|
||||
|
||||
/* Proper character */
|
||||
|
||||
@@ -907,15 +906,13 @@ static bool srv_type_label_is_valid(const char *label, size_t n) {
|
||||
return false;
|
||||
|
||||
/* Second char must be a letter */
|
||||
if (!(label[1] >= 'A' && label[1] <= 'Z') &&
|
||||
!(label[1] >= 'a' && label[1] <= 'z'))
|
||||
if (!ascii_isalpha(label[1]))
|
||||
return false;
|
||||
|
||||
/* Third and further chars must be alphanumeric or a hyphen */
|
||||
for (k = 2; k < n; k++) {
|
||||
if (!(label[k] >= 'A' && label[k] <= 'Z') &&
|
||||
!(label[k] >= 'a' && label[k] <= 'z') &&
|
||||
!(label[k] >= '0' && label[k] <= '9') &&
|
||||
if (!ascii_isalpha(label[k]) &&
|
||||
!ascii_isdigit(label[k]) &&
|
||||
label[k] != '-')
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user