diff options
author | Joseph Heenan <joseph@emobix.co.uk> | 2016-06-05 12:45:58 +0100 |
---|---|---|
committer | Joseph Heenan <joseph@emobix.co.uk> | 2016-06-09 10:57:47 +0100 |
commit | f53d79f0afd39d47f173530c59a00eb16b12bcba (patch) | |
tree | 208ec4e3cb2902e475cf5fd3338c523dd15c0efa /platform/ios | |
parent | 917b8ef89a75fbbce80a6eba506829f45470645c (diff) | |
download | mupdf-f53d79f0afd39d47f173530c59a00eb16b12bcba.tar.xz |
iOS: Replace char * with NSString in ObjC APIs
What is effectively our external API on iOS would be expected to use
NSString rather than char *.
Diffstat (limited to 'platform/ios')
-rw-r--r-- | platform/ios/Classes/MuDocRef.h | 2 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocRef.m | 4 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.h | 2 | ||||
-rw-r--r-- | platform/ios/Classes/MuDocumentController.m | 20 | ||||
-rw-r--r-- | platform/ios/Classes/MuLibraryController.m | 15 |
5 files changed, 20 insertions, 23 deletions
diff --git a/platform/ios/Classes/MuDocRef.h b/platform/ios/Classes/MuDocRef.h index 3741c691..98800bf9 100644 --- a/platform/ios/Classes/MuDocRef.h +++ b/platform/ios/Classes/MuDocRef.h @@ -8,5 +8,5 @@ fz_document *doc; bool interactive; } --(id) initWithFilename:(char *)aFilename; +-(id) initWithFilename:(NSString *)aFilename; @end diff --git a/platform/ios/Classes/MuDocRef.m b/platform/ios/Classes/MuDocRef.m index 9a178484..c5a22633 100644 --- a/platform/ios/Classes/MuDocRef.m +++ b/platform/ios/Classes/MuDocRef.m @@ -4,7 +4,7 @@ @implementation MuDocRef --(id) initWithFilename:(char *)aFilename; +-(id) initWithFilename:(NSString *)aFilename; { self = [super init]; if (self) @@ -15,7 +15,7 @@ fz_try(ctx) { - doc = fz_open_document(ctx, aFilename); + doc = fz_open_document(ctx, aFilename.UTF8String); if (!doc) { [self release]; diff --git a/platform/ios/Classes/MuDocumentController.h b/platform/ios/Classes/MuDocumentController.h index 8a905536..887c248e 100644 --- a/platform/ios/Classes/MuDocumentController.h +++ b/platform/ios/Classes/MuDocumentController.h @@ -25,7 +25,7 @@ enum }; @interface MuDocumentController : UIViewController <UIScrollViewDelegate, UIGestureRecognizerDelegate, UISearchBarDelegate, MuDialogCreator, MuUpdater> -- (id) initWithFilename: (NSString*)nsfilename path:(char *)cstr document:(MuDocRef *)aDoc; +- (id) initWithFilename: (NSString*)nsfilename path:(NSString *)path document:(MuDocRef *)aDoc; - (void) createPageView: (int)number; - (void) gotoPage: (int)number animated: (BOOL)animated; - (void) onShowOutline: (id)sender; diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index 1b39e3c1..2ae106fb 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -43,7 +43,7 @@ static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_out } } -static char *tmp_path(char *path) +static char *tmp_path(const char *path) { int f; char *buf = malloc(strlen(path) + 6 + 1); @@ -67,7 +67,7 @@ static char *tmp_path(char *path) } } -static void saveDoc(char *current_path, fz_document *doc) +static void saveDoc(const char *current_path, fz_document *doc) { char *tmp; pdf_document *idoc = pdf_specifics(ctx, doc); @@ -129,7 +129,7 @@ static void saveDoc(char *current_path, fz_document *doc) fz_document *doc; MuDocRef *docRef; NSString *key; - char *filePath; + NSString *_filePath; BOOL reflowMode; MuOutlineController *outline; UIScrollView *canvas; @@ -158,7 +158,7 @@ static void saveDoc(char *current_path, fz_document *doc) BOOL _isRotating; } -- (id) initWithFilename: (NSString*)filename path:(char *)cstr document: (MuDocRef *)aDoc +- (id) initWithFilename: (NSString*)filename path:(NSString *)cstr document: (MuDocRef *)aDoc { self = [super init]; if (!self) @@ -168,10 +168,10 @@ static void saveDoc(char *current_path, fz_document *doc) if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) self.automaticallyAdjustsScrollViewInsets = NO; #endif - key = [filename retain]; + key = [filename copy]; docRef = [aDoc retain]; doc = docRef->doc; - filePath = strdup(cstr); + _filePath = [cstr copy]; // this will be created right before the outline is shown outline = nil; @@ -341,7 +341,7 @@ static void saveDoc(char *current_path, fz_document *doc) [tickButton release]; tickButton = nil; [deleteButton release]; deleteButton = nil; [canvas release]; canvas = nil; - free(filePath); filePath = NULL; + [_filePath release]; _filePath = NULL; [outline release]; [key release]; @@ -588,7 +588,7 @@ static void saveDoc(char *current_path, fz_document *doc) - (void) shareDocument { - NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filePath]]; + NSURL *url = [NSURL fileURLWithPath:_filePath]; UIActivityViewController *cont = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObject:url] applicationActivities:nil]; cont.popoverPresentationController.barButtonItem = shareButton; [self presentViewController:cont animated:YES completion:nil]; @@ -779,7 +779,7 @@ static void saveDoc(char *current_path, fz_document *doc) if ([CloseAlertMessage isEqualToString:alertView.message]) { if (buttonIndex == 1) - saveDoc(filePath, doc); + saveDoc(_filePath.UTF8String, doc); [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES]; [[self navigationController] popViewControllerAnimated:YES]; @@ -790,7 +790,7 @@ static void saveDoc(char *current_path, fz_document *doc) [alertView dismissWithClickedButtonIndex:buttonIndex animated:NO]; if (buttonIndex == 1) { - saveDoc(filePath, doc); + saveDoc(_filePath.UTF8String, doc); [self shareDocument]; } } diff --git a/platform/ios/Classes/MuLibraryController.m b/platform/ios/Classes/MuLibraryController.m index e5a1787f..10541475 100644 --- a/platform/ios/Classes/MuLibraryController.m +++ b/platform/ios/Classes/MuLibraryController.m @@ -20,7 +20,7 @@ static void showAlert(NSString *msg, NSString *filename) NSTimer *timer; MuDocRef *doc; NSString *_filename; - char *_filePath; + NSString *_filePath; } - (void) viewWillAppear: (BOOL)animated @@ -186,16 +186,13 @@ static NSString *moveOutOfInbox(NSString *docpath) - (void) openDocument: (NSString*)nsfilename { nsfilename = moveOutOfInbox(nsfilename); - NSString *nspath = [[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", nsfilename, nil] - componentsJoinedByString:@"/"]; - _filePath = malloc(strlen([nspath UTF8String])+1); + _filePath = [[[NSArray arrayWithObjects:NSHomeDirectory(), @"Documents", nsfilename, nil] + componentsJoinedByString:@"/"] retain]; if (_filePath == NULL) { showAlert(@"Out of memory in openDocument", nsfilename); return; } - strcpy(_filePath, [nspath UTF8String]); - dispatch_sync(queue, ^{}); _filename = [nsfilename retain]; @@ -227,7 +224,7 @@ static NSString *moveOutOfInbox(NSString *docpath) - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - char *password = (char*) [[[alertView textFieldAtIndex: 0] text] UTF8String]; + const char *password = [[[alertView textFieldAtIndex: 0] text] UTF8String]; [alertView dismissWithClickedButtonIndex: buttonIndex animated: TRUE]; if (buttonIndex == 1) { if (fz_authenticate_password(ctx, doc->doc, password)) @@ -248,13 +245,13 @@ static NSString *moveOutOfInbox(NSString *docpath) [document release]; } [_filename release]; - free(_filePath); + [_filePath release]; } - (void) onPasswordCancel { [_filename release]; - free(_filePath); + [_filePath release]; } @end |