]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: new function virSkipToDigit()
authorLaine Stump <laine@redhat.com>
Fri, 8 Jan 2021 00:55:43 +0000 (19:55 -0500)
committerLaine Stump <laine@redhat.com>
Fri, 8 Jan 2021 15:15:04 +0000 (10:15 -0500)
This function skips over the beginning of a string until it reaches a
decimal digit (0-9) or the NULL at the end of the string. The original
pointer is modified in place (similar to virSkipSpaces()).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/libvirt_private.syms
src/util/virstring.c
src/util/virstring.h

index c67bd2504aff33b701809f47462484bbd73fca0a..c325040b60bfc2d1336cc441b97c6de0a1126471 100644 (file)
@@ -3217,6 +3217,7 @@ virStorageFileBackendRegister;
 virSkipSpaces;
 virSkipSpacesAndBackslash;
 virSkipSpacesBackwards;
+virSkipToDigit;
 virStrcpy;
 virStringBufferIsPrintable;
 virStringFilterChars;
index 5578a5545b96737fd5aeff429126515c08d459e8..521f2de3f64fd7bf3b4a0bcbb31ba508842872d9 100644 (file)
@@ -752,6 +752,24 @@ virSkipSpacesAndBackslash(const char **str)
     *str = cur;
 }
 
+
+/**
+ * virSkipToDigit:
+ * @str: pointer to the char pointer used
+ *
+ * Skip over any character that is not 0-9
+ */
+void
+virSkipToDigit(const char **str)
+{
+    const char *cur = *str;
+
+    while (*cur && !g_ascii_isdigit(*cur))
+        cur++;
+    *str = cur;
+}
+
+
 /**
  * virTrimSpaces:
  * @str: string to modify to remove all trailing spaces
index 210e43a9538e69ea78d006f5f8ec60010319c9d0..55547b040a21f0da057f198beb03629fa894fa8a 100644 (file)
@@ -110,6 +110,7 @@ int virDoubleToStr(char **strp, double number)
 
 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
+void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1);
 void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesBackwards(const char *str, char **endp)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);