function FormatFormula(Str:string):string;
var i,L:integer;
const SUB_0 = #$E2#$82#$80; SUPER_0 = #$E2#$81#$B0; SUPER_PLUS = #$E2#$81#$BA;
SUB_1 = #$E2#$82#$81; SUPER_1 = #$C2#$B9; SUPER_MINUS = #$E2#$81#$BB;
SUB_2 = #$E2#$82#$82; SUPER_2 = #$C2#$B2;
SUB_3 = #$E2#$82#$83; SUPER_3 = #$C2#$B3;
SUB_4 = #$E2#$82#$84; SUPER_4 = #$E2#$81#$B4;
SUB_5 = #$E2#$82#$85; SUPER_5 = #$E2#$81#$B5;
SUB_6 = #$E2#$82#$86; SUPER_6 = #$E2#$81#$B6;
SUB_7 = #$E2#$82#$87; SUPER_7 = #$E2#$81#$B7;
SUB_8 = #$E2#$82#$88; SUPER_8 = #$E2#$81#$B9;
SUB_9 = #$E2#$82#$89; SUPER_9 = #$E2#$81#$B9;
begin
Result := '';
L:=Length(Str);
case L of
0:exit;
1:begin
Result:=Str;
exit;
end;
2:begin
case Str[2] of
'0':Result := Str[1]+SUB_0;
'1':Result := Str[1]+SUB_1;
'2':Result := Str[1]+SUB_2;
'3':Result := Str[1]+SUB_3;
'4':Result := Str[1]+SUB_4;
'5':Result := Str[1]+SUB_5;
'6':Result := Str[1]+SUB_6;
'7':Result := Str[1]+SUB_7;
'8':Result := Str[1]+SUB_8;
'9':Result := Str[1]+SUB_9;
'+':Result := Str[1]+SUPER_PLUS;
'-':Result := Str[1]+SUPER_MINUS;
else Result := Str;
end;
exit;
end;
else begin
for i:=1 to L-2 do // The last two characters might be a charge, and should be treated separately
begin
case Str[i] of
'0':Result := Result+SUB_0;
'1':Result := Result+SUB_1;
'2':Result := Result+SUB_2;
'3':Result := Result+SUB_3;
'4':Result := Result+SUB_4;
'5':Result := Result+SUB_5;
'6':Result := Result+SUB_6;
'7':Result := Result+SUB_7;
'8':Result := Result+SUB_8;
'9':Result := Result+SUB_9;
else Result := Result+Str[i];
end;
end;
if Str[L] in ['+','-'] then
if Str[L-1] in DigitChars then
begin
case Str[L-1] of
'0':Result := Result+SUPER_0;
'1':Result := Result+SUPER_1;
'2':Result := Result+SUPER_2;
'3':Result := Result+SUPER_3;
'4':Result := Result+SUPER_4;
'5':Result := Result+SUPER_5;
'6':Result := Result+SUPER_6;
'7':Result := Result+SUPER_7;
'8':Result := Result+SUPER_8;
'9':Result := Result+SUPER_9;
end;
if Str[L]='+' then
Result := Result+SUPER_PLUS
else Result := Result+SUPER_MINUS;
end
else
else for i:= L-1 to L do
begin
case Str[i] of
'0':Result := Result+SUB_0;
'1':Result := Result+SUB_1;
'2':Result := Result+SUB_2;
'3':Result := Result+SUB_3;
'4':Result := Result+SUB_4;
'5':Result := Result+SUB_5;
'6':Result := Result+SUB_6;
'7':Result := Result+SUB_7;
'8':Result := Result+SUB_8;
'9':Result := Result+SUB_9;
else Result := Result+Str[i];
end;
end;
end;
end;
end;
procedure TfrmScratch.edFormulaChange(Sender : TObject);
begin
edFormula.Caption := FormatFormula(edFormula.Caption);
end;