diff options
Diffstat (limited to 'Plugins/BuiltInFunctions/HFSCodeFormatter.m')
-rw-r--r-- | Plugins/BuiltInFunctions/HFSCodeFormatter.m | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Plugins/BuiltInFunctions/HFSCodeFormatter.m b/Plugins/BuiltInFunctions/HFSCodeFormatter.m new file mode 100644 index 0000000..4c3d0c1 --- /dev/null +++ b/Plugins/BuiltInFunctions/HFSCodeFormatter.m @@ -0,0 +1,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 |