diff options
author | rowanbeentje <rowan@beent.je> | 2013-04-28 12:33:02 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2013-04-28 12:33:02 +0000 |
commit | 0a7ac2792eafc65b59bf156defb322526adf79d7 (patch) | |
tree | 1f4b06c0f7001d13ef1e66769dbf91bd36bf2e91 /Source/SPExportFilenameUtilities.m | |
parent | 3a440aa512f3524545dc0b1ec39362d052ed4806 (diff) | |
download | sequelpro-0a7ac2792eafc65b59bf156defb322526adf79d7.tar.gz sequelpro-0a7ac2792eafc65b59bf156defb322526adf79d7.tar.bz2 sequelpro-0a7ac2792eafc65b59bf156defb322526adf79d7.zip |
Merge a number of revisions from trunk back to the 1.0.x release branch:
- r4021: Add a check for SPNotLoaded values when automatically generating new tables when importing CSVs, fixing Issue #1621 (SPNotLoaded values are generated when rows shorter than the header row are seen)
- r4022: Fix crashes when importing favorites on the connection view, addressing Issue #1556; Select and scroll to newly created favorites after import
- r4023: Default to disabling SSH multiplexing to avoid connection issues as per Issue #1457; leave multiplexing code present, but behind a preference. Run `defaults write com.sequelpro.SequelPro SSHMultiplexingEnabled -boolean YES` to re-enable
- r4024: Fix handling of double-dash style comments within field names, addressing Issue #1554
- r4025: When favorites in the connection view gave no password, no longer set the focus to the password field as soon as they're selected; instead, make the password field the next responder for tab keys. This addresses Issue #1555
- r4028: Fix escaping of backlsashes in non-LIKE clauses, addressing string matching with the = and RegExp operators - addresses Issue #1563
- r4029: Fix handling of primary keys listing multiple fields of which an early field has a specified length, addressing Issue #1641
- r4030: Alter the database creation sheet to correctly use the selected new database encoding; Clean up the database creation logic and remove redundant selection logic; Correctly reset and detect the database encoding when creating and switching databases
- r4031: Fix blurry text in a number of text views in 1.0.x (Possibly caused by IB mangling; recreated new text views with the same settings to address). This fixes Issue #1560
- r4032: Detect deleted or non-writable folders for export targets and give appropriate errors (particularly for saved paths), addressing Issue #1566
- r4033: 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.m | 55 |
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; + } } } |