-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
8776fff
commit 621e07c
Showing
2 changed files
with
16 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
14 changes: 14 additions & 0 deletions
14
src/OrchardCore/OrchardCore.DisplayManagement.Abstractions/Utilities/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,14 +1,28 @@ | ||
using System.Buffers; | ||
|
||
namespace OrchardCore.DisplayManagement.Utilities; | ||
|
||
public static class StringExtensions | ||
{ | ||
private static readonly SearchValues<char> AlternateChars = SearchValues.Create("-."); | ||
|
||
/// <summary> | ||
/// Encodes dashed and dots so that they don't conflict in filenames. | ||
/// </summary> | ||
/// <param name="alternateElement"></param> | ||
/// <returns></returns> | ||
public static string EncodeAlternateElement(this string alternateElement) | ||
{ | ||
if (string.IsNullOrEmpty(alternateElement)) | ||
{ | ||
return ""; | ||
} | ||
|
||
if (!alternateElement.AsSpan().ContainsAny(AlternateChars)) | ||
{ | ||
return alternateElement; | ||
} | ||
|
||
return alternateElement.Replace("-", "__").Replace('.', '_'); | ||
} | ||
} |