-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac59662
commit 02ca8ab
Showing
2 changed files
with
33 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*.txt text eol=lf | ||
*.yml text eol=lf | ||
*.yaml text eol=lf | ||
*.cs text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |