aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPExportFilenameUtilities.m8
-rw-r--r--Source/SPNarrowDownCompletion.m2
-rw-r--r--Source/SPStringAdditions.h14
-rw-r--r--Source/SPStringAdditions.m14
4 files changed, 33 insertions, 5 deletions
diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m
index df9d3a69..a65b8e53 100644
--- a/Source/SPExportFilenameUtilities.m
+++ b/Source/SPExportFilenameUtilities.m
@@ -346,15 +346,15 @@
NSString *tokenContent = [filenamePart tokenContent];
if ([tokenContent isEqualToString:NSLocalizedString(@"host", @"export filename host token")]) {
- [string appendString:[tableDocumentInstance host]];
+ [string appendStringOrNil:[tableDocumentInstance host]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"database", @"export filename database token")]) {
- [string appendString:[tableDocumentInstance database]];
+ [string appendStringOrNil:[tableDocumentInstance database]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"table", @"table")]) {
- [string appendString:(table) ? table : @""];
+ [string appendStringOrNil:table];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"date", @"export filename date token")]) {
[dateFormatter setDateStyle:NSDateFormatterShortStyle];
@@ -380,7 +380,7 @@
[string appendString:[dateFormatter stringFromDate:[NSDate date]]];
}
else if ([tokenContent isEqualToString:NSLocalizedString(@"favorite", @"export filename favorite name token")]) {
- [string appendString:[tableDocumentInstance name]];
+ [string appendStringOrNil:[tableDocumentInstance name]];
}
}
else {
diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m
index b9dba0e4..c2158299 100644
--- a/Source/SPNarrowDownCompletion.m
+++ b/Source/SPNarrowDownCompletion.m
@@ -441,7 +441,7 @@
} else {
if([[filtered objectAtIndex:rowIndex] objectForKey:@"list"]) {
NSMutableString *tt = [NSMutableString string];
- [tt appendString:([[filtered objectAtIndex:rowIndex] objectForKey:@"type"]) ? [[filtered objectAtIndex:rowIndex] objectForKey:@"type"] : @""];
+ [tt appendStringOrNil:[[filtered objectAtIndex:rowIndex] objectForKey:@"type"]];
[tt appendString:@"\n"];
[tt appendString:NSLocalizedString(@"Type Declaration:", @"type declaration header")];
[tt appendString:@"\n"];
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h
index c6871e2a..7c0bfb90 100644
--- a/Source/SPStringAdditions.h
+++ b/Source/SPStringAdditions.h
@@ -101,3 +101,17 @@ static inline id NSMutableAttributedStringAttributeAtIndex(NSMutableAttributedSt
*/
- (BOOL)nonConsecutivelySearchString:(NSString *)other matchingRanges:(NSArray **)submatches;
@end
+
+@interface NSMutableString (SPStringAdditions)
+/**
+ * nil-safe variant of setString:
+ * nil will be interpreted as @"" instead of throwing an exception
+ */
+- (void)setStringOrNil:(NSString *)aString;
+
+/**
+ * nil-safe variant of appendString:
+ * nil will be interpreted as @"" instead of throwing an exception
+ */
+- (void)appendStringOrNil:(NSString *)aString;
+@end
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index 0254dc36..ebd81a54 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -562,3 +562,17 @@ static NSInteger _smallestOf(NSInteger a, NSInteger b, NSInteger c)
return min;
}
+
+@implementation NSMutableString (SPStringAdditions)
+
+- (void)setStringOrNil:(NSString *)aString
+{
+ [self setString:(aString? aString : @"")];
+}
+
+- (void)appendStringOrNil:(NSString *)aString
+{
+ [self appendString:(aString? aString : @"")];
+}
+
+@end