-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Inconsistent line endings in Service.g.cs - #3694
- Loading branch information
Showing
4 changed files
with
38 additions
and
2 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
18 changes: 18 additions & 0 deletions
18
src/IceRpc.Protobuf.Generators/Internal/StringExtensions.cs
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,12 +1,30 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace IceRpc.Protobuf.Generators.Internal; | ||
|
||
internal static class StringExtensions | ||
{ | ||
private static readonly string _newLine = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "\r\n" : "\n"; | ||
|
||
internal static string WithIndent(this string contents, string indent) => | ||
string.Join("\n", contents.Split('\n').Select(value => $"{indent}{value}")).Trim(); | ||
|
||
internal static string TrimTrailingWhiteSpaces(this string contents) => | ||
string.Join("\n", contents.Split('\n').Select(value => value.TrimEnd())); | ||
|
||
// TODO Once generators can target .NET 8 we can use String.ReplaceLineEndings and remove this implementation. | ||
internal static string ReplaceLineEndings(this string contents) | ||
{ | ||
if (contents.IndexOf("\r\n") != -1) | ||
{ | ||
contents = contents.Replace("\r\n", "\n"); | ||
} | ||
if (_newLine != "\n") | ||
{ | ||
contents = contents.Replace("\n", _newLine); | ||
} | ||
return contents; | ||
} | ||
} |
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
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,12 +1,30 @@ | ||
// Copyright (c) ZeroC, Inc. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
namespace IceRpc.Slice.Generators.Internal; | ||
|
||
internal static class StringExtensions | ||
{ | ||
private static readonly string _newLine = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "\r\n" : "\n"; | ||
|
||
internal static string WithIndent(this string contents, string indent) => | ||
string.Join("\n", contents.Split('\n').Select(value => $"{indent}{value}")).Trim(); | ||
|
||
internal static string TrimTrailingWhiteSpaces(this string contents) => | ||
string.Join("\n", contents.Split('\n').Select(value => value.TrimEnd())); | ||
|
||
// TODO Once generators can target .NET 8 we can use String.ReplaceLineEndings and remove this implementation. | ||
internal static string ReplaceLineEndings(this string contents) | ||
{ | ||
if (contents.IndexOf("\r\n") != -1) | ||
{ | ||
contents = contents.Replace("\r\n", "\n"); | ||
} | ||
if (_newLine != "\n") | ||
{ | ||
contents = contents.Replace("\n", _newLine); | ||
} | ||
return contents; | ||
} | ||
} |