MCPcopy Create free account
hub / github.com/SpartanJ/eepp / fromString

Method fromString

src/eepp/system/uuid.cpp:61–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61std::optional<UUID> UUID::fromString( const std::string_view& uuidStr ) {
62 // Check length (36 characters including hyphens)
63 if ( uuidStr.length() != 36 )
64 return {};
65
66 // Verify hyphen positions
67 if ( uuidStr[8] != '-' || uuidStr[13] != '-' || uuidStr[18] != '-' || uuidStr[23] != '-' )
68 return {};
69
70 // Verify version (must be '4' for UUIDv4)
71 if ( uuidStr[14] != '4' )
72 return {};
73
74 // Verify variant (must be '8', '9', 'a', or 'b')
75 char variantChar = uuidStr[19];
76 if ( !( ( variantChar >= '8' && variantChar <= '9' ) ||
77 ( variantChar >= 'a' && variantChar <= 'b' ) ) )
78 return {};
79
80 // Remove hyphens and convert to lowercase
81 std::string hexStr;
82 for ( char c : uuidStr ) {
83 if ( c != '-' ) {
84 if ( !std::isxdigit( c ) )
85 return {};
86 hexStr += std::tolower( c );
87 }
88 }
89
90 // Verify length after removing hyphens (32 hex chars)
91 if ( hexStr.length() != 32 )
92 return {};
93
94 // Convert to 128-bit binary (two 64-bit parts)
95 uint64_t high_ = hexToUint64( hexStr.substr( 0, 16 ) );
96 uint64_t low_ = hexToUint64( hexStr.substr( 16, 16 ) );
97
98 return UUID{ high_, low_ };
99}
100
101std::string UUID::toString() const {
102 char buf[36]; // 32 hex digits + 4 hyphens = 36 characters

Callers 3

runMethod · 0.95
probeServiceMethod · 0.95

Calls 3

hexToUint64Function · 0.85
substrMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected