FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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.

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

◆ 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.

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

◆ stringWithUUID

+ (NSString *) stringWithUUID

Definition at line 1 of file TSXAdditions.m.

42{
43 CFUUIDRef uuidObj = CFUUIDCreate(nil);
44 NSString *uuidString = (NSString *)CFUUIDCreateString(nil, uuidObj);
45 CFRelease(uuidObj);
46 return [uuidString autorelease];
47}

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