|
|
|
|
@ -21,9 +21,11 @@ namespace CppSharp
@@ -21,9 +21,11 @@ namespace CppSharp
|
|
|
|
|
|
|
|
|
|
public class TextGenerator : ITextGenerator |
|
|
|
|
{ |
|
|
|
|
public static string NewLineChar; |
|
|
|
|
|
|
|
|
|
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; } |
|
|
|
|
@ -45,6 +47,19 @@ namespace CppSharp
@@ -45,6 +47,19 @@ namespace CppSharp
|
|
|
|
|
return new TextGenerator(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void SetLineEndingType(NewLineType newLineType) |
|
|
|
|
{ |
|
|
|
|
NewLineChar = newLineType switch |
|
|
|
|
{ |
|
|
|
|
NewLineType.Host => Environment.NewLine, |
|
|
|
|
NewLineType.CR => "\r", |
|
|
|
|
NewLineType.LF => "\n", |
|
|
|
|
NewLineType.CRLF => "\r\n", |
|
|
|
|
NewLineType.Auto => throw new ArgumentException("Don't use Auto here.", nameof(newLineType)), |
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(newLineType)) |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Write(string msg, params object[] args) |
|
|
|
|
{ |
|
|
|
|
if (string.IsNullOrEmpty(msg)) |
|
|
|
|
@ -54,11 +69,9 @@ namespace CppSharp
@@ -54,11 +69,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 +103,7 @@ namespace CppSharp
@@ -90,7 +103,7 @@ namespace CppSharp
|
|
|
|
|
|
|
|
|
|
public void NewLine() |
|
|
|
|
{ |
|
|
|
|
StringBuilder.AppendLine(string.Empty); |
|
|
|
|
StringBuilder.Append(NewLineChar); |
|
|
|
|
IsStartOfLine = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|