@@ -27,35 +27,36 @@ #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" OF_DIRECT_MEMBERS @interface OFINIFile () -- (void)of_parseFile: (OFString *)path - encoding: (of_string_encoding_t)encoding; +- (void)of_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = line.UTF8String; size_t length = line.UTF8StringLength; for (size_t i = 0; i < length; i++) - if (!of_ascii_isspace(cString[i])) + if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile +@synthesize categories = _categories; + + (instancetype)fileWithPath: (OFString *)path { return [[[self alloc] initWithPath: path] autorelease]; } + (instancetype)fileWithPath: (OFString *)path - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithPath: path encoding: encoding] autorelease]; } @@ -64,24 +65,22 @@ OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path { - return [self initWithPath: path - encoding: OF_STRING_ENCODING_UTF_8]; + return [self initWithPath: path encoding: OFStringEncodingUTF8]; } - (instancetype)initWithPath: (OFString *)path - encoding: (of_string_encoding_t)encoding + encoding: (OFStringEncoding)encoding { self = [super init]; @try { _categories = [[OFMutableArray alloc] init]; - [self of_parseFile: path - encoding: encoding]; + [self of_parseFile: path encoding: encoding]; } @catch (id e) { [self release]; @throw e; } @@ -110,21 +109,19 @@ objc_autoreleasePoolPop(pool); return category; } -- (void)of_parseFile: (OFString *)path - encoding: (of_string_encoding_t)encoding +- (void)of_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file; OFINICategory *category = nil; OFString *line; @try { - file = [OFFile fileWithPath: path - mode: @"r"]; + file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if (e.errNo == ENOENT) return; @@ -140,12 +137,11 @@ if (![line hasSuffix: @"]"]) @throw [OFInvalidFormatException exception]; categoryName = [line substringWithRange: - of_range(1, line.length - 2)]; - + OFRangeMake(1, line.length - 2)]; category = [[[OFINICategory alloc] of_initWithName: categoryName] autorelease]; [_categories addObject: category]; } else { if (category == nil) @@ -158,20 +154,17 @@ objc_autoreleasePoolPop(pool); } - (void)writeToFile: (OFString *)path { - [self writeToFile: path - encoding: OF_STRING_ENCODING_UTF_8]; + [self writeToFile: path encoding: OFStringEncodingUTF8]; } -- (void)writeToFile: (OFString *)path - encoding: (of_string_encoding_t)encoding +- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); - OFFile *file = [OFFile fileWithPath: path - mode: @"w"]; + OFFile *file = [OFFile fileWithPath: path mode: @"w"]; bool first = true; for (OFINICategory *category in _categories) if ([category of_writeToStream: file encoding: encoding @@ -178,6 +171,12 @@ first: first]) first = false; objc_autoreleasePoolPop(pool); } + +- (OFString *)description +{ + return [OFString stringWithFormat: @"<%@: %@>", + self.class, _categories]; +} @end