[glib/wip/hadess/socket-test-not-parallel: 2/7] Revert "guuid: Remove support for curly braces and URN UUIDs"



commit 4f9c3a790a4fc706a1233edf0fce3dc640bf0e95
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Dec 11 09:57:50 2017 +0100

    Revert "guuid: Remove support for curly braces and URN UUIDs"
    
    This reverts commit 4b75333c83535cef57f674f5bd0c604901c44d1d.

 glib/guuid.c       | 23 ++++++++++++++++++++++-
 glib/tests/guuid.c |  4 ++--
 2 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/glib/guuid.c b/glib/guuid.c
index 1adc6c82e..0f48bfbe3 100644
--- a/glib/guuid.c
+++ b/glib/guuid.c
@@ -94,9 +94,27 @@ uuid_parse_string (const gchar *str,
   gint i, j, hi, lo;
   guint expected_len = 36;
 
+  if (g_str_has_prefix (str, "urn:uuid:"))
+    str += 9;
+  else if (g_str_has_prefix (str, "{urn:uuid:"))
+    expected_len += 11;
+  else if (str[0] == '{')
+    expected_len += 2;
+
   if (strlen (str) != expected_len)
     return FALSE;
 
+  if (str[0] == '{')
+    {
+      if (str[expected_len - 1] != '}')
+        return FALSE;
+
+      str++;
+    }
+
+  if (g_str_has_prefix (str, "urn:uuid:"))
+    str += 9;
+
   for (i = 0, j = 0; i < 16;)
     {
       if (j == 8 || j == 13 || j == 18 || j == 23)
@@ -128,9 +146,12 @@ uuid_parse_string (const gchar *str,
  *
  * Parses the string @str and verify if it is a UUID.
  *
- * The function accepts the following syntax:
+ * The function accepts the following syntaxes:
  *
  * - simple forms (e.g. `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
+ * - simple forms with curly braces (e.g.
+ *   `{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}`)
+ * - URN (e.g. `urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6`)
  *
  * Note that hyphens are required within the UUID string itself,
  * as per the aforementioned RFC.
diff --git a/glib/tests/guuid.c b/glib/tests/guuid.c
index 41e2c81e9..437749f0e 100644
--- a/glib/tests/guuid.c
+++ b/glib/tests/guuid.c
@@ -30,13 +30,13 @@ test_guuid_string (void)
   g_assert_false (g_uuid_string_is_valid ("00010203-0405-0607-0809"));
   g_assert_false (g_uuid_string_is_valid ("zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"));
   g_assert_false (g_uuid_string_is_valid ("000102030405060708090a0b0c0d0e0f"));
-  g_assert_false (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}"));
-  g_assert_false (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"));
 
   g_assert_true (g_uuid_string_is_valid ("00010203-0405-0607-0809-0a0b0c0d0e0f"));
   g_assert_true (g_uuid_string_is_valid ("7d444840-9dc0-11d1-b245-5ffdce74fad2"));
   g_assert_true (g_uuid_string_is_valid ("e902893a-9d22-3c7e-a7b8-d6e313b71d9f"));
   g_assert_true (g_uuid_string_is_valid ("6ba7b810-9dad-11d1-80b4-00c04fd430c8"));
+  g_assert_true (g_uuid_string_is_valid ("{urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6}"));
+  g_assert_true (g_uuid_string_is_valid ("urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6"));
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]