match á and é

This commit is contained in:
Haven1433 2022-08-31 20:40:56 -05:00
parent 280fae25a6
commit a70cdd38af
2 changed files with 8 additions and 1 deletions

View File

@ -117,15 +117,16 @@ namespace HavenSoft.HexManiac.Core {
/// Returns how many letters within partial can be matched into the full string
/// </summary>
public static int MatchLength(this string full, string partial, bool onlyCheckLettersAndDigits = false) {
full = full.Replace("é", "e");
int j = 0;
for (int i = 0; i < partial.Length; i++) {
if (onlyCheckLettersAndDigits && !char.IsLetterOrDigit(partial[i])) continue;
var testPartial = char.ToUpperInvariant(partial[i]);
if (partial[i] == 'é') testPartial = 'E';
if (partial[i] == 'á') testPartial = 'A';
while (j < full.Length) {
var testFull = char.ToUpperInvariant(full[j]);
if (full[j] == 'é') testFull = 'E';
if (full[j] == 'á') testFull = 'A';
j++;
if (testFull == testPartial) break;
if (j == full.Length) return i;

View File

@ -703,6 +703,12 @@ namespace HavenSoft.HexManiac.Tests {
Assert.Equal(bytes, result);
}
[Fact]
public void SpecialCharacters_MatchAgainstNormalCharacters_Match() {
Assert.True("á.é".MatchesPartialWithReordering("ea"));
Assert.True("a.e".MatchesPartialWithReordering("éá"));
}
private void HackTextConverter(string game) {
var converter = new PCSConverter(game);
var property = Model.GetType().GetProperty(nameof(Model.TextConverter));