unit ustreamrwln;

{$mode delphi}

interface

uses
  Classes, SysUtils;

procedure readlnS( f: TStream; out r: string );
procedure writeS( f: TSTream; const r: string );
procedure writelnS( f: TSTream; const r: string='' );

implementation


{ Lee una línea sin importar si es UNIX o DOS }
procedure readlnS( f: TStream; out r: string);
var
  c: char;
  NotEOF: boolean;
begin
  r := '';
  c := 'm';
  NotEOF:= true;
  while (c <> #10) and NotEOF do
  begin
    if f.Read(c, 1) = 1 then
      r := r + c
    else
      NotEOF:= true;
  end;

  if length(r) > 0 then
    if c = #10 then
      Delete(r, length(r), 1);
  if length(r) > 0 then
    if r[length(r)] = #13 then
      Delete(r, length(r), 1);
end;


procedure writeS( f: TSTream; const r: string );
begin
  f.Write( r[1], length( r ) );
end;


procedure writelnS( f: TSTream; const r: string );
begin
  writeS(f, r+#13#10 );
end;

end.

