-2

I explore a source code of some programm and stumbled with:

// remove newlines and partial newlines to help fix issues with Windows formatted config files on Linux systems

            Line.erase( remove( Line.begin( ), Line.end( ), '\r' ), Line.end( ) );
            Line.erase( remove( Line.begin( ), Line.end( ), '\n' ), Line.end( ) );

What does it mean?

mzarb
  • 563
  • 1
  • 4
  • 9

2 Answers2

1

The line ending in unix and windows are different. This thing is done to use the suitable line ending in a specific system. You may see here to know what line ending is.

Community
  • 1
  • 1
deeiip
  • 3,319
  • 2
  • 22
  • 33
1

Physically, different systems represent the new line character in a text file differently. This can sometimes cause difficulties when the file was written on one system, and is being read on another. In most cases, a file written as text on one system will not even be readable on another system. The major exceptions are Windows and Unix (and Mac OS, too, I think, even before it was Unix), however; on all of these systems, files are just a sequence of bytes, and each system, by convention, uses a simple sequence of one or two characters to represent a line end (or line separator---the convention isn't clear under Windows). If these are the only systems targetted (and that's true for a lot of programs), then it's possible to read the file, separated into lines, but you may get some extra characters in the lines (most typically, and additional '\r\ at the end of every line when reading under Unix if the file was written under Windows). The code you cite is just trying to remove these characters, in an extremely overly cautious manner.

James Kanze
  • 150,581
  • 18
  • 184
  • 329