Skip to content

Commit a83df54

Browse files
committed
close #647: fixed single-character handling in Rstreambuf
1 parent f99737e commit a83df54

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

inst/include/Rcpp/iostream/Rstreambuf.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Rcpp {
3535
protected:
3636
virtual std::streamsize xsputn(const char *s, std::streamsize n );
3737

38-
virtual int overflow(int c = EOF );
38+
virtual int overflow(int c = traits_type::eof() );
3939

4040
virtual int sync() ;
4141
};
@@ -67,12 +67,22 @@ namespace Rcpp {
6767
}
6868

6969
template <> inline int Rstreambuf<true>::overflow(int c ) {
70-
if (c != EOF) Rprintf( "%.1s", &c ) ;
71-
return c ;
70+
if (c == traits_type::eof())
71+
return traits_type::eof();
72+
else
73+
{
74+
char_type ch = traits_type::to_char_type(c);
75+
return xsputn(&ch, 1) == 1 ? c : traits_type::eof();
76+
}
7277
}
7378
template <> inline int Rstreambuf<false>::overflow(int c ) {
74-
if (c != EOF) REprintf( "%.1s", &c ) ;
75-
return c ;
79+
if (c == traits_type::eof())
80+
return traits_type::eof();
81+
else
82+
{
83+
char_type ch = traits_type::to_char_type(c);
84+
return xsputn(&ch, 1) == 1 ? c : traits_type::eof();
85+
}
7686
}
7787

7888
template <> inline int Rstreambuf<true>::sync(){

0 commit comments

Comments
 (0)