From 3314b88c18472f896b78018961201982744a09ef Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Tue, 3 Sep 2013 14:42:50 +0200 Subject: [PATCH] Poco::UUID::tryParse() now accepts UUIDs without hyphens; updated documentation (fixed links to specs) --- Foundation/include/Poco/UUID.h | 8 ++++---- Foundation/src/UUID.cpp | 24 +++++++++++++++--------- Foundation/testsuite/src/UUIDTest.cpp | 5 ++++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Foundation/include/Poco/UUID.h b/Foundation/include/Poco/UUID.h index 6e5d84460..cf632ff28 100644 --- a/Foundation/include/Poco/UUID.h +++ b/Foundation/include/Poco/UUID.h @@ -1,7 +1,7 @@ // // UUID.h // -// $Id: //poco/1.4/Foundation/include/Poco/UUID.h#1 $ +// $Id: //poco/1.4/Foundation/include/Poco/UUID.h#2 $ // // Library: Foundation // Package: UUID @@ -54,14 +54,14 @@ class Foundation_API UUID /// used). A UUID can be used for multiple purposes, from tagging /// objects with an extremely short lifetime, to reliably identifying /// very persistent objects across a network. + /// /// This class implements a Universal Unique Identifier, /// as specified in Appendix A of the DCE 1.1 Remote Procedure /// Call Specification (http://www.opengroup.org/onlinepubs/9629399/), /// RFC 2518 (WebDAV), section 6.4.1 and the UUIDs and GUIDs internet /// draft by Leach/Salz from February, 1998 - /// (http://ftp.ics.uci.edu/pub/ietf/webdav/uuid-guid/draft-leach-uuids-guids-01.txt) - /// and also - /// http://www.ietf.org/internet-drafts/draft-mealling-uuid-urn-03.txt + /// (http://www.ics.uci.edu/~ejw/authoring/uuid-guid/draft-leach-uuids-guids-01.txt) + /// and also http://tools.ietf.org/html/draft-mealling-uuid-urn-05 { public: enum Version diff --git a/Foundation/src/UUID.cpp b/Foundation/src/UUID.cpp index 9d7af1cd3..a7ce40dc8 100644 --- a/Foundation/src/UUID.cpp +++ b/Foundation/src/UUID.cpp @@ -1,7 +1,7 @@ // // UUID.cpp // -// $Id: //poco/1.4/Foundation/src/UUID.cpp#1 $ +// $Id: //poco/1.4/Foundation/src/UUID.cpp#2 $ // // Library: Foundation // Package: UUID @@ -149,37 +149,43 @@ void UUID::parse(const std::string& uuid) bool UUID::tryParse(const std::string& uuid) { - if (uuid.size() < 36) - return false; - - if (uuid[8] != '-'|| uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-') + if (uuid.size() < 32) return false; + bool haveHyphens = false; + if (uuid[8] == '-' && uuid[13] == '-' && uuid[18] == '-' && uuid[23] == '-') + { + if (uuid.size() >= 36) + haveHyphens = true; + else + return false; + } + std::string::const_iterator it = uuid.begin(); _timeLow = 0; for (int i = 0; i < 8; ++i) { _timeLow = (_timeLow << 4) | nibble(*it++); } - ++it; + if (haveHyphens) ++it; _timeMid = 0; for (int i = 0; i < 4; ++i) { _timeMid = (_timeMid << 4) | nibble(*it++); } - ++it; + if (haveHyphens) ++it; _timeHiAndVersion = 0; for (int i = 0; i < 4; ++i) { _timeHiAndVersion = (_timeHiAndVersion << 4) | nibble(*it++); } - ++it; + if (haveHyphens) ++it; _clockSeq = 0; for (int i = 0; i < 4; ++i) { _clockSeq = (_clockSeq << 4) | nibble(*it++); } - ++it; + if (haveHyphens) ++it; for (int i = 0; i < 6; ++i) { _node[i] = (nibble(*it++) << 4) | nibble(*it++) ; diff --git a/Foundation/testsuite/src/UUIDTest.cpp b/Foundation/testsuite/src/UUIDTest.cpp index e203e46f2..3d8e026e5 100644 --- a/Foundation/testsuite/src/UUIDTest.cpp +++ b/Foundation/testsuite/src/UUIDTest.cpp @@ -1,7 +1,7 @@ // // UUIDTest.cpp // -// $Id: //poco/1.4/Foundation/testsuite/src/UUIDTest.cpp#1 $ +// $Id: //poco/1.4/Foundation/testsuite/src/UUIDTest.cpp#2 $ // // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // and Contributors. @@ -56,6 +56,9 @@ void UUIDTest::testParse() uuid.parse("6BA7B810-9DAD-11D1-80B4-00C04FD430C8"); assert (uuid.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8"); + + uuid.parse("6BA7B8109DAD11D180B400C04FD430C8"); + assert (uuid.toString() == "6ba7b810-9dad-11d1-80b4-00c04fd430c8"); }