diff --git a/ChangeLog b/ChangeLog index 2d6866c94..ecb84382b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-02-14 Iñaki Ucar + + * inst/include/Rcpp/iostream/Rstreambuf.h: Fixed single-character handling + (pull request #649, fixes issue #647) + 2017-02-13 Dirk Eddelbuettel * R/Attributes.R (.plugins[["cpp17"]]): New plugin diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 98b3ca258..9d8519904 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -9,6 +9,8 @@ \itemize{ \item Added new size attribute aliases for number of rows and columns in DataFrame (James Balamuta in \ghpr{638} addressing \ghit{630}). + \item Fixed single-character handling in \code{Rstreambuf} (Iñaki Ucar in + \ghpr{649} addressing \ghit{647}). } \item Changes in Rcpp Sugar: \itemize{ diff --git a/inst/include/Rcpp/iostream/Rstreambuf.h b/inst/include/Rcpp/iostream/Rstreambuf.h index e25491efa..98e54e812 100644 --- a/inst/include/Rcpp/iostream/Rstreambuf.h +++ b/inst/include/Rcpp/iostream/Rstreambuf.h @@ -35,7 +35,7 @@ namespace Rcpp { protected: virtual std::streamsize xsputn(const char *s, std::streamsize n ); - virtual int overflow(int c = EOF ); + virtual int overflow(int c = traits_type::eof() ); virtual int sync() ; }; @@ -67,12 +67,18 @@ namespace Rcpp { } template <> inline int Rstreambuf::overflow(int c ) { - if (c != EOF) Rprintf( "%.1s", &c ) ; - return c ; + if (c != traits_type::eof()) { + char_type ch = traits_type::to_char_type(c); + return xsputn(&ch, 1) == 1 ? c : traits_type::eof(); + } + return c; } template <> inline int Rstreambuf::overflow(int c ) { - if (c != EOF) REprintf( "%.1s", &c ) ; - return c ; + if (c != traits_type::eof()) { + char_type ch = traits_type::to_char_type(c); + return xsputn(&ch, 1) == 1 ? c : traits_type::eof(); + } + return c; } template <> inline int Rstreambuf::sync(){