Skip to content

Commit e603c55

Browse files
author
Cédric Belin
committed
Code optimization [skip ci]
1 parent c2cdbe7 commit e603c55

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

build.cake

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Text.RegularExpressions;
23
using static System.IO.File;
34

@@ -31,10 +32,7 @@ Task("test")
3132

3233
Task("version")
3334
.Description("Updates the version number in the sources.")
34-
.DoesForEach(GetFiles("*/*.csproj"), file => {
35-
var pattern = new Regex(@"<Version>\d+(\.\d+){2}</Version>");
36-
WriteAllText(file.FullPath, pattern.Replace(ReadAllText(file.FullPath), $"<Version>{version}</Version>"));
37-
});
35+
.DoesForEach(GetFiles("*/*.csproj"), file => ReplaceInFile(file, @"<Version>\d+(\.\d+){2}</Version>", $"<Version>{version}</Version>"));
3836

3937
Task("default")
4038
.Description("The default task.")
@@ -43,3 +41,14 @@ Task("default")
4341
.IsDependentOn("build");
4442

4543
RunTarget(target);
44+
45+
/// <summary>
46+
/// Replaces the specified pattern in a given file.
47+
/// </summary>
48+
/// <param name="file">The path of the file to be processed.</param>
49+
/// <param name="pattern">The regular expression to find.</param>
50+
/// <param name="replacement">The replacement text.</param>
51+
/// <param name="options">The regular expression options to use.</param>
52+
void ReplaceInFile(FilePath file, [StringSyntax(StringSyntaxAttribute.Regex)] string pattern, string replacement, RegexOptions options = RegexOptions.None) {
53+
WriteAllText(file.FullPath, Regex.Replace(ReadAllText(file.FullPath), pattern, replacement, options));
54+
}

src/report.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Report Parse(string coverage) {
3131
var report = new Report(string.Empty);
3232
var sourceFile = new SourceFile(path: string.Empty);
3333

34-
foreach (var line in new Regex(@"\r?\n").Split(coverage)) {
34+
foreach (var line in Regex.Split(coverage, @"\r?\n")) {
3535
offset++;
3636
if (string.IsNullOrWhiteSpace(line)) continue;
3737

0 commit comments

Comments
 (0)