Skip to content

Commit

Permalink
Use enum EndOfLine
Browse files Browse the repository at this point in the history
  • Loading branch information
virzak committed Jan 26, 2024
1 parent 032da0a commit 3e78c18
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/XamlStyler.Console/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public sealed partial class CommandLineOptions
public int? CommentSpaces { get; set; }

[Option("end-of-line", HelpText = "Override: end-of-line.")]
public string EndOfLine { get; set; }
public EndOfLine? EndOfLine { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/XamlStyler.Console/XamlStylerConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private void ApplyOptionOverrides(CommandLineOptions options, IStylerOptions sty

if (options.EndOfLine != null)
{
stylerOptions.EndOfLine = options.EndOfLine;
stylerOptions.EndOfLine = options.EndOfLine.Value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public SignificantWhitespaceDocumentProcessor(IStylerOptions options)
{
this.options = options;
}

public void Process(XmlReader xmlReader, StringBuilder output, ElementProcessContext elementProcessContext)
{
// All newlines are returned by XmlReader as '\n' due to requirements in the XML Specification.
Expand Down
27 changes: 27 additions & 0 deletions src/XamlStyler/Options/EndOfLine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// (c) Xavalon. All rights reserved.

namespace Xavalon.XamlStyler.Options
{
/// <summary>
/// Type of end of line
/// </summary>
public enum EndOfLine
{
/// <summary>
/// Uses <see cref="System.Environment.NewLine"/>.
/// </summary>
Default,
/// <summary>
/// The line feed `\n` character.
/// </summary>
LF,
/// <summary>
/// The carriage return line feed `\r\n` sequence.
/// </summary>
CRLF,
/// <summary>
/// The carriage return `\r` character.
/// </summary>
CR,
}
}
2 changes: 1 addition & 1 deletion src/XamlStyler/Options/IStylerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public interface IStylerOptions

string NewLine { get; }

string EndOfLine { get; set; }
EndOfLine EndOfLine { get; set; }

#endregion Misc

Expand Down
19 changes: 11 additions & 8 deletions src/XamlStyler/Options/StylerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,28 @@ public string ConfigPath
[Browsable(false)]
public bool SuppressProcessing { get; set; }

private string endOfLine;
private EndOfLine endOfLine;

[Category("Misc")]
[Description("Defines end of line character. Specify 'lf' or 'crlf'; otherwise, default character of the host will be used.")]
[JsonProperty("EndOfLine", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[DefaultValue("")]
public string EndOfLine
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
[JsonProperty(nameof(EndOfLine), DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
[DefaultValue(EndOfLine.Default)]
public EndOfLine EndOfLine
{
get { return endOfLine; }
set
{
endOfLine = value;
NewLine = string.Equals("crlf", value, StringComparison.InvariantCultureIgnoreCase) ? "\r\n"
: string.Equals("lf", value, StringComparison.InvariantCultureIgnoreCase) ? "\n"
NewLine = value == EndOfLine.CRLF ? "\r\n"
: value == EndOfLine.LF ? "\n"
: value == EndOfLine.CR ? "\r"
: Environment.NewLine;
}
}

[JsonIgnore]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public string NewLine { get; private set; } = Environment.NewLine;

/// <summary>
Expand Down

0 comments on commit 3e78c18

Please sign in to comment.