util: split out nulstr related stuff to nulstr-util.[ch]

This commit is contained in:
Lennart Poettering
2019-03-14 13:25:52 +01:00
parent 090a9c1eba
commit d8b4d14df4
40 changed files with 70 additions and 40 deletions
+1
View File
@@ -4,6 +4,7 @@
#include "kbd-util.h"
#include "log.h"
#include "nulstr-util.h"
#include "path-util.h"
#include "set.h"
#include "string-util.h"
+2
View File
@@ -137,6 +137,8 @@ basic_sources = files('''
namespace-util.c
namespace-util.h
nss-util.h
nulstr-util.c
nulstr-util.h
ordered-set.c
ordered-set.h
parse-util.c
+17
View File
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "nulstr-util.h"
#include "string-util.h"
bool nulstr_contains(const char *nulstr, const char *needle) {
const char *i;
if (!nulstr)
return false;
NULSTR_FOREACH(i, nulstr)
if (streq(i, needle))
return true;
return false;
}
+13
View File
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#pragma once
#include <stdbool.h>
#include <string.h>
#define NULSTR_FOREACH(i, l) \
for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
#define NULSTR_FOREACH_PAIR(i, j, l) \
for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
bool nulstr_contains(const char *nulstr, const char *needle);
+1
View File
@@ -21,6 +21,7 @@
#include "log.h"
#include "macro.h"
#include "missing.h"
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "stat-util.h"
-13
View File
@@ -676,19 +676,6 @@ char *cellescape(char *buf, size_t len, const char *s) {
return buf;
}
bool nulstr_contains(const char *nulstr, const char *needle) {
const char *i;
if (!nulstr)
return false;
NULSTR_FOREACH(i, nulstr)
if (streq(i, needle))
return true;
return false;
}
char* strshorten(char *s, size_t l) {
assert(s);
-2
View File
@@ -165,8 +165,6 @@ char *cellescape(char *buf, size_t len, const char *s);
/* This limit is arbitrary, enough to give some idea what the string contains */
#define CELLESCAPE_DEFAULT_LENGTH 64
bool nulstr_contains(const char *nulstr, const char *needle);
char* strshorten(char *s, size_t l);
char *strreplace(const char *text, const char *old_string, const char *new_string);
+1
View File
@@ -11,6 +11,7 @@
#include "escape.h"
#include "extract-word.h"
#include "fileio.h"
#include "nulstr-util.h"
#include "sort-util.h"
#include "string-util.h"
#include "strv.h"
-6
View File
@@ -43,12 +43,6 @@ static inline const char* enable_disable(bool b) {
return b ? "enable" : "disable";
}
#define NULSTR_FOREACH(i, l) \
for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
#define NULSTR_FOREACH_PAIR(i, j, l) \
for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
extern int saved_argc;
extern char **saved_argv;