Develop and Download Open Source Software

Browse Subversion Repository

Contents of /findtext.pas

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Mon Nov 7 12:03:00 2011 UTC (12 years, 4 months ago) by shiraishikazuo
File MIME type: text/x-pascal
File size: 3494 byte(s)


1 unit findtext;
2 {$IFDEF FPC}
3 {$MODE DELPHI}{$H+}
4 {$ENDIF}
5
6 (***************************************)
7 (* Copyright (C) 2003, SHIRAISHI Kazuo *)
8 (***************************************)
9
10
11 interface
12 uses Classes, StdCtrls, ComCtrls, Dialogs, SynEdit,
13 base,arithmet;
14
15 //function FindWord(memo:TMemo; const SearchStr: string; StartPos, Len: Integer; Options: TSearchTypes): Integer;
16 function FindWord(memo:TSynEdit; const SearchStr: string; StartPos, Len: Integer;Options: TFindOptions): Integer;
17 //function MultiLine(var s:string):boolean;
18 function MultiLine(const s:string):boolean;
19 function SearchText(Memo:TSynEdit; const s:string; n,searchlen:integer; Options1:TFindOptions):integer;
20
21 implementation
22 uses Sysutils,Forms,
23 sconsts;
24
25 const PunctuationCharactors :set of char
26 =[chr(0)..' ', '!', '#', '&'..'/', ':'..'?','\', '^'];
27
28 function token(memo:TSynEdit; var cp0,cp:integer):string;
29 function t(p:integer):char;
30 var
31 s:string[1];
32
33 begin
34
35 result:=#0;
36 //if p<length(memo.text) then
37 with memo do
38 begin
39 selstart:=p;
40 selend:=p+1; //sellength:=1;
41 s:=seltext;
42 if length(s)>0 then
43 result:=s[1];
44 end;
45 end;
46 begin
47 while t(cp) in [#13,#10,' '] do inc(cp);
48 cp0:=cp;
49 if t(cp) in ['<','=','>'] then
50 begin
51 inc(cp);
52 if t(cp) in ['<','=','>'] then
53 inc(cp)
54 end
55 else if t(cp)='"' then
56 repeat
57 repeat
58 inc(cp);
59 until t(cp) in [#0,#13,#10,'"'];
60 if t(cp)='"' then inc(cp);
61 until t(cp)<>'"'
62 else if t(cp) in PunctuationCharactors then
63 inc(cp)
64 else
65 while not(t(cp) in PunctuationCharactors) do
66 inc(cp);
67 with memo do
68 begin
69 selstart:=cp0;
70 SelEnd:=cp; //sellength:=cp-cp0;
71 result:=seltext;
72 end;
73 end;
74
75
76 function FindWord(memo:TSynEdit; const SearchStr: string; StartPos, Len: Integer; Options:TFindOptions): Integer;
77 var
78 cp,cp0:integer;
79 s,s1:string;
80 begin
81 result:=-1;
82 s1:=SearchStr;
83 if not(frMatchCase in options) then s1:=Uppercase(s1);
84 cp:=StartPos;
85 memo.Lines.BeginUpdate;
86 while (cp-Startpos<len) {and (cp<length(memo.text))} do
87 begin
88 s:=token(memo,cp0,cp);
89 if not(frMatchCase in Options) then s:=UpperCase(s);
90 if s=s1 then
91 begin result:=cp0; break end;
92 end;
93 memo.lines.EndUpdate
94 end;
95
96 function MultiLine(const s:string):boolean;
97 var
98 cp0,cp:integer;
99 begin
100 cp:=1;
101 result:=(pos(EOL,s)>0);
102 (*
103 if result then
104 begin
105 s:=token(s,cp0,cp);
106 if (length(s)=1) and (s[1] in PunctuationCharactors) then s:=''
107 end
108 *)
109 end;
110
111 function SearchText(memo:TSynEdit;const s:string; n,searchlen:integer; Options1:TFindOptions):integer;
112 var
113 i:integer;
114 len:integer;
115 cond:boolean;
116 begin
117 len:=length(s);
118 result:=-1;
119 with Memo do
120 begin
121 Lines.BeginUpdate;
122 for i:=n to base.min(length(Text)-len+1,n+searchlen) do
123 begin
124 selstart:=i;
125 selend:=i+len; // sellength:=len;
126 if frMatchCase in Options1 then
127 cond:=(seltext=s)
128 else
129 cond:=comparetext(seltext,s)=0;
130 if cond then
131 begin
132 result:=i;
133 break;
134 end;
135 end;
136 Lines.EndUpdate;
137 end;
138 end;
139
140
141 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26