Browse Source

Allow user defined `NewLine` sequence

pull/1915/head
duckdoom5 5 months ago
parent
commit
8e170e2e7a
  1. 8
      src/Generator/Generators/CodeGenerator.cs
  2. 4
      src/Generator/Passes/GetterSetterToPropertyPass.cs
  3. 4
      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
var lines = new List<string>(); 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>"); lines.Add("<summary>");
foreach (string line in HtmlEncoder.HtmlEncode(comment.BriefText).Split( foreach (string line in commentLines)
Environment.NewLine.ToCharArray()))
{ {
if (string.IsNullOrWhiteSpace(line)) if (string.IsNullOrWhiteSpace(line))
continue; continue;

4
src/Generator/Passes/GetterSetterToPropertyPass.cs

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

4
src/Generator/Utils/BlockGenerator.cs

@ -135,12 +135,12 @@ namespace CppSharp
if (previousBlock != null && if (previousBlock != null &&
(previousBlock.NewLineKind == NewLineKind.BeforeNextBlock || (previousBlock.NewLineKind == NewLineKind.BeforeNextBlock ||
(previousBlock.NewLineKind == NewLineKind.IfNotEmpty && !previousBlockEmpty))) (previousBlock.NewLineKind == NewLineKind.IfNotEmpty && !previousBlockEmpty)))
builder.AppendLine(); builder.Append(TextGenerator.NewLineChar);
builder.Append(childText); builder.Append(childText);
if (childBlock.NewLineKind == NewLineKind.Always) if (childBlock.NewLineKind == NewLineKind.Always)
builder.AppendLine(); builder.Append(TextGenerator.NewLineChar);
previousBlock = childBlock; previousBlock = childBlock;
previousBlockEmpty = childText.Length == 0; previousBlockEmpty = childText.Length == 0;

12
src/Generator/Utils/TextGenerator.cs

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

Loading…
Cancel
Save