aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-11-13 17:34:23 +0100
committerMax <post@wickenrode.com>2015-11-13 17:34:23 +0100
commit017ad9b38b87af09134c015086b47799acbcee0b (patch)
treeb32182acde2f9639670a0337da46e1ab5aa4d1e0 /Source
parent0dbadf887635bb3904d3aa64a0588a0b23d884dc (diff)
downloadsequelpro-017ad9b38b87af09134c015086b47799acbcee0b.tar.gz
sequelpro-017ad9b38b87af09134c015086b47799acbcee0b.tar.bz2
sequelpro-017ad9b38b87af09134c015086b47799acbcee0b.zip
Fix: "Custom filename" in export dialog would accept multi line text (#2325)
Diffstat (limited to 'Source')
-rw-r--r--Source/SPExportControllerDelegate.m2
-rw-r--r--Source/SPStringAdditions.h7
-rw-r--r--Source/SPStringAdditions.m38
3 files changed, 46 insertions, 1 deletions
diff --git a/Source/SPExportControllerDelegate.m b/Source/SPExportControllerDelegate.m
index cf3101cf..0f18ef25 100644
--- a/Source/SPExportControllerDelegate.m
+++ b/Source/SPExportControllerDelegate.m
@@ -157,7 +157,7 @@ static inline BOOL IS_STRING(id x);
// if the string came from another app, paste it literal, tokenfield will take care of any conversions
NSString *raw = [pboard stringForType:NSPasteboardTypeString];
if(raw) {
- return @[raw];
+ return @[[raw stringByReplacingCharactersInSet:[NSCharacterSet newlineCharacterSet] withString:@" "]];
}
return nil;
diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h
index de6d8377..a5b1b468 100644
--- a/Source/SPStringAdditions.h
+++ b/Source/SPStringAdditions.h
@@ -78,6 +78,13 @@ static inline id NSMutableAttributedStringAttributeAtIndex(NSMutableAttributedSt
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet *)charSet;
- (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet *)charSet options:(NSUInteger)mask;
+/**
+ * Replace all occurances of any character in set with the replacement string
+ * @param set Characters to look for (MUST NOT be nil)
+ * @param string A replacement string (can be nil == empty string)
+ * @return A string with replacements applied
+ */
+- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet *)set withString:(NSString *)string;
- (CGFloat)levenshteinDistanceWithWord:(NSString *)stringB;
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m
index f8aeb296..25a21541 100644
--- a/Source/SPStringAdditions.m
+++ b/Source/SPStringAdditions.m
@@ -344,6 +344,44 @@ static NSInteger _smallestOf(NSInteger a, NSInteger b, NSInteger c);
return lineRangesArray;
}
+- (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet *)set withString:(NSString *)string
+{
+ NSUInteger len = [self length];
+ NSMutableString *newString = [NSMutableString string];
+
+ NSRange range = NSMakeRange (0, len);
+
+ while (true) {
+ NSRange substringRange;
+ NSUInteger pos = range.location;
+ BOOL endAfterInsert = NO;
+
+ range = [self rangeOfCharacterFromSet:set options:0 range:range];
+
+ if(range.location == NSNotFound) {
+ // insert the current substring up to the end
+ substringRange = NSMakeRange(pos, len - pos);
+ endAfterInsert = YES;
+ }
+ else {
+ // insert the current substring up to range.location
+ substringRange = NSMakeRange(pos, range.location - pos);
+ }
+
+ [newString appendString:[self substringWithRange:substringRange]];
+
+ if(endAfterInsert) break;
+
+ // insert the replacement character
+ [newString appendStringOrNil:string];
+
+ // continue after the replaced characters
+ range.location += range.length;
+ range.length = len - range.location;
+ }
+ return newString;
+}
+
/**
* Returns the string by removing the characters in the supplied set and options.
*/