Changeset 25 for trunk/UAcronym.pas


Ignore:
Timestamp:
May 8, 2016, 10:56:38 PM (8 years ago)
Author:
chronos
Message:
  • Added: Use block start/end for source import format parsing.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r24 r25  
    120120    Id: Integer;
    121121    Name: string;
     122    Block: TImportPattern;
    122123    Acronym: TImportPattern;
    123124    Meaning: TImportPattern;
     
    233234begin
    234235  Name := Source.Name;
     236  Block.StartString := Source.Block.StartString;
     237  Block.EndString := Source.Block.EndString;
    235238  Acronym.StartString := Source.Acronym.StartString;
    236239  Acronym.EndString := Source.Acronym.EndString;
     
    245248  WriteInteger(Node, 'Id', Id);
    246249  WriteString(Node, 'Name', Name);
     250  WriteString(Node, 'BlockStartString', Block.StartString);
     251  WriteString(Node, 'BlockEndString', Block.EndString);
    247252  WriteString(Node, 'AcronymStartString', Acronym.StartString);
    248253  WriteString(Node, 'AcronymEndString', Acronym.EndString);
     
    257262  Id := ReadInteger(Node, 'Id', 0);
    258263  Name := ReadString(Node, 'Name', '');
     264  Block.StartString := ReadString(Node, 'BlockStartString', '');
     265  Block.EndString := ReadString(Node, 'BlockEndString', '');
    259266  Acronym.StartString := ReadString(Node, 'AcronymStartString', '');
    260267  Acronym.EndString := ReadString(Node, 'AcronymEndString', '');
     
    385392  NewAcronym: TAcronymEntry;
    386393  P: Integer;
     394  NewName: string;
    387395begin
    388396  Stream := TMemoryStream.Create;
     
    393401      SetLength(S, Stream.Size);
    394402      Stream.Read(S[1], Length(S));
     403      if Format.Block.StartString <> '' then begin
     404        P := Pos(Format.Block.StartString, S);
     405        if P > 0 then
     406          Delete(S, 1, P + Length(Format.Block.StartString) - 1);
     407      end;
     408      if Format.Block.EndString <> '' then begin
     409        P := Pos(Format.Block.EndString, S);
     410        if P > 0 then
     411          Delete(S, P, Length(S));
     412      end;
     413
    395414      repeat
    396415        P := Pos(Format.Acronym.StartString, S);
     
    399418          Delete(S, 1, P + Length(Format.Acronym.StartString) - 1);
    400419          P := Pos(Format.Acronym.EndString, S);
    401           NewAcronym.Name := Trim(StripHTML(Copy(S, 1, P - 1)));
     420          NewName := Trim(StripHTML(Copy(S, 1, P - 1)));
     421          if NewName <> '' then NewAcronym.Name := NewName;
    402422          Delete(S, 1, P + Length(Format.Acronym.EndString) - 1);
    403423
Note: See TracChangeset for help on using the changeset viewer.