mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Implement completePathIntoString
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3073 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
8c8a2b47ac
commit
d52a07b1b3
3 changed files with 51 additions and 7 deletions
|
@ -49,6 +49,8 @@
|
|||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
|
||||
#include <gnustep/base/IndexedCollection.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
|
@ -2141,14 +2143,52 @@ else
|
|||
|
||||
// Manipulating File System Paths
|
||||
|
||||
|
||||
- (unsigned int) completePathIntoString: (NSString**)outputName
|
||||
caseSensitive: (BOOL)flag
|
||||
matchesIntoArray: (NSArray**)outputArray
|
||||
filterTypes: (NSArray*)filterTypes
|
||||
{
|
||||
[self notImplemented:_cmd];
|
||||
return 0;
|
||||
NSString * base_path = [self stringByDeletingLastPathComponent];
|
||||
NSString * last_compo = [self lastPathComponent];
|
||||
NSString * tmp_path;
|
||||
NSDirectoryEnumerator * e;
|
||||
int match_count = 0;
|
||||
|
||||
if (outputName != NULL) *outputName = nil;
|
||||
|
||||
if ([base_path length] == 0) base_path = @".";
|
||||
|
||||
e = [[NSFileManager defaultManager] enumeratorAtPath: base_path];
|
||||
while (tmp_path = [e nextObject], tmp_path)
|
||||
{
|
||||
/* Prefix matching */
|
||||
if (YES == flag)
|
||||
{ /* Case sensitive */
|
||||
if (NO == [tmp_path hasPrefix: last_compo])
|
||||
continue ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (NO == [[tmp_path uppercaseString]
|
||||
hasPrefix: [last_compo uppercaseString]])
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Extensions filtering */
|
||||
if (filterTypes &&
|
||||
(NO == [filterTypes containsObject: [tmp_path pathExtension]]))
|
||||
continue ;
|
||||
|
||||
/* Found a completion */
|
||||
match_count++;
|
||||
if (outputArray != NULL)
|
||||
[*outputArray addObject: tmp_path];
|
||||
|
||||
if ((outputName != NULL) &&
|
||||
((*outputName == nil) || (([*outputName length] < [tmp_path length]))))
|
||||
*outputName = tmp_path;
|
||||
}
|
||||
return match_count;
|
||||
}
|
||||
|
||||
/* Return a string for passing to OS calls to handle file system objects. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue