This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
morse-converter-web/app/scripts/CodeRecognization.dart

61 lines
1.2 KiB
Dart
Raw Normal View History

/**
* 2016 (c) Marcel Kapfer (mmk2410)
* Licensed under MIT License
*/
import 'Convert.dart';
/**
* Detect code.
*/
class CodeRecognization {
/**
* Detect if message is Morse code.
*
* @param message string to be checked.
* @return Boolean true if message is Morse code.
*/
static bool isMorseCode(String message) {
List<String> alphabet = new List.from(Convert.alphabet);
alphabet = alphabet
..remove('.')
..remove('-')
..remove(' ');
for (String char in message.toUpperCase().split('')) {
if (alphabet.contains(char)) {
return false;
}
}
return true;
}
/**
* Detect if message is writtenMorse code.
*
* @param message string to be checked.
* @return Boolean true if message is writtenMorse coe.
*/
static bool isWrittenMorseCode(String message) {
List<String> alphabet = new List.from(Convert.alphabet);
alphabet = alphabet
..remove('0')
..remove('1')
..remove('#')
..remove('+');
for (String char in message.toUpperCase().split('')) {
if (alphabet.contains(char)) {
return false;
}
}
return true;
}
}