aboutsummarylogtreecommitdiffstats
path: root/func_str_composition.pas
blob: 85a54efa06158cd9cd5e24186c821cb986b8e6b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{ Module contains composition of string functions }
unit func_str_composition;

{$mode ObjFPC}{$H+}

interface

uses
  Classes, SysUtils, types_for_app;

function ApplyStringFunctions(input: String; funcs: TFuncStrArray): String;
procedure ComposeStrFunc(var funcs: TFuncStrArray;   f : TFuncStr);

implementation

function ApplyStringFunctions(input: String; funcs: TFuncStrArray): String;
   var
     i: Integer;
     res: String;
     fs : TFuncStr;
   begin
     res := input;
     for i := High(funcs) downto Low(funcs) do
     begin
       fs := funcs[i];
       res := fs(res);
     end;
     Result := res;
   end;

procedure ComposeStrFunc(var funcs: TFuncStrArray;   f: TFuncStr);
begin
  SetLength( funcs, Length(funcs) + 1);
  funcs[ High(funcs) ] := f;
end;

end.