blob: 43b068283c852b867c2c03fc8eaf76df78f403dd [file] [log] [blame]
Jean-Baptiste Querub56ea2a2013-01-08 11:11:20 -08001//
2// Created by max on 11/6/12.
3//
4// To change the template use AppCode | Preferences | File Templates.
5//
6
7
8#import "PropertyFileReader.h"
9#import "utils.h"
10
11
12@implementation PropertyFileReader {
13}
14
15+ (void)parseProperty:(NSString *)string to:(NSMutableDictionary *)to {
16 NSRange delimiter = [string rangeOfString:@"="];
17 if (delimiter.length > 0 && delimiter.location + 1 <= string.length) {
18 NSString *key = [string substringToIndex:delimiter.location];
19 NSString *value=[string substringFromIndex:delimiter.location + 1];
20 [to setObject:value forKey:key];
21 }
22}
23
24+ (NSDictionary *)readFile:(NSString *)path {
25 NSMutableDictionary *answer = [NSMutableDictionary dictionary];
26
27 NSString *contents = readFile(path);
28
29 if (contents) {
30 NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
31 for (NSString *line in lines) {
32 NSString *trimmedLine = trim(line);
33 if ([trimmedLine length] > 0) {
34 if ([trimmedLine characterAtIndex:0] != '#') {
35 [self parseProperty:trimmedLine to:answer];
36 }
37 }
38 }
39
40 return answer;
41 }
42
43 return nil;
44}
45
46@end