Fixed CR to CRLF conversion. Thanks for the patch, Alessandro.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4530 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
5856b3b9be
commit
ac65443882
@ -380,12 +380,13 @@ class Lf2CrlfConvert {
|
|||||||
char *out;
|
char *out;
|
||||||
int outlen;
|
int outlen;
|
||||||
public:
|
public:
|
||||||
Lf2CrlfConvert(const char *in) {
|
Lf2CrlfConvert(const char *in, int inlen) {
|
||||||
outlen = 0;
|
outlen = 0;
|
||||||
const char *i;
|
const char *i;
|
||||||
char *o;
|
char *o;
|
||||||
|
int lencount;
|
||||||
// Predict size of \r\n conversion buffer
|
// Predict size of \r\n conversion buffer
|
||||||
for ( i=in; *i; ) {
|
for ( i=in, lencount = inlen; lencount--; ) {
|
||||||
if ( *i == '\r' && *(i+1) == '\n' ) // leave \r\n untranslated
|
if ( *i == '\r' && *(i+1) == '\n' ) // leave \r\n untranslated
|
||||||
{ i+=2; outlen+=2; }
|
{ i+=2; outlen+=2; }
|
||||||
else if ( *i == '\n' ) // \n by itself? leave room to insert \r
|
else if ( *i == '\n' ) // \n by itself? leave room to insert \r
|
||||||
@ -396,7 +397,7 @@ public:
|
|||||||
// Alloc conversion buffer + NULL
|
// Alloc conversion buffer + NULL
|
||||||
out = new char[outlen+1];
|
out = new char[outlen+1];
|
||||||
// Handle \n -> \r\n conversion
|
// Handle \n -> \r\n conversion
|
||||||
for ( i=in, o=out; *i; ) {
|
for ( i=in, o=out, lencount = inlen; lencount--; ) {
|
||||||
if ( *i == '\r' && *(i+1) == '\n' ) // leave \r\n untranslated
|
if ( *i == '\r' && *(i+1) == '\n' ) // leave \r\n untranslated
|
||||||
{ *o++ = *i++; *o++ = *i++; }
|
{ *o++ = *i++; *o++ = *i++; }
|
||||||
else if ( *i == '\n' ) // \n by itself? insert \r
|
else if ( *i == '\n' ) // \n by itself? insert \r
|
||||||
@ -418,7 +419,7 @@ void Fl::copy(const char *stuff, int len, int clipboard) {
|
|||||||
if (!stuff || len<0) return;
|
if (!stuff || len<0) return;
|
||||||
|
|
||||||
// Convert \n -> \r\n (for old apps like Notepad, DOS)
|
// Convert \n -> \r\n (for old apps like Notepad, DOS)
|
||||||
Lf2CrlfConvert buf(stuff);
|
Lf2CrlfConvert buf(stuff, len);
|
||||||
len = buf.GetLength();
|
len = buf.GetLength();
|
||||||
stuff = buf.GetValue();
|
stuff = buf.GetValue();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user