The R Project SVN R-packages

Rev

Rev 5705 | Rev 5862 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5705 Rev 5707
Line 68... Line 68...
68
			[re endProtected];
68
			[re endProtected];
69
            return nil;
69
            return nil;
70
        }
70
        }
71
        
71
        
72
        { // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
72
        { // the following code works also if pattern is not specified; with pattern present we could make it even easier, but currently we use it just to narrow the search (e.g. "." could still be matched by something else ...)
73
            int i=0, firstMatch=-1, matches=0;
73
            int i=0, matches=0;
74
            NSString *common=nil;
74
            NSString *common=nil;
75
            while (i<[a count]) {
75
            while (i<[a count]) {
76
                NSString *sx = (NSString*) [a objectAtIndex:i];
76
                NSString *sx = (NSString*) [a objectAtIndex:i];
77
                if ([sx hasPrefix: part]) {
77
                if ([sx hasPrefix: part]) {
78
                    if (matches==0) {
78
                    if (matches==0)
79
                        firstMatch=i;
-
 
80
                        common=[[NSString alloc] initWithString: sx];
79
                        common = [[NSString alloc] initWithString: sx];
81
                    } else {
80
                    else {
82
                        NSString *cpref=[[NSString alloc] initWithString:[common commonPrefixWithString:sx options:0]];
81
                        NSString *cpref=[[NSString alloc] initWithString:[common commonPrefixWithString:sx options:0]];
83
                        [common release];
82
                        [common release];
84
                        common=cpref;
83
                        common = cpref;
85
                    }
84
                    }
86
                    matches++;
85
                    matches++;
87
                }
86
                }
88
                i++;
87
                i++;
89
            }
88
            }
90
            if (common!=nil) { // attempt to get class of the object - it will fail if that's just a partial object, but who cares..
89
            if (common) { // attempt to get class of the object - it will fail if that's just a partial object, but who cares..
91
                x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
90
                    x = [re evaluateString:[NSString stringWithFormat:@"try(class(%@),silent=TRUE)",common]];
92
				[re endProtected];
91
                    [re endProtected];
93
                if (x!=nil && [x string]!=nil && [[x string] isEqualToString:@"function"])
92
                if (x && [x string] && [[x string] isEqualToString:@"function"])
94
                    return [[common autorelease] stringByAppendingString:@"("];
93
                    return [[common autorelease] stringByAppendingString:@"("];
95
                else
94
                else
96
                    return [common autorelease];
95
                    return [common autorelease];
97
            }
96
            }
98
        }
97
        }