Poco::UUID::tryParse() now accepts UUIDs without hyphens; updated documentation (fixed links to specs)

This commit is contained in:
Guenter Obiltschnig 2013-09-03 14:42:50 +02:00
parent 48f7ea1a58
commit 3314b88c18
3 changed files with 23 additions and 14 deletions

View File

@ -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

View File

@ -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++) ;

View File

@ -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");
}