Remove two warnings about using deprecated |+[NSString stringWithContentsOfFile:]|.
authorRobert Sesek <rsesek@bluestatic.org>
Fri, 24 Dec 2010 19:27:53 +0000 (14:27 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Fri, 24 Dec 2010 19:27:53 +0000 (14:27 -0500)
Source/BSSourceView.m

index c597ebb736be287f179ee7eff98a9c91af75aee2..f8ce52717a965eb52c62d03d5aaff19637177c35 100644 (file)
@@ -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];
   }
 }
 
 {
   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];
 }
 
 /**
   [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