Allow KIID to directly take in std::string
Reduces multibyte conversion banging on library load. uuids already are ASCII by their nature and the logic checks that or else it generates a new kiid.
This commit is contained in:
parent
02a6566438
commit
fd6564cc82
|
@ -33,6 +33,7 @@
|
||||||
#include <boost/uuid/entropy_error.hpp>
|
#include <boost/uuid/entropy_error.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <cctype>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
@ -104,16 +105,21 @@ KIID::KIID( int null ) : m_uuid( nilGenerator() ), m_cached_timestamp( 0 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KIID::KIID( const wxString& aString ) : m_uuid(), m_cached_timestamp( 0 )
|
KIID::KIID( const std::string& aString ) : m_uuid(), m_cached_timestamp( 0 )
|
||||||
{
|
{
|
||||||
if( aString.length() == 8 )
|
if( aString.length() == 8
|
||||||
|
&& std::all_of( aString.begin(), aString.end(),
|
||||||
|
[]( unsigned char c )
|
||||||
|
{
|
||||||
|
return std::isxdigit( c );
|
||||||
|
} ) )
|
||||||
{
|
{
|
||||||
// A legacy-timestamp-based UUID has only the last 4 octets filled in.
|
// A legacy-timestamp-based UUID has only the last 4 octets filled in.
|
||||||
// Convert them individually to avoid stepping in the little-endian/big-endian
|
// Convert them individually to avoid stepping in the little-endian/big-endian
|
||||||
// doo-doo.
|
// doo-doo.
|
||||||
for( int i = 0; i < 4; ++i )
|
for( int i = 0; i < 4; ++i )
|
||||||
{
|
{
|
||||||
wxString octet = aString.substr( i * 2, 2 );
|
std::string octet = aString.substr( i * 2, 2 );
|
||||||
m_uuid.data[i + 12] = strtol( octet.data(), nullptr, 16 );
|
m_uuid.data[i + 12] = strtol( octet.data(), nullptr, 16 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +129,7 @@ KIID::KIID( const wxString& aString ) : m_uuid(), m_cached_timestamp( 0 )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_uuid = stringGenerator( aString.wc_str() );
|
m_uuid = stringGenerator( aString );
|
||||||
|
|
||||||
if( IsLegacyTimestamp() )
|
if( IsLegacyTimestamp() )
|
||||||
m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), nullptr, 16 );
|
m_cached_timestamp = strtol( aString.substr( 28 ).c_str(), nullptr, 16 );
|
||||||
|
@ -152,6 +158,16 @@ KIID::KIID( const wxString& aString ) : m_uuid(), m_cached_timestamp( 0 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KIID::KIID( const const char* aString ) : KIID( std::string( aString ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
KIID::KIID( const wxString& aString ) : KIID( std::string( aString.ToUTF8() ) )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KIID::SniffTest( const wxString& aCandidate )
|
bool KIID::SniffTest( const wxString& aCandidate )
|
||||||
{
|
{
|
||||||
static wxString niluuidStr = niluuid.AsString();
|
static wxString niluuidStr = niluuid.AsString();
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <boost/uuid/uuid.hpp>
|
#include <boost/uuid/uuid.hpp>
|
||||||
#include <macros_swig.h>
|
#include <macros_swig.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class wxString;
|
class wxString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +48,8 @@ class KIID
|
||||||
public:
|
public:
|
||||||
KIID();
|
KIID();
|
||||||
KIID( int null );
|
KIID( int null );
|
||||||
|
KIID( const std::string& aString );
|
||||||
|
KIID( const char* aString );
|
||||||
KIID( const wxString& aString );
|
KIID( const wxString& aString );
|
||||||
KIID( timestamp_t aTimestamp );
|
KIID( timestamp_t aTimestamp );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue