The R Project SVN R

Rev

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

Rev 74921 Rev 76370
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
 *  file console.c
3
 *  file console.c
4
 *  Copyright (C) 1998--2003  Guido Masarotto and Brian Ripley
4
 *  Copyright (C) 1998--2003  Guido Masarotto and Brian Ripley
5
 *  Copyright (C) 2004-8      The R Foundation
5
 *  Copyright (C) 2004-8      The R Foundation
6
 *  Copyright (C) 2004-2018   The R Core Team
6
 *  Copyright (C) 2004-2019   The R Core Team
7
 *
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version.
11
 *  (at your option) any later version.
Line 1687... Line 1687...
1687
static void wcstobuf(char *buf, int len, const wchar_t *in)
1687
static void wcstobuf(char *buf, int len, const wchar_t *in)
1688
{
1688
{
1689
    int used, tot = 0;
1689
    int used, tot = 0;
1690
    char *p = buf, tmp[7];
1690
    char *p = buf, tmp[7];
1691
    const wchar_t *wc = in;
1691
    const wchar_t *wc = in;
-
 
1692
    wchar_t wc_check;
-
 
1693
    mbstate_t mb_st;
1692
 
1694
 
1693
    for(; wc; wc++, p+=used, tot+=used) {
1695
    for(; wc; wc++, p+=used, tot+=used) {
1694
	if(tot >= len - 2) break;
1696
	if(tot >= len - 2) break;
1695
	used = wctomb(p, *wc);
1697
	used = wctomb(p, *wc);
-
 
1698
	if (used >= 0) {
-
 
1699
	    /* conversion was successful, but check that converting back gets
-
 
1700
	       the original result (it does not with best-fit transliteration)
-
 
1701
	       NOTE: WideCharToMultiByte may be faster */
-
 
1702
	    memset(&mb_st, 0, sizeof(mbstate_t));
-
 
1703
	    if (mbrtowc(&wc_check, p, used, &mb_st) < 0 || wc_check != *wc) 
-
 
1704
		used = -1;
-
 
1705
	}
1696
	if (used < 0) {
1706
	if (used < 0) {
1697
	    snprintf(tmp, 7, "\\u%x", *wc);
1707
	    snprintf(tmp, 7, "\\u%x", *wc);
1698
	    used = strlen(tmp);
1708
	    used = strlen(tmp);
1699
	    memcpy(p, tmp, used);
1709
	    memcpy(p, tmp, used);
1700
	}
1710
	}