-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPDCaseInsensitiveComboBoxCell.m
45 lines (39 loc) · 1.21 KB
/
PDCaseInsensitiveComboBoxCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// PDCaseInsensitiveComboBox.m
// SproutedInterface
//
// Created by Philip Dow on 3/17/07.
// Copyright Sprouted. All rights reserved.
// Inquiries should be directed to [email protected]
//
#import <SproutedInterface/PDCaseInsensitiveComboBoxCell.h>
@implementation PDCaseInsensitiveComboBoxCell
-(NSString*)completedString:(NSString*)substring
{
if([self usesDataSource])
{
return[super completedString:substring];
}
else //basicallydowhatcompleteshoulddo--becaseinsensitive.
{
NSArray* currentList=[self objectValues];
NSEnumerator* theEnum=[currentList objectEnumerator];
id eachString;
int maxLength=0;
NSString* bestMatch=@"";
while(nil!=(eachString=[theEnum nextObject]))
{
NSString* commonPrefix= [eachString commonPrefixWithString:substring options:NSCaseInsensitiveSearch];
if([commonPrefix length]>=[substring length]&&[commonPrefix length]>maxLength)
{
maxLength=[commonPrefix length];
bestMatch=eachString;
break;
//Build match string based on what user has typed so far, to show changes in capitalization.
//bestMatch=[NSString stringWithFormat:@"%@%@",substring, [eachString substringFromIndex:[substringlength]]];
}
}
return bestMatch;
}
}
@end