febe5a9eec
This is the beta version of the Morse Converter for the web. It is a complete rewrite and now a full webapp using Polymer. It supports all the features of the desktop and the android version.
523 lines
11 KiB
CoffeeScript
523 lines
11 KiB
CoffeeScript
getWrittenMorseDecoded = (input) ->
|
|
# Well, this shouldn't happen...
|
|
if !(input)
|
|
return null
|
|
|
|
# remove trailing whitspaces
|
|
if input.charAt input.length is " "
|
|
input.substring 0, input.length - 1
|
|
|
|
input = input.toUpperCase()
|
|
output = ""
|
|
|
|
# Return special signs
|
|
if input is "LETTERSPACE"
|
|
return "#"
|
|
else if input is "END OF WORK"
|
|
return "000101"
|
|
else if input is "ERROR"
|
|
return "00000000"
|
|
else if input is "STARTING SIGNAL"
|
|
return "10101"
|
|
else if input is "ENDING SIGNAL"
|
|
return "01010"
|
|
else if input is "UNDERSTOOD"
|
|
return "00010"
|
|
else if input is "WAIT"
|
|
return "01000"
|
|
else if input is "SOS"
|
|
return "000111000"
|
|
else if input is "LETTER SPACE"
|
|
return "#"
|
|
else if input is "WORD SPACE"
|
|
return "+"
|
|
else # the converting part
|
|
|
|
while input.length > 0
|
|
|
|
if input.charAt(0) is " "
|
|
if output.charAt(output.length) is "#"
|
|
output = output.substring 0, output.length - 1
|
|
output += "+"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "\n"
|
|
output += "<br>"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "A"
|
|
output += "01#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "B"
|
|
output += "1000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "C"
|
|
output += "1010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "D"
|
|
output += "100#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "E"
|
|
output += "0#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "F"
|
|
output += "0010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "G"
|
|
output += "110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "H"
|
|
output += "0000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "I"
|
|
output += "00#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "J"
|
|
output += "0111#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "K"
|
|
output += "101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "L"
|
|
output += "0100#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "M"
|
|
output += "11#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "N"
|
|
output += "10#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "O"
|
|
output += "111#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "P"
|
|
output += "0110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Q"
|
|
output += "1101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "R"
|
|
output += "010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "S"
|
|
output += "000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "T"
|
|
output += "1#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "U"
|
|
output += "001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "V"
|
|
output += "0001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "W"
|
|
output += "011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "X"
|
|
output += "1001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Y"
|
|
output += "1011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Z"
|
|
output += "1100#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "0"
|
|
output += "11111#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "1"
|
|
output += "01111#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "2"
|
|
output += "00111#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "3"
|
|
output += "00011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "4"
|
|
output += "00001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "5"
|
|
output += "00000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "6"
|
|
output += "10000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "7"
|
|
output += "11000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "8"
|
|
output += "11100#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "9"
|
|
output += "11110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Ä"
|
|
output += "0101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Ö"
|
|
output += "1110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "Ü"
|
|
output += "0011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "ß"
|
|
output += "00011000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "."
|
|
output += "010101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is ","
|
|
output += "110011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is ":"
|
|
output += "111000#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is ""
|
|
output += "101010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "?"
|
|
output += "001100#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "!"
|
|
output += "101011#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "-"
|
|
output += "100001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "_"
|
|
output += "001101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "("
|
|
output += "10110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is ")"
|
|
output += "101101#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "="
|
|
output += "10001#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "+"
|
|
output += "01010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "/"
|
|
output += "10010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "@"
|
|
output += "011010#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "'"
|
|
output += "011110#"
|
|
input = input.substring 1
|
|
|
|
else if input.charAt(0) is "$"
|
|
output += "0001001#"
|
|
input = input.substring 1
|
|
|
|
else
|
|
return "Code not listed or wrong."
|
|
|
|
if output.charAt(output.length - 1) is "#"
|
|
output = output.substring 0, output.length - 1
|
|
|
|
return output
|
|
|
|
getWrittenMorseEncoded = (input) ->
|
|
# Well, this shouldn't happen...
|
|
if !(input) then return null
|
|
|
|
# remove trailing whitspaces
|
|
while input.charAt(input.length - 1) is " "
|
|
input = input.substring 0, input.length - 1
|
|
|
|
input = input.toUpperCase()
|
|
|
|
while input.charAt(input.length - 1) is "#" or
|
|
input.charAt(input.length - 1) is "+" or
|
|
input.charAt(input.length - 1) is "\n"
|
|
input = input.substring 0, input.length - 1
|
|
|
|
if input.charAt(input.length - 1) isnt "#"
|
|
input += "#"
|
|
|
|
inputToSign = input
|
|
output = ""
|
|
|
|
while inputToSign isnt "#"
|
|
|
|
d = 0
|
|
signFull = true
|
|
sign = ""
|
|
|
|
while signFull
|
|
|
|
if inputToSign.charAt(d) is "+" or
|
|
inputToSign.charAt(d) is "#" or
|
|
inputToSign.charAt(0) is "\n"
|
|
|
|
if d is 0
|
|
|
|
if inputToSign.charAt(0) is "+"
|
|
output += " "
|
|
inputToSign = inputToSign.substring 1, inputToSign.length
|
|
|
|
if inputToSign.charAt(0) is "#"
|
|
inputToSign = inputToSign.substring 1, inputToSign.length
|
|
|
|
if inputToSign.charAt(0) is "\n"
|
|
output += "<br>"
|
|
inputToSign = inputToSign.substring 1, inputToSign.length
|
|
|
|
else
|
|
sign = inputToSign.substring 0, d
|
|
inputToSign = inputToSign.substring d, inputToSign.length
|
|
signFull = false
|
|
|
|
else
|
|
d++
|
|
|
|
if sign is "01"
|
|
output += "A"
|
|
|
|
else if sign is "1000"
|
|
output += "B"
|
|
|
|
else if sign is "1010"
|
|
output += "C"
|
|
|
|
else if sign is "100"
|
|
output += "D"
|
|
|
|
else if sign is "0"
|
|
output += "E"
|
|
|
|
else if sign is "0010"
|
|
output += "F"
|
|
|
|
else if sign is "110"
|
|
output += "G"
|
|
|
|
else if sign is "0000"
|
|
output += "H"
|
|
|
|
else if sign is "00"
|
|
output += "I"
|
|
|
|
else if sign is "0111"
|
|
output += "J"
|
|
|
|
else if sign is "101"
|
|
output += "K"
|
|
|
|
else if sign is "0100"
|
|
output += "L"
|
|
|
|
else if sign is "11"
|
|
output += "M"
|
|
|
|
else if sign is "10"
|
|
output += "N"
|
|
|
|
else if sign is "111"
|
|
output += "O"
|
|
|
|
else if sign is "0110"
|
|
output += "P"
|
|
|
|
else if sign is "1101"
|
|
output += "Q"
|
|
|
|
else if sign is "010"
|
|
output += "R"
|
|
|
|
else if sign is "000"
|
|
output += "S"
|
|
|
|
else if sign is "1"
|
|
output += "T"
|
|
|
|
else if sign is "001"
|
|
output += "U"
|
|
|
|
else if sign is "0001"
|
|
output += "V"
|
|
|
|
else if sign is "011"
|
|
output += "W"
|
|
|
|
else if sign is "1001"
|
|
output += "X"
|
|
|
|
else if sign is "1011"
|
|
output += "Y"
|
|
|
|
else if sign is "1100"
|
|
output += "Z"
|
|
|
|
else if sign is "11111"
|
|
output += "0"
|
|
|
|
else if sign is "01111"
|
|
output += "1"
|
|
|
|
else if sign is "00111"
|
|
output += "2"
|
|
|
|
else if sign is "00011"
|
|
output += "3"
|
|
|
|
else if sign is "00001"
|
|
output += "4"
|
|
|
|
else if sign is "00000"
|
|
output += "5"
|
|
|
|
else if sign is "10000"
|
|
output += "6"
|
|
|
|
else if sign is "11000"
|
|
output += "7"
|
|
|
|
else if sign is "11100"
|
|
output += "8"
|
|
|
|
else if sign is "11110"
|
|
output += "9"
|
|
|
|
else if sign is "0101"
|
|
output += "Ä"
|
|
|
|
else if sign is "1110"
|
|
output += "Ö"
|
|
|
|
else if sign is "0011"
|
|
output += "Ü"
|
|
|
|
else if sign is "00011000"
|
|
output += "ß"
|
|
|
|
else if sign is "1111"
|
|
output += "CH"
|
|
|
|
else if sign is "010101"
|
|
output += "."
|
|
|
|
else if sign is "110011"
|
|
output += ","
|
|
|
|
else if sign is "111000"
|
|
output += ":"
|
|
|
|
else if sign is "101010"
|
|
output += ";"
|
|
|
|
else if sign is "001100"
|
|
output += "?"
|
|
|
|
else if sign is "101011"
|
|
output += "!"
|
|
|
|
else if sign is "100001"
|
|
output += "-"
|
|
|
|
else if sign is "001101"
|
|
output += "_"
|
|
|
|
else if sign is "10110"
|
|
output += "("
|
|
|
|
else if sign is "101101"
|
|
output += ")"
|
|
|
|
else if sign is "011110"
|
|
output += "'"
|
|
|
|
else if sign is "10001"
|
|
output += "="
|
|
|
|
else if sign is "01010"
|
|
output += "+"
|
|
|
|
else if sign is "10010"
|
|
output += "/"
|
|
|
|
else if sign is "011010"
|
|
output += "@"
|
|
|
|
else if sign is "10101"
|
|
output += "Begin of the signal"
|
|
|
|
else if sign is "10001"
|
|
output += "Wait"
|
|
|
|
else if sign is "00010"
|
|
output += "Understood"
|
|
|
|
else if sign is "000101"
|
|
output += "End of work"
|
|
|
|
else if sign is "000111000"
|
|
output += "SOS"
|
|
|
|
else if sign is "00000000"
|
|
output += "Error"
|
|
|
|
else
|
|
return "Code not listed or wrong."
|
|
|
|
return output
|