diff --git a/Tests/Images/GUIDs.png b/Tests/Images/GUIDs.png new file mode 100644 index 00000000..2146bfad Binary files /dev/null and b/Tests/Images/GUIDs.png differ diff --git a/Tests/StringMethodTests.cs b/Tests/StringMethodTests.cs index cc4e2b55..8e21220c 100644 --- a/Tests/StringMethodTests.cs +++ b/Tests/StringMethodTests.cs @@ -411,4 +411,37 @@ public void TestLimitEachLine(string inputString, string expected, int charLimit { Assert.Equal(expected, inputString.LimitCharactersPerLine(charLimit, spotInLine)); } -} \ No newline at end of file + + private string actualGuids = """ + 97a56312-d8e8-4ca5-87fa-18e35266d31e + bdc5a5f2-d6ff-403d-a632-f9006387e149 + aeef14aa-9aff-4f0d-8ca5-e5df1b399c20 + c702f24c-e51b-4ebd-bb45-56df08266e80 + a87f9201-a046-425d-b92b-b488667a5d92 + bc656414-4f2a-4219-b763-810632a535e2 + 11c5ecc4-0c0a-4606-a54f-16df976637d1 + 5cec5cc9-782d-47aa-bff3-c84e13a81604 + 8501db7b-ee04-4fb2-8516-f5e2f0bc71bf + 8da03c16-6d3f-4750-831b-c3866af85551 + 03d82c33-489c-41b2-8222-cc489d00b1bf + edf3b5ee-658e-41ea-8f7a-494a07beb322 + 4418874a-30c7-4a16-aba5-0f2a0c49b4f9 + d4144186-4fad-40a0-bda9-7e3a2ea58a48 + 486d81d0-0d56-466b-856c-0bc37e897b7b + 935155d5-1a96-4901-8b7d-23854fceb32d + ff826fac-d166-441e-8040-05218989e805 + 0a4ed755-f236-4e10-8b0b-592a527bb560 + 9be83ad8-5e2d-4e37-a9f5-9b728cd9b934 + 926ef504-264d-4762-b781-8813156eaa86 + """; + + + [Theory] + [InlineData("g7a56312-d8e8-4ca5-87fa-18e3S266d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")] + [InlineData("g7a56312-d8e 8-4ca5-87fa-18e3S2 66d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")] + [InlineData("g7a56312-\r\nd8e8\r\n-4ca5-87fa-18e3S266d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")] + public void TestGuidCorrections(string input, string expected) + { + Assert.Equal(expected, input.CorrectCommonGuidErrors()); + } +} diff --git a/Text-Grab/Utilities/StringMethods.cs b/Text-Grab/Utilities/StringMethods.cs index 686d111d..79ce69c8 100644 --- a/Text-Grab/Utilities/StringMethods.cs +++ b/Text-Grab/Utilities/StringMethods.cs @@ -59,6 +59,14 @@ public static class StringMethods {'b', '6'}, {'z', '2'}, {'Z', '2'} }; + public static readonly Dictionary GuidCorrections = new() + { + {'o', '0'}, {'O', '0'}, {'i', '1'}, {'l', '1'}, {'I', '1'}, + {'h', '4'}, {'z', '2'}, {'Z', '2'}, {'g', '9'}, {'G', '9'}, + {'s', '5'}, {'S', '5'}, {'Ø', '0'}, {'#', 'f'}, {'@', '0'}, + {'Q', '0'}, {'¥', 'f'}, {'£', 'f'}, {'/', '7'} + }; + public static string ReplaceWithDictionary(this string str, Dictionary dict) { StringBuilder sb = new(); @@ -74,6 +82,17 @@ public static string ReplaceGreekOrCyrillicWithLatin(this string str) return str.ReplaceWithDictionary(GreekCyrillicLatinMap); } + public static string CorrectCommonGuidErrors(this string guid) + { + // remove all spaces + guid = guid.Replace(" ", ""); + // if a line ends with a dash remove the newline after the dash + guid = guid.Replace("-\r\n", "-"); + // if a line begins with a dash remove the newline before the dash + guid = guid.Replace("\r\n-", "-"); + return guid.ReplaceWithDictionary(GuidCorrections); + } + public static IEnumerable AllIndexesOf(this string str, string searchString) { int minIndex = str.IndexOf(searchString); diff --git a/Text-Grab/Views/EditTextWindow.xaml b/Text-Grab/Views/EditTextWindow.xaml index 31482b5a..7414d604 100644 --- a/Text-Grab/Views/EditTextWindow.xaml +++ b/Text-Grab/Views/EditTextWindow.xaml @@ -215,6 +215,10 @@ x:Name="TryToAlphaMenuItem" Click="TryToAlphaMenuItem_Click" Header="Try To Make _Letters" /> +