diff --git a/src/Generator/Generators/CodeGenerator.cs b/src/Generator/Generators/CodeGenerator.cs index e8b8a0b3..b3d74a31 100644 --- a/src/Generator/Generators/CodeGenerator.cs +++ b/src/Generator/Generators/CodeGenerator.cs @@ -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; diff --git a/src/Generator/Passes/GetterSetterToPropertyPass.cs b/src/Generator/Passes/GetterSetterToPropertyPass.cs index a5d0be1a..0653ab3a 100644 --- a/src/Generator/Passes/GetterSetterToPropertyPass.cs +++ b/src/Generator/Passes/GetterSetterToPropertyPass.cs @@ -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); } } diff --git a/src/Generator/Utils/BlockGenerator.cs b/src/Generator/Utils/BlockGenerator.cs index 1dff9927..56a2b193 100644 --- a/src/Generator/Utils/BlockGenerator.cs +++ b/src/Generator/Utils/BlockGenerator.cs @@ -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 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; diff --git a/src/Generator/Utils/TextGenerator.cs b/src/Generator/Utils/TextGenerator.cs index a57ae0c6..5b52ac08 100644 --- a/src/Generator/Utils/TextGenerator.cs +++ b/src/Generator/Utils/TextGenerator.cs @@ -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 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 public void NewLine() { - StringBuilder.AppendLine(string.Empty); + StringBuilder.Append(NewLineChar); IsStartOfLine = true; }