FreeRDP
Loading...
Searching...
No Matches
NSString(TSXAdditions) Category Reference

Instance Methods

(NSData *) - dataFromHexString
 

Class Methods

(NSString *) + stringWithUUID
 
(NSString *) + hexStringFromData:ofSize:withSeparator:afterNthChar:
 

Detailed Description

Definition at line 18 of file TSXAdditions.h.

Method Documentation

◆ dataFromHexString

- (NSData *) dataFromHexString

Definition at line 1 of file TSXAdditions.m.

50{
51 NSData *hexData = [self dataUsingEncoding:NSASCIIStringEncoding];
52 const char *hexBuf = [hexData bytes];
53 NSUInteger hexLen = [hexData length];
54
55 // This indicates an error converting to ASCII.
56 if (!hexData)
57 return nil;
58
59 if ((hexLen % 2) != 0)
60 {
61 return nil;
62 }
63
64 NSMutableData *binaryData = [NSMutableData dataWithLength:(hexLen / 2)];
65 unsigned char *binaryPtr = [binaryData mutableBytes];
66 unsigned char value = 0;
67 for (NSUInteger i = 0; i < hexLen; i++)
68 {
69 char c = hexBuf[i];
70
71 if (!isxdigit(c))
72 {
73 return nil;
74 }
75
76 if (isdigit(c))
77 {
78 value += c - '0';
79 }
80 else if (islower(c))
81 {
82 value += 10 + c - 'a';
83 }
84 else
85 {
86 value += 10 + c - 'A';
87 }
88
89 if (i & 1)
90 {
91 *binaryPtr++ = value;
92 value = 0;
93 }
94 else
95 {
96 value <<= 4;
97 }
98 }
99
100 return [NSData dataWithData:binaryData];
101}

◆ hexStringFromData:ofSize:withSeparator:afterNthChar:

+ (NSString *) hexStringFromData: (const unsigned char *)  data
ofSize: (unsigned int)  size
withSeparator: (NSString *)  sep
afterNthChar: (int)  sepnth 

Definition at line 1 of file TSXAdditions.m.

103 :(const unsigned char *)data
104 ofSize:(unsigned int)size
105 withSeparator:(NSString *)sep
106 afterNthChar:(int)sepnth
107{
108 NSMutableString *result;
109 NSString *immutableResult;
110
111 result = [[NSMutableString alloc] init];
112 for (int i = 0; i < size; i++)
113 {
114 if (i && sep && sepnth && i % sepnth == 0)
115 [result appendString:sep];
116 [result appendFormat:@"%02X", data[i]];
117 }
118
119 immutableResult = [NSString stringWithString:result];
120 [result release];
121 return immutableResult;
122}

◆ stringWithUUID

+ (NSString *) stringWithUUID

Definition at line 1 of file TSXAdditions.m.

39{
40 CFUUIDRef uuidObj = CFUUIDCreate(nil);
41 NSString *uuidString = (NSString *)CFUUIDCreateString(nil, uuidObj);
42 CFRelease(uuidObj);
43 return [uuidString autorelease];
44}

The documentation for this category was generated from the following files: