Browse Source

Allow user defined `NewLine` sequence

pull/1915/head
duckdoom5 4 months ago
parent
commit
8e170e2e7a
  1. 8
      src/Generator/Generators/CodeGenerator.cs
  2. 4
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  3. 6
      src/Generator/Utils/BlockGenerator.cs
  4. 12
      src/Generator/Utils/TextGenerator.cs

8
src/Generator/Generators/CodeGenerator.cs

@ -140,11 +140,13 @@ namespace CppSharp.Generators @@ -140,11 +140,13 @@ namespace CppSharp.Generators
var lines = new List<string>();
if (comment.BriefText.Contains("\n"))
if (comment.BriefText.Contains('\n'))
{
var commentLines = HtmlEncoder.HtmlEncode(comment.BriefText)
.Split('\n', '\r');
lines.Add("<summary>");
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split(
Environment.NewLine.ToCharArray()))
foreach (string line in commentLines)
{
if (string.IsNullOrWhiteSpace(line))
continue;

4
src/Generator/Passes/GetterSetterToPropertyPass.cs

@ -334,8 +334,8 @@ namespace CppSharp.Passes @@ -334,8 +334,8 @@ namespace CppSharp.Passes
Method setter = property.SetMethod;
if (getter != setter && setter?.Comment != null)
{
comment.BriefText += Environment.NewLine + setter.Comment.BriefText;
comment.Text += Environment.NewLine + setter.Comment.Text;
comment.BriefText += TextGenerator.NewLineChar + setter.Comment.BriefText;
comment.Text += TextGenerator.NewLineChar + setter.Comment.Text;
comment.FullComment.Blocks.AddRange(setter.Comment.FullComment.Blocks);
}
}

6
src/Generator/Utils/BlockGenerator.cs

@ -135,12 +135,12 @@ namespace CppSharp @@ -135,12 +135,12 @@ namespace CppSharp
if (previousBlock != null &&
(previousBlock.NewLineKind == NewLineKind.BeforeNextBlock ||
(previousBlock.NewLineKind == NewLineKind.IfNotEmpty && !previousBlockEmpty)))
builder.AppendLine();
builder.Append(TextGenerator.NewLineChar);
builder.Append(childText);
if (childBlock.NewLineKind == NewLineKind.Always)
builder.AppendLine();
builder.Append(TextGenerator.NewLineChar);
previousBlock = childBlock;
previousBlockEmpty = childText.Length == 0;
@ -318,7 +318,7 @@ namespace CppSharp @@ -318,7 +318,7 @@ namespace CppSharp
private readonly BlockGenerator generator;
private readonly NewLineKind next;
public PushedBlock(BlockGenerator generator, NewLineKind next)
public PushedBlock(BlockGenerator generator, NewLineKind next)
{
this.generator = generator;
this.next = next;

12
src/Generator/Utils/TextGenerator.cs

@ -21,9 +21,11 @@ namespace CppSharp @@ -21,9 +21,11 @@ namespace CppSharp
public class TextGenerator : ITextGenerator
{
public static string NewLineChar = "\n";
public const uint DefaultIndentation = 4;
public StringBuilder StringBuilder = new StringBuilder();
public StringBuilder StringBuilder = new();
public bool IsStartOfLine { get; set; }
public bool NeedsNewLine { get; set; }
public uint CurrentIndentation { get; set; }
@ -54,11 +56,9 @@ namespace CppSharp @@ -54,11 +56,9 @@ namespace CppSharp
msg = string.Format(msg, args);
if (IsStartOfLine && !string.IsNullOrWhiteSpace(msg))
StringBuilder.Append(new string(' ',
(int)(CurrentIndentation * DefaultIndentation)));
StringBuilder.Append(new string(' ', (int)(CurrentIndentation * DefaultIndentation)));
if (msg.Length > 0)
IsStartOfLine = msg.EndsWith(Environment.NewLine);
IsStartOfLine = msg.Length > 0 && msg.EndsWith(NewLineChar);
StringBuilder.Append(msg);
}
@ -90,7 +90,7 @@ namespace CppSharp @@ -90,7 +90,7 @@ namespace CppSharp
public void NewLine()
{
StringBuilder.AppendLine(string.Empty);
StringBuilder.Append(NewLineChar);
IsStartOfLine = true;
}

Loading…
Cancel
Save