From 033560f898a3735ec696594720ddd9252de5e7c1 Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen Date: Wed, 27 Apr 2022 18:55:37 +0300 Subject: [PATCH] Mappings: stricter access, move to static members --- src/Mappings/ElderFutharkMapping.cs | 20 ++++++++++++-------- src/Mappings/FuthorcMapping.cs | 20 ++++++++++++-------- src/Mappings/MedievalFuthorkMapping.cs | 19 +++++++++++-------- src/Mappings/YoungerFutharkMapping.cs | 19 +++++++++++-------- src/Transform.cs | 10 +++++++--- tests/YoungerFutharkTest.cs | 4 ++-- 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/src/Mappings/ElderFutharkMapping.cs b/src/Mappings/ElderFutharkMapping.cs index 4619e49..0a643a3 100644 --- a/src/Mappings/ElderFutharkMapping.cs +++ b/src/Mappings/ElderFutharkMapping.cs @@ -3,11 +3,10 @@ namespace Riimut.Mappings { - public class ElderFutharkMapping + internal class ElderFutharkMapping { - public static Dictionary GetLettersToRunesDictionary() - { - return new Dictionary() + + private readonly static Dictionary LettersToRunesMapping = new Dictionary() { {"a", "ᚨ"}, {"á", "ᚨ"}, @@ -52,11 +51,8 @@ public static Dictionary GetLettersToRunesDictionary() {"þ", "ᚦ"}, {" ", ":"}, }; - } - public static Dictionary GetRunesToLettersDictionary() - { - return new Dictionary() + private readonly static Dictionary RunesToLettersMapping = new Dictionary() { {"ᚠ", "f"}, {"ᚢ", "u"}, @@ -87,6 +83,14 @@ public static Dictionary GetRunesToLettersDictionary() {"ᛞ", "d"}, {":", " "}, }; + public static Dictionary GetLettersToRunesDictionary() + { + return LettersToRunesMapping; + } + + public static Dictionary GetRunesToLettersDictionary() + { + return RunesToLettersMapping; } } } diff --git a/src/Mappings/FuthorcMapping.cs b/src/Mappings/FuthorcMapping.cs index 9f04df9..bcf9a79 100644 --- a/src/Mappings/FuthorcMapping.cs +++ b/src/Mappings/FuthorcMapping.cs @@ -3,11 +3,9 @@ namespace Riimut.Mappings { - public class FuthorcMapping + internal class FuthorcMapping { - public static Dictionary GetLettersToRunesDictionary() - { - return new Dictionary() + private readonly static Dictionary LettersToRunesMapping = new Dictionary() { {"a", "ᚪ"}, {"á", "ᚪ"}, @@ -55,11 +53,8 @@ public static Dictionary GetLettersToRunesDictionary() {"þ", "ᚦ"}, {" ", ":"}, }; - } - public static Dictionary GetRunesToLettersDictionary() - { - return new Dictionary() + private readonly static Dictionary RunesToLettersMapping = new Dictionary() { {"ᚠ", "f"}, {"ᚢ", "u"}, @@ -93,6 +88,15 @@ public static Dictionary GetRunesToLettersDictionary() {":", " "}, {"ᛠ", "ea"}, }; + + public static Dictionary GetLettersToRunesDictionary() + { + return LettersToRunesMapping; + } + + public static Dictionary GetRunesToLettersDictionary() + { + return RunesToLettersMapping; } } } diff --git a/src/Mappings/MedievalFuthorkMapping.cs b/src/Mappings/MedievalFuthorkMapping.cs index 17fabc4..68af35f 100644 --- a/src/Mappings/MedievalFuthorkMapping.cs +++ b/src/Mappings/MedievalFuthorkMapping.cs @@ -3,11 +3,9 @@ namespace Riimut.Mappings { - public class MedievalFuthorkMapping + internal class MedievalFuthorkMapping { - public static Dictionary GetLettersToRunesDictionary() - { - return new Dictionary() + private readonly static Dictionary LettersToRunesMapping = new Dictionary() { {"a", "ᛆ"}, {"á", "ᛆ"}, @@ -53,11 +51,8 @@ public static Dictionary GetLettersToRunesDictionary() {"þ", "ᚦ"}, {" ", ":"}, }; - } - public static Dictionary GetRunesToLettersDictionary() - { - return new Dictionary() + private readonly static Dictionary RunesToLettersMapping = new Dictionary() { {"ᚠ", "f"}, {"ᚢ", "u"}, @@ -87,6 +82,14 @@ public static Dictionary GetRunesToLettersDictionary() {"ᚽ", "e"}, {"ᚵ", "g"}, }; + public static Dictionary GetLettersToRunesDictionary() + { + return LettersToRunesMapping; + } + + public static Dictionary GetRunesToLettersDictionary() + { + return RunesToLettersMapping; } } } diff --git a/src/Mappings/YoungerFutharkMapping.cs b/src/Mappings/YoungerFutharkMapping.cs index abfd7d2..476c5b0 100644 --- a/src/Mappings/YoungerFutharkMapping.cs +++ b/src/Mappings/YoungerFutharkMapping.cs @@ -3,11 +3,9 @@ namespace Riimut.Mappings { - public class YoungerFutharkMapping + internal class YoungerFutharkMapping { - public static Dictionary GetLettersToRunesDictionary() - { - return new Dictionary() + private readonly static Dictionary LettersToRunesMapping = new Dictionary() { {"a", "ᛅ"}, {"á", "ᛅ"}, @@ -51,11 +49,8 @@ public static Dictionary GetLettersToRunesDictionary() {"ǫ", "ᚢ"}, {" ", ":"}, }; - } - public static Dictionary GetRunesToLettersDictionary() - { - return new Dictionary() + private readonly static Dictionary RunesToLettersMapping = new Dictionary() { {"ᚠ", "f"}, {"ᚢ", "u"}, @@ -80,6 +75,14 @@ public static Dictionary GetRunesToLettersDictionary() {"ᛦ", "R"}, {":", " "}, }; + public static Dictionary GetLettersToRunesDictionary() + { + return LettersToRunesMapping; + } + + public static Dictionary GetRunesToLettersDictionary() + { + return RunesToLettersMapping; } } } diff --git a/src/Transform.cs b/src/Transform.cs index ba88556..0d2eafa 100644 --- a/src/Transform.cs +++ b/src/Transform.cs @@ -12,11 +12,15 @@ public static string WithDictionary(string content, Dictionary d { StringBuilder result = new StringBuilder(); - foreach (char letter in content) { + foreach (char letter in content) + { string part = Char.ToLower(letter).ToString(); - if (dictionary.ContainsKey(part)) { + if (dictionary.ContainsKey(part)) + { result.Append(dictionary[part]); - } else { + } + else + { result.Append(part); } } diff --git a/tests/YoungerFutharkTest.cs b/tests/YoungerFutharkTest.cs index 6e12170..1c0212d 100644 --- a/tests/YoungerFutharkTest.cs +++ b/tests/YoungerFutharkTest.cs @@ -33,7 +33,7 @@ public void Transforms_Text_Content_To_Younger_Futhark() public void Transforms_Runes_To_Letters() { string runes = "ᚠᚢᚦᚬᚱᚴᚼᚽᚾᚿᛁᛅᛆᛋᛌᛏᛐᛒᛘᛚᛦ:"; - string letters ="fuþorkhhnniaassttbmlR "; + string letters = "fuþorkhhnniaassttbmlR "; string result = YoungerFuthark.RunesToLetters(runes); @@ -45,7 +45,7 @@ public void Transforms_Rune_Content_To_Latin_Letters() { // From Old Groms runestone. string runes = "ᛅᚢᚴ:ᛏᛅᚾᛁ:ᚴᛅᚱᚦᛁ:ᚴᚱᛁᛋᛏᚾᛅ"; - string letters ="auk tani karþi kristna"; + string letters = "auk tani karþi kristna"; string result = YoungerFuthark.RunesToLetters(runes);