blob: 4c3d0c1dab6df7aeff2ee9fa8134dc29b9f0a38f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#import "HFSCodeFormatter.h"
@implementation HFSCodeFormatter
- (NSString *)stringForObjectValue: (id)anObject
{
unsigned long longValue;
char a, b, c, d;
if ([anObject isKindOfClass: [NSNumber class]])
longValue = [anObject unsignedLongValue];
else
longValue = 0;
a = (longValue >> 24) & 0xff;
b = (longValue >> 16) & 0xff;
c = (longValue >> 8) & 0xff;
d = longValue & 0xff;
return [NSString stringWithFormat: @"%c%c%c%c", a, b, c, d];
}
- (BOOL)getObjectValue: (id *)anObject
forString: (NSString *)string
errorDescription: (NSString **)error
{
unsigned long objectValue;
unsigned int i, bitNo;
bitNo = 24;
objectValue = 0;
for (i = 0; i < [string length] && i < 4; i++) {
objectValue += ([string characterAtIndex: i] & 0xff) << bitNo;
bitNo -= 8;
}
*anObject = [NSNumber numberWithUnsignedLong: objectValue];
return YES;
}
- (BOOL)isPartialStringValid: (NSString *)partialString
newEditingString: (NSString **)newString
errorDescription: (NSString **)error
{
return [partialString length] <= 4;
}
@end
|