The R Project SVN R

Rev

Rev 87891 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 87891 Rev 89894
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 2001--2025 The R Core Team
3
 *  Copyright (C) 2001--2026 The R Core Team
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Pulic License as published by
6
 *  it under the terms of the GNU General Pulic License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 392... Line 392...
392
	R_xlen_t i, nc = XLENGTH(x);
392
	R_xlen_t i, nc = XLENGTH(x);
393
	PROTECT(ans = allocVector(STRSXP, nc));
393
	PROTECT(ans = allocVector(STRSXP, nc));
394
	for (i = 0; i < nc; i++) {
394
	for (i = 0; i < nc; i++) {
395
	    int this = INTEGER(x)[i];
395
	    int this = INTEGER(x)[i];
396
	    if (this == NA_INTEGER
396
	    if (this == NA_INTEGER
-
 
397
		|| this < 0
397
		|| (this >= 0xD800 && this <= 0xDFFF)
398
		|| (0xD800 <= this && this <= 0xDFFF)
398
		|| this > 0x10FFFF)
399
		|| this > 0x10FFFF)
399
		SET_STRING_ELT(ans, i, NA_STRING);
400
		SET_STRING_ELT(ans, i, NA_STRING);
400
	    else {
401
	    else {
401
		used = inttomb(buf, this);
402
		used = inttomb(buf, this);
402
		buf[used] = '\0';
403
		buf[used] = '\0';
Line 409... Line 410...
409
	bool haveNA = false;
410
	bool haveNA = false;
410
	/* Note that this gives zero length for input '0', so it is omitted */
411
	/* Note that this gives zero length for input '0', so it is omitted */
411
	for (i = 0, len = 0; i < nc; i++) {
412
	for (i = 0, len = 0; i < nc; i++) {
412
	    int this = INTEGER(x)[i];
413
	    int this = INTEGER(x)[i];
413
	    if (this == NA_INTEGER
414
	    if (this == NA_INTEGER
-
 
415
		|| this < 0
414
		|| (this >= 0xDC00 && this <= 0xDFFF)
416
		|| (0xDC00 <= this && this <= 0xDFFF)
415
		|| this > 0x10FFFF) {
417
		|| this > 0x10FFFF) {
416
		haveNA = true;
418
		haveNA = true;
417
		break;
419
		break;
418
	    }
420
	    }
419
	    else if (this >=  0xD800 && this <= 0xDBFF) {
421
	    else if (this >= 0xD800 && this <= 0xDBFF) {
420
		if(!s_pair || i >= nc-1) {haveNA = true; break;}
422
		if(!s_pair || i >= nc-1) {haveNA = true; break;}
421
		int next = INTEGER(x)[i+1];
423
		int next = INTEGER(x)[i+1];
422
		if(next >= 0xDC00 && next <= 0xDFFF) i++;
424
		if(0xDC00 <= next && next <= 0xDFFF) i++;
423
		else {haveNA = true; break;}
425
		else {haveNA = true; break;}
424
		len += 4; // all points not in the basic plane have length 4
426
		len += 4; // all points not in the basic plane have length 4
425
	    }
427
	    }
426
	    else
428
	    else
427
		len += inttomb(NULL, this);
429
		len += inttomb(NULL, this);
Line 438... Line 440...
438
	    R_CheckStack2(len+1);
440
	    R_CheckStack2(len+1);
439
	    tmp = alloca(len+1); tmp[len] = '\0';
441
	    tmp = alloca(len+1); tmp[len] = '\0';
440
	}
442
	}
441
	for (i = 0, len = 0; i < nc; i++) {
443
	for (i = 0, len = 0; i < nc; i++) {
442
	    int this = INTEGER(x)[i];
444
	    int this = INTEGER(x)[i];
443
	    if(s_pair && (this >=  0xD800 && this <= 0xDBFF)) {
445
	    if(s_pair && (this >= 0xD800 && this <= 0xDBFF)) {
444
		// all the validity checking has already been done.
446
		// all the validity checking has already been done.
445
		int next = INTEGER(x)[++i];
447
		int next = INTEGER(x)[++i];
446
		unsigned int hi = this - 0xD800, lo = next - 0xDC00;
448
		unsigned int hi = this - 0xD800, lo = next - 0xDC00;
447
		this = 0x10000 + (hi << 10) + lo;
449
		this = 0x10000 + (hi << 10) + lo;
448
	    }
450
	    }