From 1639195d9fe9fde19465bd46e25d8899a6493fa2 Mon Sep 17 00:00:00 2001 From: Ben Griner Date: Tue, 5 Feb 2019 10:42:45 -0500 Subject: [PATCH 1/5] adding new StringNoHyphens func --- uuid.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/uuid.go b/uuid.go index a2b8e2c..2d884fa 100644 --- a/uuid.go +++ b/uuid.go @@ -128,6 +128,19 @@ func (u UUID) String() string { return string(buf) } +// Returns string representation of UUID without hyphens +func (u UUID) StringNoHyphens() string { + buf := make([]byte, 36) + + hex.Encode(buf[0:8], u[0:4]) + hex.Encode(buf[8:12], u[4:6]) + hex.Encode(buf[12:16], u[6:8]) + hex.Encode(buf[16:20], u[8:10]) + hex.Encode(buf[20:], u[10:]) + + return string(buf) +} + // SetVersion sets version bits. func (u *UUID) SetVersion(v byte) { u[6] = (u[6] & 0x0f) | (v << 4) From 1ee38113101f1c094e642af55ad9c048cc6191e2 Mon Sep 17 00:00:00 2001 From: Ben Griner Date: Tue, 5 Feb 2019 11:26:43 -0500 Subject: [PATCH 2/5] adding test for StringNoHyphens --- uuid_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/uuid_test.go b/uuid_test.go index fa40280..57ee2b4 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -48,6 +48,10 @@ func (s *testSuite) TestString(c *C) { c.Assert(NamespaceDNS.String(), Equals, "6ba7b810-9dad-11d1-80b4-00c04fd430c8") } +func (s *testSuite) TestStringNoHyphens(c *C) { + c.Assert(NamespaceDNS.StringNoHyphens(), Equals, "6ba7b8109dad11d180b400c04fd430c8") +} + func (s *testSuite) TestEqual(c *C) { c.Assert(Equal(NamespaceDNS, NamespaceDNS), Equals, true) c.Assert(Equal(NamespaceDNS, NamespaceURL), Equals, false) From 131a6a00aab786e6b688f26973cb2fbe46333aaa Mon Sep 17 00:00:00 2001 From: Ben Griner Date: Tue, 5 Feb 2019 11:31:49 -0500 Subject: [PATCH 3/5] reducing byte from 36 to 32 --- uuid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uuid.go b/uuid.go index 2d884fa..d430d5e 100644 --- a/uuid.go +++ b/uuid.go @@ -130,7 +130,7 @@ func (u UUID) String() string { // Returns string representation of UUID without hyphens func (u UUID) StringNoHyphens() string { - buf := make([]byte, 36) + buf := make([]byte, 32) hex.Encode(buf[0:8], u[0:4]) hex.Encode(buf[8:12], u[4:6]) From 6bdaeafcfff06afba13f8a94312269a69216306f Mon Sep 17 00:00:00 2001 From: Ben Griner Date: Tue, 5 Feb 2019 13:28:17 -0500 Subject: [PATCH 4/5] simplifying StringNoHyphens func --- uuid.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/uuid.go b/uuid.go index d430d5e..66e41c6 100644 --- a/uuid.go +++ b/uuid.go @@ -130,15 +130,7 @@ func (u UUID) String() string { // Returns string representation of UUID without hyphens func (u UUID) StringNoHyphens() string { - buf := make([]byte, 32) - - hex.Encode(buf[0:8], u[0:4]) - hex.Encode(buf[8:12], u[4:6]) - hex.Encode(buf[12:16], u[6:8]) - hex.Encode(buf[16:20], u[8:10]) - hex.Encode(buf[20:], u[10:]) - - return string(buf) + return hex.EncodeToString(u[:]) } // SetVersion sets version bits. From ffc5e1e443820cdaac5ecfc7b6818178bcbe71c6 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Sun, 3 Mar 2019 15:48:28 -0500 Subject: [PATCH 5/5] Update uuid.go Co-Authored-By: bpgriner --- uuid.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uuid.go b/uuid.go index 66e41c6..4c4b649 100644 --- a/uuid.go +++ b/uuid.go @@ -128,7 +128,7 @@ func (u UUID) String() string { return string(buf) } -// Returns string representation of UUID without hyphens +// StringNoHyphens returns the string representation of UUID without hyphens. func (u UUID) StringNoHyphens() string { return hex.EncodeToString(u[:]) }