static T9Mappings() { //map backward //this mapping should occur just once, so in static ctor foreach (var keyValuePair in _digitToChar) { for (int i = 0; i < keyValuePair.Value.Length; i++) { var key = keyValuePair.Value[i]; var keypress = new Keypress(keyValuePair.Key, i + 1, key); CharToDigits.Add(key, keypress); } } }
private Keypress ParseCharToKeypress(char input, ConversionSettings cs = ConversionSettings.Default) { //ConversionSettings cs = ConversionSettings.Default; if (T9Mappings.CharToDigits.TryGetValue(input, out var keypress)) { return(keypress); } else { if (cs.HasFlag(ConversionSettings.FailOnUnconvertable)) { var message = $"Cannot convert character {input} to T9"; Log.Warn(message); throw new T9ConversionException(message); } else { Log.Warn($"Unsuccesful attempt to convert {input} into T9 sequence"); } keypress = new Keypress(-1, -1, input); return(keypress); } }