-
Notifications
You must be signed in to change notification settings - Fork 0
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
fcbd03f
commit a7bb964
Showing
10 changed files
with
104 additions
and
23 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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Connect.Razor.Internals; | ||
|
||
namespace Connect.Razor.Blade | ||
{ | ||
public static partial class Text | ||
{ | ||
/// <summary> | ||
/// Cut off a text at the best possible place with a max-length. | ||
/// This will count html-entities like & or umlauts as 1 character, | ||
/// and will try to cut off between words if possible. | ||
/// </summary> | ||
/// <param name="value">String to cut off. Can contain umlauts and html-entities, but should not contain html-tags as there are not treated properly.</param> | ||
/// <param name="length">length to cut off at</param> | ||
/// <returns></returns> | ||
public static string Crop(string value, int length) | ||
{ | ||
return Truncator.SafeTruncate(value, length); | ||
} | ||
|
||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.Text.RegularExpressions; | ||
using Connect.Razor.Internals; | ||
|
||
namespace Connect.Razor.Blade | ||
{ | ||
public static partial class Text | ||
{ | ||
/// <summary> | ||
/// Will remove all new-lines from a string and merge multiple spaces together | ||
/// </summary> | ||
/// <param name="value"></param> | ||
/// <returns></returns> | ||
public static string Zip(string value) | ||
{ | ||
return string.IsNullOrEmpty(value) | ||
? value | ||
: ShrinkSpaces(Nl2X(value, " ")); | ||
} | ||
|
||
internal static string ShrinkSpaces(string value) | ||
{ | ||
return Regex.Replace(value, @"\s{2,}", " "); | ||
} | ||
|
||
internal static readonly Regex NewLine = new Regex(@"[\r\n]"); | ||
|
||
internal static string Nl2X(string value, string replacement) | ||
{ | ||
return NewLine.Replace(value, replacement); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Connect.Razor.Internals; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Connect.Razor.Blade; | ||
|
||
|
||
namespace Razor_Blades_Tests | ||
{ | ||
[TestClass] | ||
public class Test_Blades_Zip | ||
{ | ||
|
||
[TestMethod] | ||
public void Test_Zip_Basic() | ||
{ | ||
var message = "This is a teaser for something"; | ||
var expected = "This is a teaser for something"; | ||
Assert.AreEqual(expected, Text.Zip(message), "multiple spaces must go"); | ||
} | ||
|
||
[TestMethod] | ||
public void Test_Zip_NewLine() | ||
{ | ||
var message = "This is a \n teaser\n for something"; | ||
var expected = "This is a teaser for something"; | ||
Assert.AreEqual(expected, Text.Zip(message), "multiple spaces must go"); | ||
} | ||
|
||
} | ||
} |
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