Skip to content

Commit

Permalink
Merge pull request #76 from kognate/master
Browse files Browse the repository at this point in the history
[FIX] Stop using deprecated -[NSString initWithContentsOfFile:]. Fix a type error in MiscMerge. (Joshua Smith)
  • Loading branch information
rentzsch committed Nov 22, 2011
2 parents b2fd82c + 242a800 commit dc55ebb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MiscMerge/MiscMergeExpression.m
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ - (id)initWithExpressions:(NSArray *)list
{
self = [super init];
if ( self ) {
expressions = [list retain];
expressions = [list mutableCopy];
}
return self;
}
Expand Down
19 changes: 15 additions & 4 deletions MiscMerge/MiscMergeTemplate.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,25 @@ + (NSString *)defaultEndDelimiter
return self;
}

/* helper method to load string contents of filenames */
- (NSString *) contentsOfFileWithName:(NSString *)filename {
NSError *error = nil;
NSString *fileString = [NSString stringWithContentsOfFile:filename
encoding:NSASCIIStringEncoding
error:&error];

if (error != nil) {
NSLog(@"%@: Could not read template file %@ because %@", [self class], filename, [error localizedDescription]);
}
return fileString;
}

/*"
* Loads the contents of filename, then calls -#initWithString:.
"*/
- initWithContentsOfFile:(NSString *)filename
{
NSString *fileString = [[[NSString alloc] initWithContentsOfFile:filename] autorelease];
if (fileString == nil) NSLog(@"%@: Could not read template file %@", [self class], filename);
NSString *fileString = [self contentsOfFileWithName:filename];
return [self initWithString:fileString];
}

Expand Down Expand Up @@ -432,8 +444,7 @@ - (void)_addCommandString:(NSString *)commandString
"*/
- (void)parseContentsOfFile:(NSString *)filename
{
NSString *string = [[NSString alloc] initWithContentsOfFile:filename];
if (string == nil) NSLog(@"%@: Could not read template file %@", [self class], filename);
NSString *string = [self contentsOfFileWithName:filename];
[self setFilename:filename];
[self parseString:string];
[string release];
Expand Down
5 changes: 3 additions & 2 deletions MiscMerge/_MiscMergeIncludeCommand.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ - (BOOL)parseFromScanner:(NSScanner *)aScanner template:(MiscMergeTemplate *)tem

resolvedFilename = [template resolveTemplateFilename:filename];

NSError *error = nil;
if ([resolvedFilename length] > 0)
fileString = [[[NSString alloc] initWithContentsOfFile:resolvedFilename] autorelease];
fileString = [NSString stringWithContentsOfFile:resolvedFilename encoding:NSASCIIStringEncoding error:&error];

if (fileString)
{
Expand All @@ -72,7 +73,7 @@ - (BOOL)parseFromScanner:(NSScanner *)aScanner template:(MiscMergeTemplate *)tem
}
else
{
[template reportParseError:@"%@: Could not load from file '%@'", [self class], resolvedFilename];
[template reportParseError:@"%@: Could not load from file '%@' because %@", [self class], resolvedFilename, [error localizedDescription]];
}

return YES;
Expand Down

0 comments on commit dc55ebb

Please sign in to comment.