aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPExportFilenameUtilities.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2013-03-04 00:02:33 +0000
committerrowanbeentje <rowan@beent.je>2013-03-04 00:02:33 +0000
commitf2545c5e4fc4414d4ee448de4a5f399d6cf58ad2 (patch)
tree1d523fb5fc8ace7f75401ce0a0c883592cd01ff4 /Source/SPExportFilenameUtilities.m
parent5ab13b27148a09e5bbf28c9ecfb7a8303b42462d (diff)
downloadsequelpro-f2545c5e4fc4414d4ee448de4a5f399d6cf58ad2.tar.gz
sequelpro-f2545c5e4fc4414d4ee448de4a5f399d6cf58ad2.tar.bz2
sequelpro-f2545c5e4fc4414d4ee448de4a5f399d6cf58ad2.zip
- Add support for export path tokens containing non-alphanumeric characters, automatically grouping and tokenising as required for both dragged and typed tokens. This addresses Issue #1567.
Diffstat (limited to 'Source/SPExportFilenameUtilities.m')
-rw-r--r--Source/SPExportFilenameUtilities.m55
1 files changed, 41 insertions, 14 deletions
diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m
index 1a14ef6c..5ea5bb44 100644
--- a/Source/SPExportFilenameUtilities.m
+++ b/Source/SPExportFilenameUtilities.m
@@ -150,8 +150,7 @@
*/
- (void)tokenizeCustomFilenameTokenField
{
- NSCharacterSet *nonAlphanumericSet = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
- NSArray *validTokens = [exportCustomFilenameTokensField objectValue];
+ NSCharacterSet *alphanumericSet = [NSCharacterSet alphanumericCharacterSet];
if ([exportCustomFilenameTokenField currentEditor] == nil) return;
@@ -163,21 +162,49 @@
// Retrieve the object value of the token field. This consists of plain text and recognised tokens interspersed.
NSArray *representedObjects = [exportCustomFilenameTokenField objectValue];
- // Walk through the strings - not the tokens - and determine whether any need tokenizing
+ // Walk through the strings - not the tokens - and determine whether any need tokenizing,
+ // including scanning for groups of strings which make up a single token
BOOL tokenizingRequired = NO;
-
- for (id representedObject in representedObjects)
- {
- if ([representedObject isKindOfClass:[SPExportFileNameTokenObject class]]) continue;
-
- NSArray *tokenParts = [representedObject componentsSeparatedByCharactersInSet:nonAlphanumericSet];
-
- for (NSString *tokenPart in tokenParts)
- {
- if ([validTokens containsObject:tokenPart]) {
- tokenizingRequired = YES;
+ NSUInteger i, j;
+ NSInteger k;
+ id tokenCheck;
+ NSMutableArray *tokenParts = [NSMutableArray array];
+
+ // Add all tokens, words, and separators to the array to process
+ for (id eachObject in representedObjects) {
+ if ([eachObject isKindOfClass:[SPExportFileNameTokenObject class]]) {
+ [tokenParts addObject:eachObject];
+ } else {
+ for (i = 0, j = 0; i < [(NSString *)eachObject length]; i++) {
+ if ([alphanumericSet characterIsMember:[eachObject characterAtIndex:i]]) {
+ continue;
+ }
+ if (i > j) {
+ [tokenParts addObject:[eachObject substringWithRange:NSMakeRange(j, i - j)]];
+ }
+ [tokenParts addObject:[eachObject substringWithRange:NSMakeRange(i, 1)]];
+ j = i + 1;
+ }
+ if (j < i) {
+ [tokenParts addObject:[eachObject substringWithRange:NSMakeRange(j, i - j)]];
+ }
+ }
+ }
+
+ // Walk through the array to process, scanning it for words or groups which are tokens
+ for (i = 0; i < [tokenParts count]; i++) {
+ for (k = i; k >= 0; k--) {
+
+ // Don't process existing token objects
+ if ([[tokenParts objectAtIndex:k] isKindOfClass:[SPExportFileNameTokenObject class]]) {
break;
}
+
+ // Check whether this item, or group of adjacent items, make up a token
+ tokenCheck = [self tokenObjectForString:[[tokenParts subarrayWithRange:NSMakeRange(k, 1 + i - k)] componentsJoinedByString:@""]];
+ if ([tokenCheck isKindOfClass:[SPExportFileNameTokenObject class]]) {
+ tokenizingRequired = YES;
+ }
}
}