
27.08.2010, 00:57
|
 |
Гуру
|
|
Регистрация: 09.03.2009
Адрес: На курорте, из окна вижу теплое Баренцево море. Бррр.
Сообщения: 4,723
Репутация: 52347
|
|
Забавная задачка, давно такой небыло. Вот такая забавка получилась:
Код:
TSection = record
Name, Value: String;
end;
TSectionArray = Array of TSection;
TCustomParser = class
fText: String;
fSections: TSectionArray;
private
procedure SetText(const Value: String);
function GetSectionCount: Integer;
public
property Text: String read fText write SetText;
property Count: Integer read GetSectionCount;
property Sections: TSectionArray read fSections write fSections;
function GetSectionValue(Section: String): String;
end;
{ TCustomParser }
function TCustomParser.GetSectionCount: Integer;
begin
Result := Length(fSections);
end;
function TCustomParser.GetSectionValue(Section: String): String;
Var i: Integer;
begin
for i := 0 to Length(fSections) - 1
do if fSections[i].Name = Section
then begin
Result := fSections[i].Value;
Break;
end;
end;
procedure TCustomParser.SetText(const Value: String);
Var S: String;
begin
fText := Value;
S := Value;
SetLength(fSections, 0);
while Pos('<', S) > 0
do begin
SetLength(fSections, Length(fSections) + 1);
Delete(S, 1, Pos('<', S));
fSections[High(fSections)].Name := Copy(S, 1, Pos('>', S) - 1);
Delete(S, 1, Pos('>', S));
fSections[High(fSections)].Value := Copy(S, 1, Pos('</', S) - 1);
Delete(S, 1, Pos('>', S));
end;
end;
__________________
Жизнь такова какова она есть и больше никакова.
Помогаю за спасибо.
|