Changeset 50 for trunk/UAcronym.pas


Ignore:
Timestamp:
Jul 25, 2016, 5:07:25 PM (8 years ago)
Author:
chronos
Message:
  • Added: New pattern action "Remove on start".
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UAcronym.pas

    r47 r50  
    115115  end;
    116116
    117   TImportPatternFlag = (ipfNone, ipfNewItem, ipfSkip);
     117  TImportPatternFlag = (ipfNone, ipfNewItem, ipfSkip, ipfRemove);
    118118  TImportVariable = (ivNone, ivAcronym, ivMeaning, ivDescription);
    119119
     
    247247  SNewItem = 'New item';
    248248  SSkip = 'Skip';
     249  SRemoveOnStart = 'Remove on start';
     250  SUnsupportedAuthMethod = 'Unsupported HTTP authorization method';
    249251
    250252
     
    258260  ImportPatternFlagString[ipfNewItem] := SNewItem;
    259261  ImportPatternFlagString[ipfSkip] := SSkip;
     262  ImportPatternFlagString[ipfRemove] := SRemoveOnStart;
    260263end;
    261264
     
    393396var
    394397  H: string;
    395   P: Integer;
    396398begin
    397399  with TFPHttpClient(Sender) do begin
     
    400402
    401403    if H <> 'Basic' then
    402       raise Exception.Create('Unsupported HTTP authorization method');
     404      raise Exception.Create(SUnsupportedAuthMethod);
    403405
    404406    if (Self.UserName <> '') and (UserName = '') then begin
     
    440442
    441443  // Remove unneeded items
    442 {  repeat
     444  repeat
    443445    LastLength := Length(S);
    444446    for I := 0 to Format.ItemPatterns.Count - 1 do
    445447    with TImportPattern(Format.ItemPatterns[I]) do
    446     if Flag = ipfSkip then begin
     448    if Flag = ipfRemove then begin
    447449      P := Pos(StartString, S);
    448450      if P > 0 then begin
     
    455457    end;
    456458  until Length(S) = LastLength;
    457 }
     459
    458460  // Find items
    459461  repeat
     
    462464    while I < Format.ItemPatterns.Count do
    463465    with TImportPattern(Format.ItemPatterns[I]) do begin
    464       if Flag <> ipfSkip then begin
     466      if Flag <> ipfRemove then begin
    465467        if Length(StartString) > 0 then begin
    466468          P := Pos(StartString, S);
     
    470472        if ((Length(StartString) > 0) and (P > 0)) or (Length(StartString) = 0) then begin
    471473          P := Pos(EndString, S);
    472           T := StripHTML(Copy(S, 1, P - 1));
    473           T := StringReplace(T, '&quot;', '"', [rfReplaceAll]);
    474           T := StringReplace(T, '&trade;', 'TM', [rfReplaceAll]);
    475           T := StringReplace(T, '&amp;', '&', [rfReplaceAll]);
    476           T := StringReplace(T, '&#160;', ' ', [rfReplaceAll]); // No break space
    477           T := Trim(T);
    478           case Variable of
    479             ivAcronym: NewAcronym.Name := T;
    480             ivMeaning: NewAcronym.Meaning := T;
    481             ivDescription: NewAcronym.Description := T;
     474          T := Copy(S, 1, P - 1);
     475          if Flag <> ipfSkip then begin
     476            T := StripHTML(T);
     477            T := StringReplace(T, '&quot;', '"', [rfReplaceAll]);
     478            T := StringReplace(T, '&trade;', 'TM', [rfReplaceAll]);
     479            T := StringReplace(T, '&amp;', '&', [rfReplaceAll]);
     480            T := StringReplace(T, '&#160;', ' ', [rfReplaceAll]); // No break space
     481            T := Trim(T);
     482            case Variable of
     483              ivAcronym: NewAcronym.Name := T;
     484              ivMeaning: NewAcronym.Meaning := T;
     485              ivDescription: NewAcronym.Description := T;
     486            end;
    482487          end;
    483488          Delete(S, 1, P + Length(EndString) - 1);
Note: See TracChangeset for help on using the changeset viewer.