The R Project SVN R

Rev

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

Rev 34194 Rev 35796
Line 143... Line 143...
143
	if(!ISNAN(dblind))
143
	if(!ISNAN(dblind))
144
	    indx = integerOneIndex((int)dblind, len);
144
	    indx = integerOneIndex((int)dblind, len);
145
	break;
145
	break;
146
    case STRSXP:
146
    case STRSXP:
147
	/* Try for exact match */
147
	/* Try for exact match */
148
	for (i = 0; i < length(names); i++)
148
	for (i = 0; i < length(names); i++) 
-
 
149
	    if (STRING_ELT(names, i) == NA_STRING || 
-
 
150
		STRING_ELT(s, pos) == NA_STRING) {
-
 
151
		/* NA matches nothing */
-
 
152
	    } else {
149
	    if (streql(CHAR(STRING_ELT(names, i)),
153
		if (streql(CHAR(STRING_ELT(names, i)),
150
		       CHAR(STRING_ELT(s, pos)))) {
154
			   CHAR(STRING_ELT(s, pos)))) {
151
		indx = i;
155
		    indx = i;
152
		break;
156
		    break;
-
 
157
		}
153
	    }
158
	    }
154
	/* Try for partial match */
159
	/* Try for partial match */
155
	if (pok && indx < 0) {
160
	if (pok && indx < 0) {
-
 
161
	    if (STRING_ELT(names, i) == NA_STRING || 
-
 
162
		STRING_ELT(s, pos) == NA_STRING) {
-
 
163
		/* NA matches nothing */
-
 
164
	    } else {
156
	    len = strlen(CHAR(STRING_ELT(s, pos)));
165
		len = strlen(CHAR(STRING_ELT(s, pos)));
157
	    for(i = 0; i < length(names); i++) {
166
		for(i = 0; i < length(names); i++) {
158
		if(!strncmp(CHAR(STRING_ELT(names, i)),
167
		    if(!strncmp(CHAR(STRING_ELT(names, i)),
159
			    CHAR(STRING_ELT(s, pos)), len)) {
168
				CHAR(STRING_ELT(s, pos)), len)) {
160
		    if(indx == -1)/* first one */
169
			if(indx == -1)/* first one */
161
			indx = i;
170
			    indx = i;
162
		    else
171
			else
163
			indx = -2;/* more than one partial match */
172
			    indx = -2;/* more than one partial match */
-
 
173
		    }
164
		}
174
		}
165
	    }
175
	    }
166
	}
176
	}
167
	break;
177
	break;
168
    case SYMSXP:
178
    case SYMSXP:
169
	for (i = 0; i < length(names); i++)
179
	for (i = 0; i < length(names); i++)
-
 
180
	    if (STRING_ELT(names, i) != NA_STRING &&
170
	    if (streql(CHAR(STRING_ELT(names, i)), CHAR(PRINTNAME(s)))) {
181
		streql(CHAR(STRING_ELT(names, i)), CHAR(PRINTNAME(s)))) {
171
		indx = i;
182
		indx = i;
172
		break;
183
		break;
173
	    }
184
	    }
174
    default:
185
    default:
175
	error(_("invalid subscript type"));
186
	error(_("invalid subscript type"));
Line 375... Line 386...
375
     */
386
     */
376
 
387
 
377
#ifdef USE_HASHING
388
#ifdef USE_HASHING
378
    if(usehashing) {
389
    if(usehashing) {
379
	/* must be internal, so names contains a character vector */
390
	/* must be internal, so names contains a character vector */
-
 
391
	/* NB: this does not behave in the same way with respect to ""
-
 
392
	   and NA names: they will match */
380
	PROTECT(indx = match(names, s, 0));
393
	PROTECT(indx = match(names, s, 0));
-
 
394
	/* second pass to correct this */
-
 
395
	for (i = 0; i < ns; i++)
-
 
396
	    if(STRING_ELT(s, i) == NA_STRING || !CHAR(STRING_ELT(s, i))[0])
-
 
397
		INTEGER(indx)[i] = 0;
381
	for (i = 0; i < ns; i++) SET_STRING_ELT(indexnames, i, R_NilValue);
398
	for (i = 0; i < ns; i++) SET_STRING_ELT(indexnames, i, R_NilValue);
382
    } else {
399
    } else {
383
#endif
400
#endif
384
	PROTECT(indx = allocVector(INTSXP, ns));
401
	PROTECT(indx = allocVector(INTSXP, ns));
385
	for (i = 0; i < ns; i++) {
402
	for (i = 0; i < ns; i++) {