Overview
Comment: | OFUUID: Add -[initWithUUIDString:] |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
02005b54f1ee07c5710199e5dfab95d1 |
User & Date: | js on 2021-10-22 21:40:13 |
Other Links: | manifest | tags |
Context
2021-10-23
| ||
12:16 | OFUUID: Add convenience methods check-in: b2f23fd283 user: js tags: trunk | |
2021-10-22
| ||
21:40 | OFUUID: Add -[initWithUUIDString:] check-in: 02005b54f1 user: js tags: trunk | |
2021-10-18
| ||
00:02 | OFUUID: -[initWithUUIDBytes:] & -[getUUIDBytes:] check-in: 7d94c3ed89 user: js tags: trunk | |
Changes
Modified src/OFUUID.h from [646e59f09e] to [1b0596c0e2].
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 | * @brief Initializes an already allocated OFUUID with the specified bytes. * * @param bytes The bytes to initialize the OFUUID with * @return An initialized OFUUID */ - (instancetype)initWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Compares the UUID to another UUID. * * @param UUID The UUID to compare to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFUUID *)UUID; | > > > > > > > > > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | * @brief Initializes an already allocated OFUUID with the specified bytes. * * @param bytes The bytes to initialize the OFUUID with * @return An initialized OFUUID */ - (instancetype)initWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Initializes an already allocated OFUUID with the specified UUID * string. * * @param string The UUID string to initialize the OFUUID with * @return An initialized OFUUID */ - (instancetype)initWithUUIDString: (OFString *)string; /** * @brief Compares the UUID to another UUID. * * @param UUID The UUID to compare to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFUUID *)UUID; |
︙ | ︙ |
Modified src/OFUUID.m from [d01fab39d1] to [b9dcec5f4c].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFUUID.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFUUID + (instancetype)UUID { return [[[self alloc] init] autorelease]; } | > > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFUUID.h" #import "OFArray.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #define bytesSize 16 @implementation OFUUID + (instancetype)UUID { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | } - (instancetype)initWithUUIDBytes: (const unsigned char [16])bytes { self = [super init]; memcpy(_bytes, bytes, sizeof(_bytes)); return self; } - (bool)isEqual: (id)object { OFUUID *UUID; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | } - (instancetype)initWithUUIDBytes: (const unsigned char [16])bytes { self = [super init]; memcpy(_bytes, bytes, sizeof(_bytes)); return self; } static void decode(OFArray OF_GENERIC(OFString *) *components, size_t componentIndex, size_t componentLength, unsigned char *bytes, size_t *i) { void *pool = objc_autoreleasePoolPush(); OFString *component = [components objectAtIndex: componentIndex]; const char *cString; if (component.UTF8StringLength != componentLength) @throw [OFInvalidFormatException exception]; if (*i + componentLength / 2 > bytesSize) @throw [OFOutOfRangeException exception]; cString = component.UTF8String; for (size_t j = 0; j < componentLength; j += 2) { uint8_t value; if (cString[j] >= '0' && cString[j] <= '9') value = cString[j] - '0'; else if (cString[j] >= 'a' && cString[j] <= 'f') value = cString[j] - 'a' + 10; else if (cString[j] >= 'A' && cString[j] <= 'F') value = cString[j] - 'A' + 10; else @throw [OFInvalidFormatException exception]; value <<= 4; if (cString[j + 1] >= '0' && cString[j + 1] <= '9') value |= cString[j + 1] - '0'; else if (cString[j + 1] >= 'a' && cString[j + 1] <= 'f') value |= cString[j + 1] - 'a' + 10; else if (cString[j + 1] >= 'A' && cString[j + 1] <= 'F') value |= cString[j + 1] - 'A' + 10; else @throw [OFInvalidFormatException exception]; bytes[(*i)++] = value; } objc_autoreleasePoolPop(pool); } - (instancetype)initWithUUIDString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); size_t i = 0; OFArray OF_GENERIC(OFString *) *components = [string componentsSeparatedByString: @"-"]; if (components.count != 5) @throw [OFInvalidFormatException exception]; decode(components, 0, 8, _bytes, &i); decode(components, 1, 4, _bytes, &i); decode(components, 2, 4, _bytes, &i); decode(components, 3, 4, _bytes, &i); decode(components, 4, 12, _bytes, &i); OFEnsure(i == 16); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (bool)isEqual: (id)object { OFUUID *UUID; |
︙ | ︙ |