19 class _GUID_from_text :
public GUID
21 unsigned read_hex(
char c);
22 unsigned read_byte(
const char * ptr);
23 unsigned read_word(
const char * ptr);
24 unsigned read_dword(
const char * ptr);
25 void read_bytes(
unsigned char * out,
unsigned num,
const char * ptr);
28 _GUID_from_text(
const char * text);
31 unsigned _GUID_from_text::read_hex(
char c)
33 if (c>=
'0' && c<=
'9')
return (
unsigned)c -
'0';
34 else if (c>=
'a' && c<=
'f')
return 0xa + (unsigned)c -
'a';
35 else if (c>=
'A' && c<=
'F')
return 0xa + (unsigned)c -
'A';
39 unsigned _GUID_from_text::read_byte(
const char * ptr)
41 return (read_hex(ptr[0])<<4) | read_hex(ptr[1]);
43 unsigned _GUID_from_text::read_word(
const char * ptr)
45 return (read_byte(ptr)<<8) | read_byte(ptr+2);
48 unsigned _GUID_from_text::read_dword(
const char * ptr)
50 return (read_word(ptr)<<16) | read_word(ptr+4);
53 void _GUID_from_text::read_bytes(uint8_t * out,
unsigned num,
const char * ptr)
57 *out = read_byte(ptr);
63 _GUID_from_text::_GUID_from_text(
const char * text)
65 if (*text==
'{') text++;
69 const char * t = strchr(text,
'}');
71 else max = text + strlen(text);
78 if (text+8>max)
break;
79 Data1 = read_dword(text);
81 while(*text==
'-') text++;
82 if (text+4>max)
break;
83 Data2 = read_word(text);
85 while(*text==
'-') text++;
86 if (text+4>max)
break;
87 Data3 = read_word(text);
89 while(*text==
'-') text++;
90 if (text+4>max)
break;
91 read_bytes(Data4,2,text);
93 while(*text==
'-') text++;
94 if (text+12>max)
break;
95 read_bytes(Data4+2,6,text);
103 return _GUID_from_text( text );
108 static const char table[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
109 assert((val & ~0xF) == 0);
113 static void print_hex(
unsigned val,
char * &out,
unsigned bytes)
118 unsigned char c = (
unsigned char)((val >> ((bytes - 1 - n) << 3)) & 0xFF);
151 const unsigned char * in = (
const unsigned char *) buffer;
160 if (FAILED(CoCreateGuid( & out ) ) )
crash();
171 const GUID pfc::guid_null = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
void nixGetRandomData(void *outPtr, size_t outBytes)
static void print_hex(unsigned val, char *&out, unsigned bytes)
GUID GUID_from_text(const char *text)
static char print_hex_digit(unsigned val)
print_guid(const GUID &p_guid)
void print_hex_raw(const void *buffer, unsigned bytes, char *p_out)