| 475 | | NSEnumerator *enumerator; |
|---|
| 476 | | NSArray *nicks, *commands, *set, *matches; |
|---|
| 477 | | NSString *p, *prefix; |
|---|
| 478 | | unsigned int i, count; |
|---|
| | 475 | NSEnumerator *enumerator, *setEnumerator; |
|---|
| | 476 | NSArray *nicks, *commands, *set, *matchingSet; |
|---|
| | 477 | NSString *match, *prefix = NULL; |
|---|
| | 478 | unsigned int matches = 0; |
|---|
| 485 | | matches = [set stringsMatchingString:string options:NSCaseInsensitiveSearch]; |
|---|
| 486 | | |
|---|
| 487 | | if([matches count] == 1) { |
|---|
| 488 | | string = [matches objectAtIndex:0]; |
|---|
| 489 | | |
|---|
| 490 | | if(set == nicks) { |
|---|
| 491 | | string = [string stringByAppendingString: |
|---|
| 492 | | [WCSettings objectForKey:WCTabCompleteNicksString]]; |
|---|
| | 485 | setEnumerator = [set objectEnumerator]; |
|---|
| | 486 | |
|---|
| | 487 | while((match = [setEnumerator nextObject])) { |
|---|
| | 488 | if([match rangeOfString:string options:NSCaseInsensitiveSearch].location == 0) { |
|---|
| | 489 | if(matches == 0) |
|---|
| | 490 | prefix = match; |
|---|
| | 491 | else |
|---|
| | 492 | prefix = [prefix commonPrefixWithString:match options:NSCaseInsensitiveSearch]; |
|---|
| | 493 | |
|---|
| | 494 | matchingSet = set; |
|---|
| | 495 | matches++; |
|---|
| 500 | | else if([matches count] > 1) { |
|---|
| 501 | | prefix = p = @""; |
|---|
| 502 | | count = [matches count] - 1; |
|---|
| 503 | | |
|---|
| 504 | | for(i = 0; i < count; i++) { |
|---|
| 505 | | p = [[matches objectAtIndex:i] commonPrefixWithString:[matches objectAtIndex:i + 1] |
|---|
| 506 | | options:NSCaseInsensitiveSearch]; |
|---|
| 507 | | |
|---|
| 508 | | if([p length] > [prefix length]) |
|---|
| 509 | | prefix = p; |
|---|
| 510 | | } |
|---|
| 511 | | |
|---|
| 512 | | if([prefix length] > 0) |
|---|
| 513 | | return prefix; |
|---|
| | 498 | } |
|---|
| | 499 | |
|---|
| | 500 | if(matches > 1) |
|---|
| | 501 | return prefix; |
|---|
| | 502 | |
|---|
| | 503 | if(matches == 1) { |
|---|
| | 504 | if(matchingSet == nicks) { |
|---|
| | 505 | return [prefix stringByAppendingString: |
|---|
| | 506 | [WCSettings objectForKey:WCTabCompleteNicksString]]; |
|---|