From 2888453617113c1e6e760da0e2b7f14228d5f64c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 22 Sep 2022 21:19:33 -0700 Subject: [PATCH] add an abstraction for checking string prefixes --- lib/cgraph/CMakeLists.txt | 1 + lib/cgraph/Makefile.am | 3 ++- lib/cgraph/cgraph.vcxproj | 1 + lib/cgraph/cgraph.vcxproj.filters | 3 +++ lib/cgraph/startswith.h | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 lib/cgraph/startswith.h diff --git a/lib/cgraph/CMakeLists.txt b/lib/cgraph/CMakeLists.txt index ac14bc490..7255b88a7 100644 --- a/lib/cgraph/CMakeLists.txt +++ b/lib/cgraph/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(cgraph SHARED likely.h prisize_t.h stack.h + startswith.h strcasecmp.h strview.h tokenize.h diff --git a/lib/cgraph/Makefile.am b/lib/cgraph/Makefile.am index 1a58bda7f..ef8b92b91 100644 --- a/lib/cgraph/Makefile.am +++ b/lib/cgraph/Makefile.am @@ -10,7 +10,8 @@ endif pkginclude_HEADERS = cgraph.h noinst_HEADERS = agxbuf.h alloc.h bitarray.h cghdr.h exit.h itos.h likely.h \ - prisize_t.h stack.h strcasecmp.h strview.h tokenize.h unreachable.h unused.h + prisize_t.h stack.h startswith.h strcasecmp.h strview.h tokenize.h \ + unreachable.h unused.h noinst_LTLIBRARIES = libcgraph_C.la lib_LTLIBRARIES = libcgraph.la pkgconfig_DATA = libcgraph.pc diff --git a/lib/cgraph/cgraph.vcxproj b/lib/cgraph/cgraph.vcxproj index 4fd19c689..ee95eeb2a 100644 --- a/lib/cgraph/cgraph.vcxproj +++ b/lib/cgraph/cgraph.vcxproj @@ -107,6 +107,7 @@ win_flex -oscan.c scan.l + diff --git a/lib/cgraph/cgraph.vcxproj.filters b/lib/cgraph/cgraph.vcxproj.filters index 83633d7db..ee2d35f65 100644 --- a/lib/cgraph/cgraph.vcxproj.filters +++ b/lib/cgraph/cgraph.vcxproj.filters @@ -45,6 +45,9 @@ Header Files + + Header Files + Header Files diff --git a/lib/cgraph/startswith.h b/lib/cgraph/startswith.h new file mode 100644 index 000000000..e4e66f924 --- /dev/null +++ b/lib/cgraph/startswith.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include +#include + +/// does the string \p s begin with the string \p prefix? +static inline bool startswith(const char *s, const char *prefix) { + assert(s != NULL); + assert(prefix != NULL); + + return strncmp(s, prefix, strlen(prefix)) == 0; +} -- 2.40.0