CWAPI - Charlie Wang API

CWMFoundation – Morse

CWMFoundation Charlie Wang 663℃

CWMFoundation 意为 Charlie.Wang Foundation Mini(迷你版)

是作者工作中为方便代码编写,逐渐整理归档的一些代码集。

在原有CWFoundation的基础上,去除了大量窗体上的控件,只留下一个Delphi Pas文件的轻量级类。

Morse只是一个双向转换摩斯电码的类。

//***********************************
//***** CWMFoundation Morse ******
//***********************************
{$REGION ' CWMFoundation Morse Implementation '}
function TCWMorse.TransferMORSE(_code: string; isMorse: Boolean):string;
var
 i:Integer;
begin
 CW_MORSE_A[0] := '';
 CW_MORSE_A[1] := '.-';
 CW_MORSE_A[2] := '-...';
 CW_MORSE_A[3] := '-.-.';
 CW_MORSE_A[4] := '-..';
 CW_MORSE_A[5] := '.';
 CW_MORSE_A[6] := '..-.';
 CW_MORSE_A[7] := '--.';
 CW_MORSE_A[8] := '....';
 CW_MORSE_A[9] := '..';
 CW_MORSE_A[10] := '.---';
 CW_MORSE_A[11] := '-.-';
 CW_MORSE_A[12] := '.-..';
 CW_MORSE_A[13] := '--';
 CW_MORSE_A[14] := '-.';
 CW_MORSE_A[15] := '---';
 CW_MORSE_A[16] := '.--.';
 CW_MORSE_A[17] := '--.-';
 CW_MORSE_A[18] := '.-.';
 CW_MORSE_A[19] := '...';
 CW_MORSE_A[20] := '-';
 CW_MORSE_A[21] := '..-';
 CW_MORSE_A[22] := '...-';
 CW_MORSE_A[23] := '.--';
 CW_MORSE_A[24] := '-..-';
 CW_MORSE_A[25] := '-.--';
 CW_MORSE_A[26] := '--..';
 CW_MORSE_A[27] := '-.-..';
 CW_MORSE_A[28] := '--.-.';
 CW_MORSE_A[29] := '----';
 CW_MORSE_A[30] := '.---.';
 CW_MORSE_A[31] := '...-.';
 CW_MORSE_A[32] := '..--';
 Result := ' ';
 if isMorse = True then
 begin
 for i := 0 to Length(CW_MORSE_A)-1 do
 begin
 if CW_MORSE_A[i] = _code then
 begin
 Result := CW_MORSE_B[i];
 Exit;
 end;
 end;
 end else
 begin
 for i := 0 to Length(CW_MORSE_B)-1 do
 begin
 if CW_MORSE_B[i] = _code then
 begin
 Result := CW_MORSE_A[i];
 Exit;
 end;
 end;
 end;
end;
 
function TCWMorse.MorseToString(_morse: string):string;
var
 i:Integer;
 ResultString : string;
begin
 ResultString := '';
 try
 _morse := CWStr.TRIM_SIDES(_morse);
 CWStr.SPLIT_STRING(_morse,CW_SPACE);
 for i := 0 to CW_SPLITSTRING_STRINGLIST.Count-1 do
 begin
 ResultString := ResultString + TransferMORSE(CW_SPLITSTRING_STRINGLIST[i],True);
 end;
 finally
 Result := CWStr.TRIM_ALL_SINGLE(ResultString);
 CW_SPLITSTRING_STRINGLIST.Clear;
 end;
end;
 
function TCWMorse.StringToMorse(_string: string):string;
var
 i:Integer;
 ResultString : string;
begin
 ResultString := '';
 _string := UpperCase(_string);
 try
 for i := 1 to Length(_string) do
 begin
 ResultString := ResultString + TransferMORSE(MidStr(_string,i,1),False) + CW_SPACE;;
 end;
 finally
 Result := CWStr.TRIM_SIDES(ResultString);
 end;
end;
{$ENDREGION}

该代码仍旧会不断更新…



转载请注明:CWAPI » CWMFoundation – Morse