Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gubskiy committed Aug 22, 2024
1 parent 245d36c commit 233c1d4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/X.Extensions.Text/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public static string CleanCharacters(this string text)
/// Replace multiple strings in text with single string
/// </summary>
/// <param name="text"></param>
/// <param name="forReplace"></param>
/// <param name="whichReplace"></param>
/// <param name="targets"></param>
/// <param name="replacement"></param>
/// <returns></returns>
public static string Replace(this string text, IEnumerable<string> forReplace, string whichReplace)
public static string Replace(this string text, IEnumerable<string> targets, string replacement)
{
return TextHelper.Replace(text, forReplace, whichReplace);
return TextHelper.Replace(text, targets, replacement);
}

/// <summary>
Expand Down
30 changes: 17 additions & 13 deletions src/X.Extensions.Text/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class TextHelper
/// <summary>
///
/// </summary>
public static IReadOnlyCollection<string> SystemCharacters = new[]
public static readonly IReadOnlyCollection<string> SystemCharacters = new[]
{
"&", "?", "^", ":", "/", "\\", "@", "$", "(", ")", "+", "[",
"]", "{", "}", "%", "~", ">", "<", "=", "*", "“", "\"", "!",
Expand Down Expand Up @@ -44,9 +44,9 @@ public static string Substring(string text, int length)
/// <returns></returns>
public static string Substring(string text, int length, string endPart)
{
if (String.IsNullOrEmpty(text))
if (string.IsNullOrEmpty(text))
{
return String.Empty;
return string.Empty;
}

if (text.Length > length)
Expand All @@ -68,7 +68,7 @@ public static string CleanCharacters(string text)

var result = Replace(text, SystemCharacters, space);

var doubleSpace = String.Format("{0}{0}", space);
var doubleSpace = string.Format("{0}{0}", space);

while (result.Contains(doubleSpace))
{
Expand All @@ -81,15 +81,15 @@ public static string CleanCharacters(string text)
}

/// <summary>
///
/// Replaces all occurrences of the specified target strings in the input text with the provided replacement string.
/// </summary>
/// <param name="text"></param>
/// <param name="forReplace"></param>
/// <param name="whichReplace"></param>
/// <returns></returns>
public static string Replace(string text, IEnumerable<string> forReplace, string whichReplace)
/// <param name="text">The input string in which replacements will be made.</param>
/// <param name="targets">An enumerable collection of strings to be replaced.</param>
/// <param name="replacement">The string that will replace each target string.</param>
/// <returns>The modified string with all specified targets replaced by the replacement string.</returns>
public static string Replace(string text, IEnumerable<string> targets, string replacement)
{
return forReplace.Aggregate(text, (current, x) => current.Replace(x, whichReplace));
return targets.Aggregate(text, (current, x) => current.Replace(x, replacement));
}

/// <summary>
Expand Down Expand Up @@ -134,6 +134,12 @@ public static string ToPlainText(string text, bool preserveLineBreaks)
return text.Replace(lineBreakPlaceholder, "<br />");
}

/// <summary>
///
/// </summary>
/// <param name="text"></param>
/// <param name="lineBreakPlaceholder"></param>
/// <returns></returns>
public static string TrimLineBreaksFromStart(string text, string lineBreakPlaceholder = "[[LINE_BREAK]]")
{
if (string.IsNullOrEmpty(text))
Expand All @@ -149,8 +155,6 @@ public static string TrimLineBreaksFromStart(string text, string lineBreakPlaceh
return text;
}



/// <summary>
/// Try to convert HTML to plain text
/// </summary>
Expand Down

0 comments on commit 233c1d4

Please sign in to comment.