Skip to content

Commit d96fcc0

Browse files
authored
Merge pull request #649 from Enchufa2/master
close #647: fixed single-character handling in Rstreambuf
2 parents f99737e + a82ce37 commit d96fcc0

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2017-02-14 Iñaki Ucar <[email protected]>
2+
3+
* inst/include/Rcpp/iostream/Rstreambuf.h: Fixed single-character handling
4+
(pull request #649, fixes issue #647)
5+
16
2017-02-13 Dirk Eddelbuettel <[email protected]>
27

38
* R/Attributes.R (.plugins[["cpp17"]]): New plugin

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
\itemize{
1010
\item Added new size attribute aliases for number of rows and columns in
1111
DataFrame (James Balamuta in \ghpr{638} addressing \ghit{630}).
12+
\item Fixed single-character handling in \code{Rstreambuf} (Iñaki Ucar in
13+
\ghpr{649} addressing \ghit{647}).
1214
}
1315
\item Changes in Rcpp Sugar:
1416
\itemize{

inst/include/Rcpp/iostream/Rstreambuf.h

Lines changed: 11 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,18 @@ 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+
char_type ch = traits_type::to_char_type(c);
72+
return xsputn(&ch, 1) == 1 ? c : traits_type::eof();
73+
}
74+
return c;
7275
}
7376
template <> inline int Rstreambuf<false>::overflow(int c ) {
74-
if (c != EOF) REprintf( "%.1s", &c ) ;
75-
return c ;
77+
if (c != traits_type::eof()) {
78+
char_type ch = traits_type::to_char_type(c);
79+
return xsputn(&ch, 1) == 1 ? c : traits_type::eof();
80+
}
81+
return c;
7682
}
7783

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

0 commit comments

Comments
 (0)