From 315191b18352a1e834e2d3b682987b3e025f7d7c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 24 Dec 2010 14:27:53 -0500 Subject: [PATCH] Remove two warnings about using deprecated |+[NSString stringWithContentsOfFile:]|. --- Source/BSSourceView.m | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/BSSourceView.m b/Source/BSSourceView.m index c597ebb..f8ce527 100644 --- a/Source/BSSourceView.m +++ b/Source/BSSourceView.m @@ -19,6 +19,7 @@ @interface BSSourceView (Private) - (void)setupViews; - (void)errorHighlightingFile:(NSNotification*)notif; +- (void)setPlainTextStringFromFile:(NSString*)filePath; @end @implementation BSSourceView @@ -97,7 +98,7 @@ @catch (NSException* exception) { // If the PHP executable is not available then the NSTask will throw an exception - [textView setString:[NSString stringWithContentsOfFile:f]]; + [self setPlainTextStringFromFile:f]; } } @@ -137,7 +138,7 @@ { NSData* data = [[notif userInfo] objectForKey:NSFileHandleNotificationDataItem]; if ([data length] > 0) // there's something on stderr, so the PHP CLI failed - [textView setString:[NSString stringWithContentsOfFile:file]]; + [self setPlainTextStringFromFile:file]; } /** @@ -217,4 +218,21 @@ [scrollView setDocumentView:textView]; } +/** + * Gets the plain-text representation of the file at |filePath| and sets the + * contents in the source view. + */ +- (void)setPlainTextStringFromFile:(NSString*)filePath +{ + NSError* error; + NSString* contents = [NSString stringWithContentsOfFile:filePath + encoding:NSUTF8StringEncoding + error:&error]; + if (error) { + NSLog(@"Error reading file at %@: %@", filePath, error); + return; + } + [textView setString:contents]; +} + @end -- 2.43.5