]> granicus.if.org Git - graphviz/commitdiff
add an abstraction for checking string prefixes
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 23 Sep 2022 04:19:33 +0000 (21:19 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 23 Sep 2022 14:57:00 +0000 (07:57 -0700)
lib/cgraph/CMakeLists.txt
lib/cgraph/Makefile.am
lib/cgraph/cgraph.vcxproj
lib/cgraph/cgraph.vcxproj.filters
lib/cgraph/startswith.h [new file with mode: 0644]

index ac14bc49074a3adfcadf0008e2a2f144b4e670cc..7255b88a7677242ab92f4ceb9ed041d5448d79fd 100644 (file)
@@ -21,6 +21,7 @@ add_library(cgraph SHARED
   likely.h
   prisize_t.h
   stack.h
+  startswith.h
   strcasecmp.h
   strview.h
   tokenize.h
index 1a58bda7fa4fd959332dd9bc6eecddf99044526d..ef8b92b91ce7c42fbfac016b108378ec72c01104 100644 (file)
@@ -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
index 4fd19c689f0a6fc16604e76c5afb2bc10ff2f118..ee95eeb2af038b1441571cdedf4b111b7150e6c7 100644 (file)
@@ -107,6 +107,7 @@ win_flex -oscan.c scan.l</Command>
     <ClInclude Include="likely.h" />
     <ClInclude Include="prisize_t.h" />
     <ClInclude Include="stack.h" />
+    <ClInclude Include="startswith.h" />
     <ClInclude Include="strcasecmp.h" />
     <ClInclude Include="strview.h" />
     <ClInclude Include="tokenize.h" />
index 83633d7db1b7d835027d80a35f5b66d37f2f463a..ee2d35f65d619d42180e690692ac2e7b9f1ff70c 100644 (file)
@@ -45,6 +45,9 @@
     <ClInclude Include="stack.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="startswith.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
     <ClInclude Include="strcasecmp.h">
       <Filter>Header Files</Filter>
     </ClInclude>
diff --git a/lib/cgraph/startswith.h b/lib/cgraph/startswith.h
new file mode 100644 (file)
index 0000000..e4e66f9
--- /dev/null
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+
+/// 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;
+}