Skip to content
This repository was archived by the owner on Jun 28, 2026. It is now read-only.
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,17 @@ private static bool DoesEntityMatchSearch(EntityPrototype prototype, string sear
if (string.IsNullOrEmpty(searchStr))
return true;

if (prototype.ID.Contains(searchStr, StringComparison.InvariantCultureIgnoreCase))
if (prototype.ID.ContainsSearch(searchStr))
return true;

if (prototype.EditorSuffix != null &&
prototype.EditorSuffix.Contains(searchStr, StringComparison.InvariantCultureIgnoreCase))
prototype.EditorSuffix.ContainsSearch(searchStr))
return true;

if (string.IsNullOrEmpty(prototype.Name))
return false;

if (prototype.Name.Contains(searchStr, StringComparison.InvariantCultureIgnoreCase))
if (prototype.Name.ContainsSearch(searchStr))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ private void BuildTileList(string? searchStr = null)
if (!string.IsNullOrEmpty(searchStr))
{
tileDefs = tileDefs.Where(s =>
Loc.GetString(s.Name).Contains(searchStr, StringComparison.CurrentCultureIgnoreCase) ||
s.ID.Contains(searchStr, StringComparison.OrdinalIgnoreCase));
Loc.GetString(s.Name).ContainsSearch(searchStr) ||
s.ID.ContainsSearch(searchStr));
}

tileDefs = tileDefs.OrderBy(d => Loc.GetString(d.Name));
Expand Down
41 changes: 41 additions & 0 deletions Robust.Shared/Utility/SearchHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Globalization;

namespace Robust.Shared.Utility;

/// <summary>
/// Helpers for user-facing text search that use Unicode-aware comparison, so that characters
/// differing only by diacritical marks are treated as equivalent.
/// </summary>
/// <remarks>
/// Uses <see cref="CompareOptions.IgnoreNonSpace"/>, <see cref="CompareOptions.IgnoreWidth"/>,
/// and <see cref="CompareOptions.IgnoreKanaType"/> via <see cref="CompareInfo"/>. This means:
/// <list type="bullet">
/// <item>Characters that differ only by diacritical marks are equivalent: Russian ё matches е,
/// German ü matches u, French é/è/ê all match e, Spanish ñ matches n, etc.</item>
/// <item>Full-width and half-width variants of the same character are equivalent (relevant for
/// Japanese and Chinese input).</item>
/// <item>Hiragana and Katakana representations of the same sound are equivalent.</item>
/// </list>
/// Uses the current culture so that locale-specific comparison rules are respected.
/// No configuration or setup is required; any UI code can call <see cref="ContainsSearch"/> directly.
/// </remarks>
public static class SearchHelpers
{
private const CompareOptions SearchOptions =
CompareOptions.IgnoreCase |
CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreWidth |
CompareOptions.IgnoreKanaType;

/// <summary>
/// Returns <see langword="true"/> if <paramref name="source"/> contains
/// <paramref name="search"/>, ignoring case, diacritical marks, character width, and
/// kana type.
/// </summary>
public static bool ContainsSearch(this string source, string search)
{
if (string.IsNullOrEmpty(search)) return true;
if (string.IsNullOrEmpty(source)) return false;
return CultureInfo.CurrentCulture.CompareInfo.IndexOf(source, search, SearchOptions) >= 0;
}
}
Loading