-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathold_school_texting_unit.pas
More file actions
154 lines (144 loc) · 3.21 KB
/
old_school_texting_unit.pas
File metadata and controls
154 lines (144 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
6 kyu
Texting with an old-school mobile phone
https://www.codewars.com/kata/5ca24526b534ce0018a137b5
}
unit old_school_texting_unit;
{$mode objfpc}{$H+}
interface
function SendMessage(msg: string): string;
implementation
type
Chars = ' ' .. 'z';
const
Trans: array[Chars] of string = (
'0', {32=SPACE}
'1111', {33=!}
'', {34="}
'#-', {35=#}
'', {36=$}
'', {37=%}
'', {38=&}
'*', {39='}
'', {40=(}
'', {41=)}
'*-', {42=*}
'***', {43=+}
'11', {44=,}
'**', {45=-}
'1', {46=.}
'', {47=/}
'0-', {48=0}
'1-', {49=1}
'2-', {50=2}
'3-', {51=3}
'4-', {52=4}
'5-', {53=5}
'6-', {54=6}
'7-', {55=7}
'8-', {56=8}
'9-', {57=9}
'', {58=:}
'', {59=;}
'', {60=<}
'****', {61==}
'', {62=>}
'111', {63=?}
'', {64=@}
'^2', {65=A}
'^22', {66=B}
'^222', {67=C}
'^3', {68=D}
'^33', {69=E}
'^333', {70=F}
'^4', {71=G}
'^44', {72=H}
'^444', {73=I}
'^5', {74=J}
'^55', {75=K}
'^555', {76=L}
'^6', {77=M}
'^66', {78=N}
'^666', {79=O}
'^7', {80=P}
'^77', {81=Q}
'^777', {82=R}
'^7777', {83=S}
'^8', {84=T}
'^88', {85=U}
'^888', {86=V}
'^9', {87=W}
'^99', {88=X}
'^999', {89=Y}
'^9999', {90=Z}
'', {91=[}
'', {92=\}
'', {93=]}
'', {94=^}
'', {95=_}
'', {96=`}
'v2', {97=a}
'v22', {98=b}
'v222', {99=c}
'v3', {100=d}
'v33', {101=e}
'v333', {102=f}
'v4', {103=g}
'v44', {104=h}
'v444', {105=i}
'v5', {106=j}
'v55', {107=k}
'v555', {108=l}
'v6', {109=m}
'v66', {110=n}
'v666', {111=o}
'v7', {112=p}
'v77', {113=q}
'v777', {114=r}
'v7777', {115=s}
'v8', {116=t}
'v88', {117=u}
'v888', {118=v}
'v9', {119=w}
'v99', {120=x}
'v999', {121=y}
'v9999' {122=z}
);
function SendMessage(msg: string): string;
var
lower: boolean = True;
curr: Chars;
i: integer;
lastchar: char = ' ';
tr: string;
firstchar: char;
begin
Result := '';
for i := 1 to Length(msg) do
begin
if not (msg[i] in [Low(Trans)..High(Trans)]) then
Continue;
curr := msg[i];
tr := Trans[curr];
if tr = '' then
Continue;
firstchar := tr[1];
if (firstchar = '^') or (firstchar = 'v') then
begin
tr := Copy(tr, 2);
if (lower and (firstchar = '^')) or ((not lower) and (firstchar = 'v')) then
begin
lower := not lower;
Result := Result + '#';
lastchar := '#';
end;
end;
if tr[1] = lastchar then
Result := Result + ' ';
Result := Result + tr;
lastchar := tr[Length(tr)];
if lastchar = '-' then
lastchar := ' ';
end;
end;
end.