Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add string trimming extensions and usage #179

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/modules/Elsa.Studio.UIHints/Components/MultiLine.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using Elsa.Studio.Models
@using Elsa.Api.Client.Resources.Scripting.Models
@using Elsa.Studio.UIHints.Extensions

@{
var inputDescriptor = EditorContext.InputDescriptor;
Expand Down Expand Up @@ -29,7 +30,7 @@

private async Task OnValueChanged(string newValue)
{
var expression = Expression.CreateLiteral(newValue);
var expression = Expression.CreateLiteral(newValue.TrimNull());

await EditorContext.UpdateExpressionAsync(expression);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

private async Task OnValueChanged(string newValue)
{
var expression = Expression.CreateLiteral(newValue);
var expression = Expression.CreateLiteral(newValue.TrimWhitespace());

await EditorContext.UpdateExpressionAsync(expression);
}
Expand Down
23 changes: 23 additions & 0 deletions src/modules/Elsa.Studio.UIHints/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Elsa.Studio.UIHints.Extensions;

/// <summary>
/// Provides a set of extension methods for <see cref="string"/>.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Trims the whitespace from the string, including null characters and new lines.
/// </summary>
public static string TrimWhitespace(this string value)
{
return value.Trim(' ', '\0', '\n', '\r');
}

/// <summary>
/// Trims the null characters from the string.
/// </summary>
public static string TrimNull(this string value)
{
return value.Trim('\0');
}
}
Loading