Beispiel #1
0
        static string decode(string inputString)
        {
            Console.WriteLine(inputString);
            List <char> result = new List <char>();

            MatchCollection matches = regExRule.Matches(inputString);

            foreach (Match match in matches)
            {
                string morseSymbol = match.Groups[1].Value;
                char   decodedSymbol;
                if (!MorseCodeDictionary.TryGetValue(morseSymbol, out decodedSymbol))
                {
                    decodedSymbol = '*';
                }
                result.Add(decodedSymbol);

                string separator = match.Groups[2].Value;
                if (separator == "   ")
                {
                    result.Add(' ');
                }
            }
            return(new string(result.ToArray()));
        }
Beispiel #2
0
 private static bool ValidateTextMsg(string textMessage, bool throwException = true)
 {
     foreach (var ch in textMessage.ToLower())
     {
         if (MorseCodeDictionary.ContainsKey(ch))
         {
             continue;
         }
         else
         {
             string errorMsg = $"Char {ch} is not allowed in input string!";
             if (throwException)
             {
                 throw new ArgumentOutOfRangeException(errorMsg);
             }
             return(false);
         }
     }
     return(true);
 }
Beispiel #3
0
 private static Dictionary <string, char> CreateInvertedDictionary()
 {
     return(MorseCodeDictionary.ToDictionary(x => x.Value, y => y.Key));
 }