Skip to content

Commit

Permalink
chore: lf
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Dec 18, 2024
1 parent ac59662 commit 02ca8ab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitatrributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.txt text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
*.cs text eol=lf
65 changes: 32 additions & 33 deletions src/Actions/Utils/Sed.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;

namespace Actions.Utils
namespace Actions.Utils;

public static class Sed
{
public static class Sed
/// <summary>
/// Replace file contents with pattern and replacement.
/// </summary>
/// <param name="path"></param>
/// <param name="pattern"></param>
/// <param name="replacement"></param>
/// <param name="writeBack"></param>
/// <returns></returns>
public static (string before, string after) Replace(string path, string pattern, string replacement, bool writeBack)
{
/// <summary>
/// Replace file contents with pattern and replacement.
/// </summary>
/// <param name="path"></param>
/// <param name="pattern"></param>
/// <param name="replacement"></param>
/// <param name="writeBack"></param>
/// <returns></returns>
public static (string before, string after) Replace(string path, string pattern, string replacement, bool writeBack)
{
var input = File.ReadAllText(path);
var result = Replace(input, pattern, replacement);

if (writeBack)
{
File.WriteAllText(path, result.after);
}

return result;
}
var input = File.ReadAllText(path);
var result = Replace(input, pattern, replacement);

/// <summary>
/// Replace contents with pattern and replacement.
/// </summary>
/// <param name="input"></param>
/// <param name="pattern"></param>
/// <param name="replacement"></param>
/// <returns></returns>
public static (string before, string after) Replace(string input, string pattern, string replacement)
if (writeBack)
{
var updatedContent = Regex.Replace(input, pattern, replacement, RegexOptions.Multiline);
return (input, updatedContent);
File.WriteAllText(path, result.after);
}

return result;
}

/// <summary>
/// Replace contents with pattern and replacement.
/// </summary>
/// <param name="input"></param>
/// <param name="pattern"></param>
/// <param name="replacement"></param>
/// <returns></returns>
public static (string before, string after) Replace(string input, string pattern, string replacement)
{
var updatedContent = Regex.Replace(input, pattern, replacement, RegexOptions.Multiline);
return (input, updatedContent);
}
}

0 comments on commit 02ca8ab

Please sign in to comment.