mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-30 09:45:32 +00:00
Implemented Fulltext search across tags and linebreaks for letters
This commit is contained in:
39
HaWeb/SearchHelpers/StringHelpers.cs
Normal file
39
HaWeb/SearchHelpers/StringHelpers.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace HaWeb.SearchHelpers;
|
||||
using System.Text;
|
||||
|
||||
public static class StringHelpers {
|
||||
public static string NormalizeWhiteSpace(string input, char normalizeTo = ' ', bool toLower = true) {
|
||||
if (string.IsNullOrEmpty(input)) {
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
// TODO: what about punctuation (char.IsPunctuation()) ? what about spaces?
|
||||
|
||||
// Remove all whitespace, search becomes whitespace insensitive
|
||||
// foreach (var c in input)
|
||||
// if (!char.IsWhiteSpace(c)) {
|
||||
// if (toLower) output.Append(char.ToLower(c));
|
||||
// else output.Append(c);
|
||||
// }
|
||||
|
||||
// Collapse all whitespace into a single whitespace:
|
||||
bool skipped = false;
|
||||
|
||||
foreach (char c in input) {
|
||||
if (char.IsWhiteSpace(c)) {
|
||||
if (!skipped) {
|
||||
output.Append(normalizeTo);
|
||||
skipped = true;
|
||||
}
|
||||
} else {
|
||||
skipped = false;
|
||||
if (toLower) output.Append(char.ToLower(c));
|
||||
else output.Append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return output.ToString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user