Janilabo

Janilabo | Expand() [SCAR Divi]

Apr 28th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.22 KB | None | 0 0
  1. function Expand(trgt_pos: Integer; s1, s2, str: string; includeTags: Boolean): string;
  2. var
  3.   l, p, start, finish, s1L, s2L, e: Integer;
  4.   tmp: string;
  5. begin
  6.   Result := '';
  7.   l := Length(str);
  8.   s1L := Length(s1);
  9.   s2L := Length(s2);
  10.   if ((s1L <= l) and (s2L <= l) and (trgt_pos <= l) and (trgt_pos >= 1)) then
  11.   begin
  12.     if includeTags then
  13.     begin
  14.       s1L := 0;
  15.       e := s2L;
  16.       s2L := 0;
  17.     end;
  18.     finish := PosEx(s2, str, trgt_pos);
  19.     if ((finish < 1) or (finish = trgt_pos)) then
  20.       Exit;
  21.     tmp := Copy(str, 1, trgt_pos);
  22.     repeat
  23.       p := PosEx(s1, tmp, (p + 1));
  24.       if (p > 0) then
  25.         start := p;
  26.     until (p <= 0);
  27.     if ((start <> trgt_pos) and (start > 0) and (finish > 0) and (start < finish)) then
  28.       Result := Copy(str, (start + s1L), (((finish - start) - S2L) + e));
  29.     tmp := '';
  30.   end;
  31. end;
  32.  
  33. var
  34.   str, tmp: string;
  35.   id, id_pos: Integer;
  36.  
  37. begin
  38.   ClearDebug;
  39.   str := '{* Lets do this... {* function Expand() *} It is... Magical! *}';
  40.   WriteLn('ExpandEx(): "' + Expand(Pos('Expand', str), '{* ', ' *}', str, True) + '" [tags included]');
  41.   WriteLn('ExpandEx(): "' + Expand(Pos('Expand', str), '{* ', ' *}', str, False) + '" [without tags]');
  42. end.
Advertisement
Add Comment
Please, Sign In to add comment