The R Project SVN R

Rev

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

Rev 50479 Rev 50880
Line 50... Line 50...
50
    SEXP ans, collapse, sep, x;
50
    SEXP ans, collapse, sep, x;
51
    int i, j, k, maxlen, nx, pwidth, sepw, u_sepw, ienc;
51
    int i, j, k, maxlen, nx, pwidth, sepw, u_sepw, ienc;
52
    const char *s, *csep, *cbuf, *u_csep=NULL;
52
    const char *s, *csep, *cbuf, *u_csep=NULL;
53
    char *buf;
53
    char *buf;
54
    Rboolean allKnown, anyKnown, sepASCII, sepKnown, use_UTF8, sepUTF8;
54
    Rboolean allKnown, anyKnown, sepASCII, sepKnown, use_UTF8, sepUTF8;
-
 
55
    const void *vmax;
55
 
56
 
56
    checkArity(op, args);
57
    checkArity(op, args);
57
 
58
 
58
    /* We use formatting and so we */
59
    /* We use formatting and so we */
59
    /* must initialize printing. */
60
    /* must initialize printing. */
Line 134... Line 135...
134
	    if (k > 0) {
135
	    if (k > 0) {
135
		SEXP cs = STRING_ELT(VECTOR_ELT(x, j), i % k);
136
		SEXP cs = STRING_ELT(VECTOR_ELT(x, j), i % k);
136
		if(IS_UTF8(cs)) use_UTF8 = TRUE;
137
		if(IS_UTF8(cs)) use_UTF8 = TRUE;
137
	    }
138
	    }
138
	}
139
	}
-
 
140
	vmax = vmaxget();
139
	for (j = 0; j < nx; j++) {
141
	for (j = 0; j < nx; j++) {
140
	    k = length(VECTOR_ELT(x, j));
142
	    k = length(VECTOR_ELT(x, j));
141
	    if (k > 0) {
143
	    if (k > 0) {
142
		if(use_UTF8)
144
		if(use_UTF8)
143
		    pwidth += strlen(translateCharUTF8(STRING_ELT(VECTOR_ELT(x, j), i % k)));
145
		    pwidth += strlen(translateCharUTF8(STRING_ELT(VECTOR_ELT(x, j), i % k)));
144
		else
146
		else
145
		    pwidth += strlen(translateChar(STRING_ELT(VECTOR_ELT(x, j), i % k)));
147
		    pwidth += strlen(translateChar(STRING_ELT(VECTOR_ELT(x, j), i % k)));
-
 
148
		vmaxset(vmax);
146
	    }
149
	    }
147
	}
150
	}
148
	if (use_UTF8 && !u_csep) {
151
	if (use_UTF8 && !u_csep) {
149
	    u_csep = translateCharUTF8(sep);
152
	    u_csep = translateCharUTF8(sep);
150
	    u_sepw = strlen(u_csep);
153
	    u_sepw = strlen(u_csep);
151
	}
154
	}
152
	pwidth += (nx - 1) * (use_UTF8 ? u_sepw : sepw);
155
	pwidth += (nx - 1) * (use_UTF8 ? u_sepw : sepw);
153
	cbuf = buf = R_AllocStringBuffer(pwidth, &cbuff);
156
	cbuf = buf = R_AllocStringBuffer(pwidth, &cbuff);
-
 
157
	vmax = vmaxget();
154
	for (j = 0; j < nx; j++) {
158
	for (j = 0; j < nx; j++) {
155
	    k = length(VECTOR_ELT(x, j));
159
	    k = length(VECTOR_ELT(x, j));
156
	    if (k > 0) {
160
	    if (k > 0) {
157
		SEXP cs = STRING_ELT(VECTOR_ELT(x, j), i % k);
161
		SEXP cs = STRING_ELT(VECTOR_ELT(x, j), i % k);
158
		if (use_UTF8) {
162
		if (use_UTF8) {
Line 174... Line 178...
174
		} else {
178
		} else {
175
		    strcpy(buf, csep);
179
		    strcpy(buf, csep);
176
		    buf += sepw;
180
		    buf += sepw;
177
		}
181
		}
178
	    }
182
	    }
-
 
183
	    vmax = vmaxget();
179
	}
184
	}
