Вверх ↑
Ответов: 9906
Рейтинг: 351
#1: 2016-06-12 08:14:14 ЛС | профиль | цитата
Слушай, nesco...

Присмотрелся я тут к использованию FParse.
Вспомнил, что это я сам писал комментарий:    // Защиты от Len<=0 -- НЕТ!!!

И - не понравилось мне (см. комментарий):
#pas
procedure THIHiLightMemo.ParseHilighting; //added by Galkov
.....................
UG := FParse(U, '=');
while UG <> '' do begin
UG := Uppercase(UG);
if (UG = 'U') then
include(AttrArr[i].fontstyle, fsUnderline)
else if (UG = 'B') then
include(AttrArr[i].fontstyle, fsBold)
else if (UG = 'C') or (UG = 'I') then
include(AttrArr[i].fontstyle, fsItalic)
else if (UG = 'S') then
include(AttrArr[i].fontstyle, fsStrikeOut);
// Где у нас ГАРАНТИЯ, что тут U<>'' ???
// Более того: у нас есть гарантия, что U='' на последнем "правильном" заходе
UG := FParse(U, '=');
end;
end;
end;

Отсюда, такое предложение:
#pas
procedure THIHiLightMemo.ParseHilighting; //added by Galkov
var i,k:integer; U,UG,str:string;
begin
for i := HS.Count - 1 downto min do
if HS.Items[i] = '' then HS.Delete(i)
else begin
U := HS.Items[i];
str := FParse(U, '=');
if str = '' then HS.Delete(i);
end;
SetLength(AttrArr, HS.Count);
SetLength(TypeArr, HS.Count);
for i := HS.Count - 1 downto min do begin
U := HS.Items[i];
str := FParse(U, '=');
k := PosEx('*', str, 1);
if (k=0)and(Length(str)>2)and(str[1]='{')and(str[Length(str)]='}') then begin
str := Copy(str, 2, Length(str)-2);
dec(k); // устанавливаем признак блока
end;
HS.Items[i] := str;
TypeArr[i] := k;
U := Uppercase(U) + '==';
AttrArr[i].fontcolor := Str2Color(FParse(U, '=')); //++Colors
AttrArr[i].fontstyle := [];
repeat
UG := FParse(U, '=');
if (UG = 'U') then
include(AttrArr[i].fontstyle, fsUnderline)
else if (UG = 'B') then
include(AttrArr[i].fontstyle, fsBold)
else if (UG = 'C') or (UG = 'I') then
include(AttrArr[i].fontstyle, fsItalic)
else if (UG = 'S') then
include(AttrArr[i].fontstyle, fsStrikeOut);
until UG = ''; // Может лучше: (U='') ??? Хотя и так правильно...
end;
end;

Другие вхождения FParse в коде не просматривал. Мои возможности не беспредельны

карма: 9

0