Commits

Anonymous committed 0fe46bc

Moved the Finder-like sorting code to its own file, as I'll be using it in the import window as well. Refs #621.

  • Participants
  • Parent commits 1dbcc9b
  • Branches default

Comments (0)

Files changed (4)

Developer Tools/Growl Registration Dictionary Editor/GRDEAppDelegate.m

 #import "GRDEAppDelegate.h"
 
 #import "GRDEDocument.h"
-
-#include <sys/param.h>
-
-static int sortFilenamesLikeFinder(id filenameA, id filenameB, void *context);
+#import "NSString+FinderLikeSorting.h"
 
 @implementation GRDEAppDelegate
 
 }
 
 @end
-
-//Sorting Like the Finder: http://developer.apple.com/qa/qa2004/qa1159.html
-static int sortFilenamesLikeFinder(id filenameA, id filenameB, void *context) {
-	static UTF16Char filenameA_UTF16[MAXPATHLEN];
-	[filenameA getCharacters:filenameA_UTF16];
-	static UTF16Char filenameB_UTF16[MAXPATHLEN];
-	[filenameB getCharacters:filenameB_UTF16];
-
-	SInt32 comparisonResult;
-	OSStatus err = UCCompareTextDefault(  kUCCollateComposeInsensitiveMask
-	                                    | kUCCollateWidthInsensitiveMask
-	                                    | kUCCollateCaseInsensitiveMask
-	                                    | kUCCollateDigitsOverrideMask
-	                                    | kUCCollateDigitsAsNumberMask
-	                                    | kUCCollatePunctuationSignificantMask,
-	                                    filenameA_UTF16,
-	                                    [filenameA length],
-	                                    filenameB_UTF16,
-	                                    [filenameB length],
-	                                    /*equivalent?*/ NULL,
-	                                    &comparisonResult);
-	
-	/*Quoth the technote:
-	 *
-	 *Return the result.  Conveniently, UCCompareTextDefault
-     *returns -1, 0, or +1, which matches the values for
-     *~~CF~~NSComparisonResult exactly.
-	 */
-    return (NSComparisonResult)comparisonResult;
-}

Developer Tools/Growl Registration Dictionary Editor/Growl Registration Dictionary Editor.xcodeproj/project.pbxproj

 		072DC3B709F2383600B8D4EC /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 072DC3B609F2383600B8D4EC /* Carbon.framework */; };
 		072DC3D509F25F2000B8D4EC /* AXCArrayControllerWithDragAndDrop.m in Sources */ = {isa = PBXBuildFile; fileRef = 072DC3D409F25F2000B8D4EC /* AXCArrayControllerWithDragAndDrop.m */; };
 		0752F6BA09F878A400032AAC /* NSMutableDictionary+Intersection.m in Sources */ = {isa = PBXBuildFile; fileRef = 0752F6B909F878A400032AAC /* NSMutableDictionary+Intersection.m */; };
+		31135DFC0CB13CDD002BD7DA /* NSString+FinderLikeSorting.m in Sources */ = {isa = PBXBuildFile; fileRef = 31135DFB0CB13CDD002BD7DA /* NSString+FinderLikeSorting.m */; };
 		3181A5540CA87EDE006B6B5D /* Notify code samples in Resources */ = {isa = PBXBuildFile; fileRef = 3181A5500CA87EDE006B6B5D /* Notify code samples */; };
 		3181A5560CA896AB006B6B5D /* GRDECodeSampleIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 3181A5550CA896AB006B6B5D /* GRDECodeSampleIcon.icns */; };
 		3181A5610CA89D0B006B6B5D /* GRDEAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3181A5600CA89D0B006B6B5D /* GRDEAppDelegate.m */; };
 		2A37F4BAFDCFA73011CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = English; path = English.lproj/Credits.rtf; sourceTree = "<group>"; };
 		2A37F4C4FDCFA73011CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
 		2A37F4C5FDCFA73011CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
