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