mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-24 22:29:47 +01:00
trunk/branch integration: isNil() / isNull() / tryParse()
This commit is contained in:
@@ -143,18 +143,24 @@ void UUID::swap(UUID& uuid)
|
|||||||
|
|
||||||
void UUID::parse(const std::string& uuid)
|
void UUID::parse(const std::string& uuid)
|
||||||
{
|
{
|
||||||
if (uuid.size() < 36)
|
if (!tryParse(uuid))
|
||||||
throw SyntaxException(uuid);
|
throw SyntaxException(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[8] != '-'|| uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-')
|
||||||
throw SyntaxException(uuid);
|
return false;
|
||||||
|
|
||||||
std::string::const_iterator it = uuid.begin();
|
std::string::const_iterator it = uuid.begin();
|
||||||
_timeLow = 0;
|
_timeLow = 0;
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
_timeLow = (_timeLow << 4) | nibble(*it++);
|
_timeLow = (_timeLow << 4) | nibble(*it++);
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
_timeMid = 0;
|
_timeMid = 0;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
@@ -178,6 +184,8 @@ void UUID::parse(const std::string& uuid)
|
|||||||
{
|
{
|
||||||
_node[i] = (nibble(*it++) << 4) | nibble(*it++) ;
|
_node[i] = (nibble(*it++) << 4) | nibble(*it++) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -319,37 +327,42 @@ void UUID::toNetwork()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UUID& UUID::nil()
|
namespace
|
||||||
{
|
{
|
||||||
static UUID nil;
|
static UUID uuidNull;
|
||||||
return nil;
|
static UUID uuidDNS("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
|
||||||
|
static UUID uuidURI("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
|
||||||
|
static UUID uuidOID("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
|
||||||
|
static UUID uuidX500("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const UUID& UUID::null()
|
||||||
|
{
|
||||||
|
return uuidNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UUID& UUID::dns()
|
const UUID& UUID::dns()
|
||||||
{
|
{
|
||||||
static UUID uuidDNS("6ba7b810-9dad-11d1-80b4-00c04fd430c8");
|
|
||||||
return uuidDNS;
|
return uuidDNS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UUID& UUID::uri()
|
const UUID& UUID::uri()
|
||||||
{
|
{
|
||||||
static UUID uuidURI("6ba7b811-9dad-11d1-80b4-00c04fd430c8");
|
|
||||||
return uuidURI;
|
return uuidURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UUID& UUID::oid()
|
const UUID& UUID::oid()
|
||||||
{
|
{
|
||||||
static UUID uuidOID("6ba7b812-9dad-11d1-80b4-00c04fd430c8");
|
|
||||||
return uuidOID;
|
return uuidOID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const UUID& UUID::x500()
|
const UUID& UUID::x500()
|
||||||
{
|
{
|
||||||
static UUID uuidX500("6ba7b814-9dad-11d1-80b4-00c04fd430c8");
|
|
||||||
return uuidX500;
|
return uuidX500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// UUIDGenerator.cpp
|
// UUIDGenerator.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.3/Foundation/src/UUIDGenerator.cpp#4 $
|
// $Id: //poco/1.4/Foundation/src/UUIDGenerator.cpp#1 $
|
||||||
//
|
//
|
||||||
// Library: Foundation
|
// Library: Foundation
|
||||||
// Package: UUID
|
// Package: UUID
|
||||||
@@ -88,7 +88,11 @@ UUID UUIDGenerator::createFromName(const UUID& nsid, const std::string& name, Di
|
|||||||
UUID netNsid = nsid;
|
UUID netNsid = nsid;
|
||||||
netNsid.toNetwork();
|
netNsid.toNetwork();
|
||||||
de.reset();
|
de.reset();
|
||||||
de.update(&netNsid, sizeof(netNsid));
|
de.update(&netNsid._timeLow, sizeof(netNsid._timeLow));
|
||||||
|
de.update(&netNsid._timeMid, sizeof(netNsid._timeMid));
|
||||||
|
de.update(&netNsid._timeHiAndVersion, sizeof(netNsid._timeHiAndVersion));
|
||||||
|
de.update(&netNsid._clockSeq, sizeof(netNsid._clockSeq));
|
||||||
|
de.update(&netNsid._node[0], sizeof(netNsid._node));
|
||||||
de.update(name);
|
de.update(name);
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
const DigestEngine::Digest& d = de.digest();
|
const DigestEngine::Digest& d = de.digest();
|
||||||
@@ -145,9 +149,14 @@ UUID UUIDGenerator::createOne()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UUIDGenerator& UUIDGenerator::defaultGenerator()
|
namespace
|
||||||
{
|
{
|
||||||
static SingletonHolder<UUIDGenerator> sh;
|
static SingletonHolder<UUIDGenerator> sh;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UUIDGenerator& UUIDGenerator::defaultGenerator()
|
||||||
|
{
|
||||||
return *sh.get();
|
return *sh.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user