00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <xplc/uuid.h>
00035
00036 const UUID UuidFromString(const char* str) {
00037 UUID rv;
00038 char tmp[3];
00039 char* end;
00040 bool format1 = false;
00041 bool ok = false;
00042
00043 do {
00044 if(*str == '{') {
00045 format1 = true;
00046 ++str;
00047 }
00048
00049 rv.Data1 = strtoul(str, &end, 16);
00050 if(end != str + 8)
00051 break;
00052 str = end;
00053
00054 if(*str != '-')
00055 break;
00056 ++str;
00057
00058 rv.Data2 = static_cast<unsigned short>(strtoul(str, &end, 16));
00059 if(end != str + 4)
00060 break;
00061 str = end;
00062
00063 if(*str != '-')
00064 break;
00065 ++str;
00066
00067 rv.Data3 = static_cast<unsigned short>(strtoul(str, &end, 16));
00068 if(end != str + 4)
00069 break;
00070 str = end;
00071
00072 if(*str != '-')
00073 break;
00074 ++str;
00075
00076 tmp[2] = 0;
00077
00078 strncpy(tmp, str, 2);
00079 rv.Data4[0] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
00080 if(end != tmp + 2)
00081 break;
00082 str += 2;
00083
00084 strncpy(tmp, str, 2);
00085 rv.Data4[1] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
00086 if(end != tmp + 2)
00087 break;
00088 str += 2;
00089
00090 if(*str != '-')
00091 break;
00092 ++str;
00093
00094 for(int i = 2; i < 8; ++i) {
00095 strncpy(tmp, str, 2);
00096 rv.Data4[i] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
00097 if(end != tmp + 2)
00098 break;
00099 str += 2;
00100 }
00101
00102 if(format1) {
00103 if(*str != '}')
00104 break;
00105 ++str;
00106 }
00107
00108 if(*str != 0)
00109 break;
00110
00111 ok = true;
00112 } while(0);
00113
00114 if(!ok)
00115 rv = UUID_null;
00116
00117 return rv;
00118 }
00119