180
	ienc = 0;
185
	ienc = 0;
181
	if(use_UTF8) ienc = CE_UTF8;
186
	if(use_UTF8) ienc = CE_UTF8;
182
	else if(anyKnown && allKnown) {
187
	else if(anyKnown && allKnown) {
183
	    if(known_to_be_latin1) ienc = CE_LATIN1;
188
	    if(known_to_be_latin1) ienc = CE_LATIN1;
Line 199... Line 204...
199
	    csep = translateChar(sep);
204
	    csep = translateChar(sep);
200
	sepw = strlen(csep);
205
	sepw = strlen(csep);
201
	anyKnown = ENC_KNOWN(sep) > 0;
206
	anyKnown = ENC_KNOWN(sep) > 0;
202
	allKnown = anyKnown || strIsASCII(csep);
207
	allKnown = anyKnown || strIsASCII(csep);
203
	pwidth = 0;
208
	pwidth = 0;
-
 
209
	vmax = vmaxget();
204
	for (i = 0; i < nx; i++)
210
	for (i = 0; i < nx; i++)
205
	    if(use_UTF8)
211
	    if(use_UTF8) {
206
		pwidth += strlen(translateCharUTF8(STRING_ELT(ans, i)));
212
		pwidth += strlen(translateCharUTF8(STRING_ELT(ans, i)));
-
 
213
		vmaxset(vmax);
207
	    else
214
	    } else
208
		pwidth += strlen(CHAR(STRING_ELT(ans, i)));
215
		pwidth += strlen(CHAR(STRING_ELT(ans, i)));
209
	pwidth += (nx - 1) * sepw;
216
	pwidth += (nx - 1) * sepw;
210
	cbuf = buf = R_AllocStringBuffer(pwidth, &cbuff);
217
	cbuf = buf = R_AllocStringBuffer(pwidth, &cbuff);
-
 
218
	vmax = vmaxget();
211
	for (i = 0; i < nx; i++) {
219
	for (i = 0; i < nx; i++) {
212
	    if(i > 0) {
220
	    if(i > 0) {
213
		strcpy(buf, csep);
221
		strcpy(buf, csep);
214
		buf += sepw;
222
		buf += sepw;
215
	    }
223
	    }
Line 219... Line 227...
219
		s = CHAR(STRING_ELT(ans, i));
227
		s = CHAR(STRING_ELT(ans, i));
220
	    strcpy(buf, s);
228
	    strcpy(buf, s);
221
	    while (*buf)
229
	    while (*buf)
222
		buf++;
230
		buf++;
223
	    allKnown = allKnown &&
231
	    allKnown = allKnown &&
224
		(strIsASCII(s) || (ENC_KNOWN(STRING_ELT(ans, i))> 0));
232
		(strIsASCII(s) || (ENC_KNOWN(STRING_ELT(ans, i)) > 0));
225
	    anyKnown = anyKnown || (ENC_KNOWN(STRING_ELT(ans, i))> 0);
233
	    anyKnown = anyKnown || (ENC_KNOWN(STRING_ELT(ans, i)) > 0);
-
 
234
	    if(use_UTF8) vmaxset(vmax);
226
	}
235
	}
227
	UNPROTECT(1);
236
	UNPROTECT(1);
228
	ienc = CE_NATIVE;
237
	ienc = CE_NATIVE;
229
	if(use_UTF8) ienc = CE_UTF8;
238
	if(use_UTF8) ienc = CE_UTF8;
230
	else if(anyKnown && allKnown) {
239
	else if(anyKnown && allKnown) {