]> xenbits.xensource.com Git - libvirt.git/commitdiff
internal: Introduce STRCASESKIP()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 10 Nov 2022 11:52:56 +0000 (12:52 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 16 Nov 2022 11:15:05 +0000 (12:15 +0100)
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@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
docs/coding-style.rst
src/internal.h

index 1faaf681e48bb3ee37a8f61adfaf3a697a7740eb..02d99330bfef8118f2c42b59cfe633d17f4a60f8 100644 (file)
@@ -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:
 
    ::
index 1e8e2908bfa579307efdc8199661e5f871f29e11..35cc22ee3dc07715919931952120da59792a22b6 100644 (file)
@@ -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)