[PATCH 3/7] internal: Introduce STRCASESKIP()

Michal Privoznik mprivozn at redhat.com
Wed Nov 16 09:11:41 UTC 2022


There is so far one case where STRCASEPREFIX(a, b) && a +
strlen(b) combo is used (in virVMXConfigScanResultsCollector()),
but there will be more. Do what we do usually: introduce a macro.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 docs/coding-style.rst | 9 +++++++++
 src/internal.h        | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/docs/coding-style.rst b/docs/coding-style.rst
index 1faaf681e4..02d99330bf 100644
--- a/docs/coding-style.rst
+++ b/docs/coding-style.rst
@@ -750,6 +750,15 @@ use one of the following semantically named macros
       * use: */
      STRSKIP(a, b)
 
+-  For skipping prefix case insensitively:
+
+   ::
+
+     /* Instead of:
+      *   STRCASEPREFIX(a, b) ? a + strlen(b) : NULL
+      * use: */
+     STRCASESKIP(a, b)
+
 -  To avoid having to check if a or b are NULL:
 
    ::
diff --git a/src/internal.h b/src/internal.h
index 1e8e2908bf..35cc22ee3d 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -87,6 +87,8 @@
 #define STRPREFIX(a, b) (strncmp(a, b, strlen(b)) == 0)
 #define STRCASEPREFIX(a, b) (g_ascii_strncasecmp(a, b, strlen(b)) == 0)
 #define STRSKIP(a, b) (STRPREFIX(a, b) ? (a) + strlen(b) : NULL)
+#define STRCASESKIP(a, b) (STRCASEPREFIX(a, b) ? (a) + strlen(b) : NULL)
+
 /**
  * STRLIM
  * @str: pointer to a string (evaluated once)
-- 
2.37.4



More information about the libvir-list mailing list