initial commit
[rofl0r-KOL.git] / UWrd.pas
blob9fdf6ce981cee54984ed9e9c94c1bb1d55ec1cee
1 unit UWrd;
3 interface
5 function words (str:string;d:char ):integer;
6 function wordn (str:string;d:char;n:integer):string ;
7 function wordd (str:string;d:char;n:integer):string ;
8 function wordp (str:string;d:char;n:integer):integer;
9 function wordi ( wrd,str:string;d:cHar):boolean;
10 function wordf (str:string;d:char;n:integer):string ;
12 implementation
14 function words;
15 var tempstr : string;
16 ins : boolean;
17 i,j : integer;
18 begin
19 tempstr := d + str + d;
20 ins := false;
21 j := 0;
22 for i := 1 to length(tempstr) do begin
23 if ins then
24 if tempstr[i] =d then ins:=false
25 else begin end
26 else
27 if tempstr[i]<>d then begin
28 inc(j);ins:=true;
29 end;
30 end;
31 words:=j;
32 end;
34 function wordn;
35 var i,j:integer;
36 tempstr:string;
37 begin
38 i:=words(str, d);
39 if i<n then begin
40 wordn:='';
41 exit;
42 end;
43 i:=1;
44 while words(copy(str,1,i), d)<n do inc(i);
45 j:=i;
46 tempstr:=str+d;
47 while tempstr[j]<>d do inc(j);
48 wordn:=copy(str,i,j-i);
49 end;
51 function wordd;
52 var i,j:integer;
53 sss:string;
54 tempstr:string;
55 begin
56 i:=words(str, d);
57 if i<n then begin
58 wordd:=str;
59 exit;
60 end;
61 i:=1;
62 while words(copy(str,1,i), d)<n do inc(i);
63 j:=i;
64 tempstr:=str+d;
65 while tempstr[j]<>d do inc(j);
66 sss :=copy(str,1,i-1);
67 wordd:=sss+copy(str,j+1,length(tempstr)-j);
68 end;
70 function wordp;
71 var i:integer;
72 begin
73 i:=words(str, d);
74 if i < n then begin
75 wordp := 0;
76 exit;
77 end;
78 i:=1;
79 while words(copy(str,1,i), d)<n do inc(i);
80 wordp := i;
81 end;
83 function wordi;
84 var i : integer;
85 begin
86 wordi := true;
87 for i := 1 to words(str, d) do
88 if wrd = wordn(str, d, i) tHen exit;
89 wordi := false;
90 end;
92 function wordf;
93 var i: integer;
94 begin
95 i := wordp(str, d, n);
96 wordf := '';
97 if (i > 0) and (i < length(str)) then
98 wordf := copy(str, i, length(str) - i + 1);
99 end;
101 end.