Files
openide/native/MacLauncher/PropertyFileReader.m
Roman Shevchenko 1972f691fd [platform] compilation warnings in macOS launcher
GitOrigin-RevId: 6035b3bf384d8ec255a00084944c3e5d7def5038
2021-01-27 12:30:57 +00:00

42 lines
1.2 KiB
Objective-C

// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
#import "PropertyFileReader.h"
#import "utils.h"
@implementation PropertyFileReader {
}
+ (void)parseProperty:(NSString *)string to:(NSMutableDictionary *)to {
NSRange delimiter = [string rangeOfString:@"="];
if (delimiter.length > 0 && delimiter.location + 1 <= string.length) {
NSString *key = [string substringToIndex:delimiter.location];
NSString *value=[string substringFromIndex:delimiter.location + 1];
to[key] = value;
}
}
+ (NSDictionary *)readFile:(NSString *)path {
NSMutableDictionary *answer = [NSMutableDictionary dictionary];
NSString *contents = readFile(path);
if (contents) {
NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (NSString *line in lines) {
NSString *trimmedLine = trim(line);
if ([trimmedLine length] > 0) {
if ([trimmedLine characterAtIndex:0] != '#') {
[self parseProperty:trimmedLine to:answer];
}
}
}
return answer;
}
return nil;
}
@end