+		31135DFA0CB13CDD002BD7DA /* NSString+FinderLikeSorting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+FinderLikeSorting.h"; sourceTree = "<group>"; };
+		31135DFB0CB13CDD002BD7DA /* NSString+FinderLikeSorting.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+FinderLikeSorting.m"; sourceTree = "<group>"; };
 		3181A5500CA87EDE006B6B5D /* Notify code samples */ = {isa = PBXFileReference; lastKnownFileType = folder; path = "Notify code samples"; sourceTree = "<group>"; };
 		3181A5550CA896AB006B6B5D /* GRDECodeSampleIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = GRDECodeSampleIcon.icns; path = "GRDE Code Sample icon/GRDECodeSampleIcon.icns"; sourceTree = "<group>"; };
 		3181A55F0CA89D0B006B6B5D /* GRDEAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GRDEAppDelegate.h; sourceTree = "<group>"; };
 			children = (
 				0752F6B809F878A400032AAC /* NSMutableDictionary+Intersection.h */,
 				0752F6B909F878A400032AAC /* NSMutableDictionary+Intersection.m */,
+				31135DFA0CB13CDD002BD7DA /* NSString+FinderLikeSorting.h */,
+				31135DFB0CB13CDD002BD7DA /* NSString+FinderLikeSorting.m */,
 			);
 			name = Additions;
 			sourceTree = "<group>";
 				072DC3D509F25F2000B8D4EC /* AXCArrayControllerWithDragAndDrop.m in Sources */,
 				0752F6BA09F878A400032AAC /* NSMutableDictionary+Intersection.m in Sources */,
 				3181A5610CA89D0B006B6B5D /* GRDEAppDelegate.m in Sources */,
+				31135DFC0CB13CDD002BD7DA /* NSString+FinderLikeSorting.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Developer Tools/Growl Registration Dictionary Editor/NSString+FinderLikeSorting.h

+//
+//  NSString+FinderLikeSorting.h
+//  Growl Registration Dictionary Editor
+//
+//  Created by Peter Hosey on 2007-10-01.
+//  Copyright 2007 Peter Hosey. All rights reserved.
+//
+
+@interface NSString (FinderLikeSorting)
+
+//Sort two strings (ostensibly, filenames) like the Finder would. Uses the QA1159 algorithm: http://developer.apple.com/qa/qa2004/qa1159.html
+- (NSComparisonResult) finderCompare:(NSString *)other;
+
+@end
+
+/*Comparison function for use with -[NSArray sortedArrayUsingFunction:context:] and -[NSMutableArray sortUsingFunction:context:].
+ *Should also work with CFArraySortValues, if you cast the function pointer (CF's comparator-function type doesn't use ids).
+ *Uses the QA1159 algorithm.
+ */
+extern int sortFilenamesLikeFinder(id filenameA, id filenameB, void *context);

Developer Tools/Growl Registration Dictionary Editor/NSString+FinderLikeSorting.m

+//
+//  NSString+FinderLikeSorting.m
+//  Growl Registration Dictionary Editor
+//
+//  Created by Peter Hosey on 2007-10-01.
+//  Copyright 2007 Peter Hosey. All rights reserved.
+//
+
+#import "NSString+FinderLikeSorting.h"
+
+#include <sys/param.h>
+
+@implementation NSString (FinderLikeSorting)
+
+- (NSComparisonResult) finderCompare:(NSString *)other {
+	return sortFilenamesLikeFinder(self, other, /*context*/ NULL);
+}
+
+@end
+
+//Based on sample code from QA1159: http://developer.apple.com/qa/qa2004/qa1159.html
+int sortFilenamesLikeFinder(id filenameA, id filenameB, void *context) {
+	static UTF16Char filenameA_UTF16[MAXPATHLEN];
+	[filenameA getCharacters:filenameA_UTF16];
+	static UTF16Char filenameB_UTF16[MAXPATHLEN];
+	[filenameB getCharacters:filenameB_UTF16];
+
+	SInt32 comparisonResult;
+	OSStatus err = UCCompareTextDefault(  kUCCollateComposeInsensitiveMask
+	                                    | kUCCollateWidthInsensitiveMask
+	                                    | kUCCollateCaseInsensitiveMask
+	                                    | kUCCollateDigitsOverrideMask
+	                                    | kUCCollateDigitsAsNumberMask
+	                                    | kUCCollatePunctuationSignificantMask,
+	                                    filenameA_UTF16,
+	                                    [filenameA length],
+	                                    filenameB_UTF16,
+	                                    [filenameB length],
+	                                    /*equivalent?*/ NULL,
+	                                    &comparisonResult);
+
+	/*Quoth the technote:
+	 *
+	 *Return the result.  Conveniently, UCCompareTextDefault
+	 *returns -1, 0, or +1, which matches the values for
+	 *~~CF~~NSComparisonResult exactly.
+	 */
+    return (NSComparisonResult)comparisonResult;
+}