Closed edwinyzh closed 1 year ago
Thanks for the valid request.
Getting this right has been a minor pain...
there are 2 functions: nl() and crnl() that can also be used... Part of cleaning up whitespace in general is what led to the <| and |> feature.
I also want to make the use of <| and |> somehow configurable via the context... during dev, you may want it verbose and in release compact, but we don't want to have to change the script in order to do so.
procedure TTestNewLineOption.RemoveEmptyAndStripLines;
var
s: TStringStream;
w: TNewLineStreamWriter;
str: string;
begin
s := TStringStream.Create;
w := TNewLineStreamWriter.Create(s, TEncoding.ASCII, #10, [eoStripEmptyLines, eoTrimLines]);
try
w.Write(#10#10#10#10#10' hello '#10#10#10#10' world '#10#10#10#10);
finally
w.Free;
str := s.datastring;
Assert.AreEqual('hello'#10'world'#10, str);
s.Free;
end;
end;
procedure TTestNewLineOption.RemoveEmptyLines;
var
s: TStringStream;
w: TNewLineStreamWriter;
str: string;
begin
s := TStringStream.Create;
w := TNewLineStreamWriter.Create(s, TEncoding.ASCII, #10, [eoStripEmptyLines]);
try
w.Write(#10#10#10#10#10' hello '#10#10#10#10' world '#10#10#10#10);
finally
w.Free;
str := s.datastring;
Assert.AreEqual(' hello '#10' world '#10, str);
s.Free;
end;
end;
See attached screenshot, it seems that the lines where each script line are located are outputted to the result.
I'm currently using the eoStripRecurringNewlines options and I like it, it removes duplicated lines. and I wonder if there is a way to even eliminate the empty lines.
No,
eoTrimLines
or<% IgnoreNL %>
won't help, because I need new lines for the real content, but just don't want the empty lines. I know there is also the strange<|
and|>
tokens, but I tried it and it doesn't seem to work - it also removes the actual content, not sure why. And even if it works, the code looks too strange and reduces readability, I'd rather post-process it in my delphi code to remove the lines instead...But don't worry, this is only a must-have request, not a critical issue :)