From 16fc03f1f8626dd282f4e268cce1549d9159387f Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 10 Jul 2022 10:53:54 -0700 Subject: [PATCH] cgraph: add a 'strdup' equivalent for 'strview_t' This will be used in an upcoming commit. --- lib/cgraph/strview.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/cgraph/strview.h b/lib/cgraph/strview.h index ea22d8fe4..8e4d593ad 100644 --- a/lib/cgraph/strview.h +++ b/lib/cgraph/strview.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -34,6 +35,14 @@ static inline strview_t strview(const char *referent, char terminator) { return (strview_t){.data = referent, .size = strlen(referent)}; } +/// make a heap-allocated string from this string view +static inline char *strview_str(strview_t source) { + + assert(source.data != NULL); + + return gv_strndup(source.data, source.size); +} + /// compare two string references for case insensitive equality static inline bool strview_case_eq(strview_t a, strview_t b) { -- 2.40.0