diff --git a/src/OFString+Cube.h b/src/OFString+Cube.h new file mode 100644 index 0000000..2d10d4a --- /dev/null +++ b/src/OFString+Cube.h @@ -0,0 +1,8 @@ +#import + +@interface +OFString (Cube) +@property (readonly, nonatomic) int cube_intValue; + +- (int)cube_intValueWithBase:(unsigned char)base; +@end diff --git a/src/OFString+Cube.mm b/src/OFString+Cube.mm new file mode 100644 index 0000000..b16d19f --- /dev/null +++ b/src/OFString+Cube.mm @@ -0,0 +1,32 @@ +#import "OFString+Cube.h" + +#include "cube.h" + +@implementation +OFString (Cube) +- (int)cube_intValue +{ + @try { + return self.intValue; + } @catch (OFInvalidFormatException *e) { + conoutf(@"invalid value: %@", self); + return 0; + } @catch (OFOutOfRangeException *e) { + conoutf(@"invalid value: %@", self); + return 0; + } +} + +- (int)cube_intValueWithBase:(unsigned char)base +{ + @try { + return [self intValueWithBase:base]; + } @catch (OFInvalidFormatException *e) { + conoutf(@"invalid value: %@", self); + return 0; + } @catch (OFOutOfRangeException *e) { + conoutf(@"invalid value: %@", self); + return 0; + } +} +@end