Skip to content

Commit d2b3f33

Browse files
committed
Add GUID correction method
1 parent 6c7831d commit d2b3f33

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

Tests/Images/GUIDs.png

62.2 KB
Loading

Tests/StringMethodTests.cs

+34-1
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,37 @@ public void TestLimitEachLine(string inputString, string expected, int charLimit
411411
{
412412
Assert.Equal(expected, inputString.LimitCharactersPerLine(charLimit, spotInLine));
413413
}
414-
}
414+
415+
private string actualGuids = """
416+
97a56312-d8e8-4ca5-87fa-18e35266d31e
417+
bdc5a5f2-d6ff-403d-a632-f9006387e149
418+
aeef14aa-9aff-4f0d-8ca5-e5df1b399c20
419+
c702f24c-e51b-4ebd-bb45-56df08266e80
420+
a87f9201-a046-425d-b92b-b488667a5d92
421+
bc656414-4f2a-4219-b763-810632a535e2
422+
11c5ecc4-0c0a-4606-a54f-16df976637d1
423+
5cec5cc9-782d-47aa-bff3-c84e13a81604
424+
8501db7b-ee04-4fb2-8516-f5e2f0bc71bf
425+
8da03c16-6d3f-4750-831b-c3866af85551
426+
03d82c33-489c-41b2-8222-cc489d00b1bf
427+
edf3b5ee-658e-41ea-8f7a-494a07beb322
428+
4418874a-30c7-4a16-aba5-0f2a0c49b4f9
429+
d4144186-4fad-40a0-bda9-7e3a2ea58a48
430+
486d81d0-0d56-466b-856c-0bc37e897b7b
431+
935155d5-1a96-4901-8b7d-23854fceb32d
432+
ff826fac-d166-441e-8040-05218989e805
433+
0a4ed755-f236-4e10-8b0b-592a527bb560
434+
9be83ad8-5e2d-4e37-a9f5-9b728cd9b934
435+
926ef504-264d-4762-b781-8813156eaa86
436+
""";
437+
438+
439+
[Theory]
440+
[InlineData("g7a56312-d8e8-4ca5-87fa-18e3S266d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")]
441+
[InlineData("g7a56312-d8e 8-4ca5-87fa-18e3S2 66d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")]
442+
[InlineData("g7a56312-\r\nd8e8\r\n-4ca5-87fa-18e3S266d3le", "97a56312-d8e8-4ca5-87fa-18e35266d31e")]
443+
public void TestGuidCorrections(string input, string expected)
444+
{
445+
Assert.Equal(expected, input.CorrectCommonGuidErrors());
446+
}
447+
}

Text-Grab/Utilities/StringMethods.cs

+19
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public static class StringMethods
5959
{'b', '6'}, {'z', '2'}, {'Z', '2'}
6060
};
6161

62+
public static readonly Dictionary<char, char> GuidCorrections = new()
63+
{
64+
{'o', '0'}, {'O', '0'}, {'i', '1'}, {'l', '1'}, {'I', '1'},
65+
{'h', '4'}, {'z', '2'}, {'Z', '2'}, {'g', '9'}, {'G', '9'},
66+
{'s', '5'}, {'S', '5'}, {'Ø', '0'}, {'#', 'f'}, {'@', '0'},
67+
{'Q', '0'}, {'¥', 'f'}, {'£', 'f'}, {'/', '7'}
68+
};
69+
6270
public static string ReplaceWithDictionary(this string str, Dictionary<char, char> dict)
6371
{
6472
StringBuilder sb = new();
@@ -74,6 +82,17 @@ public static string ReplaceGreekOrCyrillicWithLatin(this string str)
7482
return str.ReplaceWithDictionary(GreekCyrillicLatinMap);
7583
}
7684

85+
public static string CorrectCommonGuidErrors(this string guid)
86+
{
87+
// remove all spaces
88+
guid = guid.Replace(" ", "");
89+
// if a line ends with a dash remove the newline after the dash
90+
guid = guid.Replace("-\r\n", "-");
91+
// if a line begins with a dash remove the newline before the dash
92+
guid = guid.Replace("\r\n-", "-");
93+
return guid.ReplaceWithDictionary(GuidCorrections);
94+
}
95+
7796
public static IEnumerable<int> AllIndexesOf(this string str, string searchString)
7897
{
7998
int minIndex = str.IndexOf(searchString);

Text-Grab/Views/EditTextWindow.xaml

+4
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
x:Name="TryToAlphaMenuItem"
216216
Click="TryToAlphaMenuItem_Click"
217217
Header="Try To Make _Letters" />
218+
<MenuItem
219+
x:Name="CorrectGuid"
220+
Click="CorrectGuid_Click"
221+
Header="Correct Common _GUID/UUID Errors" />
218222
<MenuItem
219223
x:Name="ToggleCaseMenuItem"
220224
Command="{x:Static local:EditTextWindow.ToggleCaseCmd}"

Text-Grab/Views/EditTextWindow.xaml.cs

+12
Original file line numberDiff line numberDiff line change
@@ -2127,5 +2127,17 @@ private void WrapTextCHBOX_Checked(object sender, RoutedEventArgs e)
21272127

21282128
DefaultSettings.EditWindowIsWordWrapOn = WrapTextMenuItem.IsChecked;
21292129
}
2130+
2131+
private void CorrectGuid_Click(object sender, RoutedEventArgs e)
2132+
{
2133+
string workingString = GetSelectedTextOrAllText();
2134+
2135+
workingString = workingString.CorrectCommonGuidErrors();
2136+
2137+
if (PassedTextControl.SelectionLength == 0)
2138+
PassedTextControl.Text = workingString;
2139+
else
2140+
PassedTextControl.SelectedText = workingString;
2141+
}
21302142
#endregion Methods
21312143
}

0 commit comments

Comments
 (0)