Skip to content

Commit

Permalink
Removed UTF8 BOM from output text file.
Browse files Browse the repository at this point in the history
  • Loading branch information
kekyo committed Oct 16, 2024
1 parent 48dca99 commit 3026a10
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions RelaxVersioner.Core/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using GitReader;
Expand All @@ -26,6 +27,8 @@ internal static class Utilities
{
private static readonly char[] directorySeparatorChar_ =
{ Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };

public static readonly Encoding UTF8 = new UTF8Encoding(false);

public static string GetDirectoryPath(string path) =>
Path.GetDirectoryName(path) switch
Expand Down
6 changes: 3 additions & 3 deletions RelaxVersioner.Core/Writers/NpmReplaceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void ReplaceSubKey(string key)
stream =>
{
using var tr = context.ReplaceInputPath is { } rip ?
new StreamReader(rip, Encoding.UTF8, true) :
new StreamReader(rip, Utilities.UTF8, true) :
Console.In;
var tw = new StreamWriter(stream, Encoding.UTF8);
var tw = new StreamWriter(stream, Utilities.UTF8);
Replace(tr, tw);
});
Expand All @@ -108,7 +108,7 @@ void ReplaceSubKey(string key)
}

using var tr = context.ReplaceInputPath is { } rip ?
new StreamReader(rip, Encoding.UTF8, true) :
new StreamReader(rip, Utilities.UTF8, true) :
Console.In;
Replace(tr, Console.Out);
}
Expand Down
6 changes: 3 additions & 3 deletions RelaxVersioner.Core/Writers/TextReplaceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ void Replace(TextReader tr, TextWriter tw)
stream =>
{
using var tr = context.ReplaceInputPath is { } rip ?
new StreamReader(rip, Encoding.UTF8, true) :
new StreamReader(rip, Utilities.UTF8, true) :
Console.In;
var tw = new StreamWriter(stream, Encoding.UTF8);
var tw = new StreamWriter(stream, Utilities.UTF8);
Replace(tr, tw);
});
Expand All @@ -78,7 +78,7 @@ void Replace(TextReader tr, TextWriter tw)
}

using var tr = context.ReplaceInputPath is { } rip ?
new StreamReader(rip, Encoding.UTF8, true) :
new StreamReader(rip, Utilities.UTF8, true) :
Console.In;
Replace(tr, Console.Out);
}
Expand Down
2 changes: 1 addition & 1 deletion RelaxVersioner.Core/Writers/TextWriteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void Write(TextWriter tw, bool emitEol)

Processor.WriteSafeTransacted(
context.OutputPath,
stream => Write(new StreamWriter(stream, Encoding.UTF8), false));
stream => Write(new StreamWriter(stream, Utilities.UTF8), false));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion RelaxVersioner/build/RelaxVersioner.props
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
string path = Path.GetFullPath(File.ItemSpec);
using (Stream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
{
TextWriter tw = new StreamWriter(fs, Encoding.UTF8);
TextWriter tw = new StreamWriter(fs, new UTF8Encoding(false));
string text = Text;
if (text != null)
{
Expand Down

0 comments on commit 3026a10

Please sign in to comment.