• R/O
  • SSH
  • HTTPS

dzlargetextview: Commit


Commit MetaInfo

Revision272 (tree)
Time2018-05-10 19:38:57
Authordummzeuch

Log Message

search -> search test

Change Summary

Incremental Difference

--- trunk/src/dzLargeTextViewer.dpr (revision 271)
+++ trunk/src/dzLargeTextViewer.dpr (revision 272)
@@ -5,20 +5,18 @@
55 w_LargeTextViewer in 'w_LargeTextViewer.pas' {f_LargeTextViewer},
66 u_TextFileIndexer in 'u_TextFileIndexer.pas',
77 w_GotoLine in 'w_GotoLine.pas' {f_GotoLine},
8- w_Search in 'w_Search.pas' {f_Search},
8+ w_BMSearchTest in 'w_BMSearchTest.pas' {f_BMSearchTest},
99 JclUnicode in '..\libs\jcl\source\common\JclUnicode.pas',
1010 u_LargeTextAccess in 'u_LargeTextAccess.pas',
11- u_Int64ListFile in 'u_Int64ListFile.pas';
11+ u_Int64ListFile in 'u_Int64ListFile.pas',
12+ w_Search in 'w_Search.pas' {f_Search};
1213
1314 {$R *_version.res}
1415 {$R *_icon.res}
1516
16-var
17- f_Search: Tf_Search;
1817 begin
1918 Application.Initialize;
2019 Application.MainFormOnTaskbar := True;
21-// Application.CreateForm(Tf_Search, f_Search);
2220 Application.CreateForm(Tf_LargeTextViewer, f_LargeTextViewer);
2321 Application.Run;
2422 end.
--- trunk/src/dzLargeTextViewer.dproj (revision 271)
+++ trunk/src/dzLargeTextViewer.dproj (revision 272)
@@ -256,125 +256,6 @@
256256
257257
258258
259-
260-
261-
262-
263-
264-
265-
266-
267-
268-
269-
270-
271-
272-
273-
274-
275-
276-
277-
278-
279-
280-
281-
282-
283-
284-
285-
286-
287-
288-
289-
290-
291-
292-
293-
294-
295-
296-
297-
298-
299-
300-
301-
302-
303-
304-
305-
306-
307-
308-
309-
310-
311-
312-
313-
314-
315-
316-
317-
318-
319-
320-
321-
322-
323-
324-
325-
326-
327-
328-
329-
330-
331-
332-
333-
334-
335-
336-
337-
338-
339-
340-
341-
342-
343-
344-
345-
346-
347-
348-
349-
350-
351-
352-
353-
354-
355-
356-
357-
358-
359-
360-
361-
362-
363-
364-
365-
366-
367-
368-
369-
370-
371-
372-
373-
374-
375-
376-
377-
378259 <Excluded_Packages Name="$(BDS)\bin\dcloffice2k100.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
379260 <Excluded_Packages Name="$(BDS)\bin\dclofficexp100.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
380261 <Excluded_Packages Name="$(BDS)\bin\bcbie100.bpl">File c:\program files (x86)\codegear\rad studio\5.0\bin\bcbie100.bpl not found</Excluded_Packages>
@@ -407,6 +288,9 @@
407288 <DCCReference Include="u_Int64ListFile.pas" />
408289 <DCCReference Include="u_LargeTextAccess.pas" />
409290 <DCCReference Include="u_TextFileIndexer.pas" />
291+ <DCCReference Include="w_BMSearchTest.pas">
292+ <Form>f_BMSearchTest</Form>
293+ </DCCReference>
410294 <DCCReference Include="w_GotoLine.pas">
411295 <Form>f_GotoLine</Form>
412296 </DCCReference>
--- trunk/src/w_BMSearchTest.pas (nonexistent)
+++ trunk/src/w_BMSearchTest.pas (revision 272)
@@ -0,0 +1,214 @@
1+unit w_BMSearchTest;
2+
3+interface
4+
5+uses
6+ Windows,
7+ Messages,
8+ SysUtils,
9+ Variants,
10+ Classes,
11+ Graphics,
12+ Controls,
13+ Forms,
14+ StdCtrls,
15+ u_dzTranslator;
16+
17+type
18+ TOnSearchEvent = procedure(_Sender: TObject; const _Pattern: string) of object;
19+
20+type
21+ Tf_BMSearchTest = class(TForm)
22+ ed_Pattern: TEdit;
23+ l_Pattern: TLabel;
24+ m_Text: TMemo;
25+ b_Find: TButton;
26+ procedure b_FindClick(Sender: TObject);
27+ private
28+ FCallback: TOnSearchEvent;
29+ procedure SetData(const _Pattern: string; _Callback: TOnSearchEvent);
30+ public
31+ class procedure Execute(_Owner: TWinControl; const _Pattern: string; _Callback: TOnSearchEvent); static;
32+ constructor Create(_Owner: TComponent); override;
33+ end;
34+
35+implementation
36+
37+{$R *.dfm}
38+
39+uses
40+ StrUtils,
41+ u_dzVclUtils;
42+
43+type
44+ ITextBuffer = interface ['{8B4A019A-99CA-4E86-864D-D1E9E6020648}']
45+ function GetChar(_Idx: Int64): Char;
46+ function GetString(_Idx: Int64; _Len: integer): string;
47+ function GetLength: Int64;
48+ end;
49+
50+//type
51+// TTextBuffer = class
52+// private
53+// function GetChar(_Idx: Int64): char;
54+// function GetLength: Int64;
55+// public
56+// constructor Create(const _fn: string);
57+// destructor Destroy;
58+// end;
59+
60+type
61+ TStringBuffer = class(TInterfacedObject, ITextBuffer)
62+ private
63+ FText: string;
64+ function GetChar(_Idx: Int64): Char;
65+ function GetString(_Idx: Int64; _Len: integer): string;
66+ function GetLength: Int64;
67+ public
68+ constructor Create(const _Text: string);
69+ end;
70+
71+{ TStringBuffer }
72+
73+constructor TStringBuffer.Create(const _Text: string);
74+begin
75+ inherited Create;
76+ FText := _Text;
77+end;
78+
79+function TStringBuffer.GetChar(_Idx: Int64): Char;
80+begin
81+ Result := FText[_Idx];
82+end;
83+
84+function TStringBuffer.GetLength: Int64;
85+begin
86+ Result := Length(FText);
87+end;
88+
89+function TStringBuffer.GetString(_Idx: Int64; _Len: integer): string;
90+begin
91+ Result := Copy(FText, _Idx, _Len);
92+end;
93+
94+type
95+ TBMSearch = class
96+ private
97+ FSkip: array of integer;
98+ FPatternLen: integer;
99+ FPattern: string;
100+ public
101+ constructor Create(const _Pattern: string);
102+ function Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
103+ end;
104+
105+{ TBMSearch }
106+
107+constructor TBMSearch.Create(const _Pattern: string);
108+var
109+ i: integer;
110+begin
111+ FPattern := _Pattern;
112+ FPatternLen := Length(_Pattern);
113+ if FPatternLen = 0 then
114+ Exit;
115+
116+ SetLength(FSkip, integer(High(Char)) + 1);
117+ for i := Low(FSkip) to High(FSkip) do
118+ FSkip[i] := FPatternLen;
119+ for i := 1 to FPatternLen - 1 do
120+ FSkip[integer(_Pattern[i])] := FPatternLen - i;
121+end;
122+
123+function TBMSearch.Find(_Text: ITextBuffer; var _Offset: Int64): Boolean;
124+var
125+ i: Int64;
126+ TextLen: Int64;
127+ TextIdx: Int64;
128+ PatternIdx: integer;
129+ s: string;
130+begin
131+ Result := False;
132+ if FPatternLen = 0 then
133+ Exit;
134+
135+ i := FPatternLen + (_Offset);
136+ TextLen := _Text.GetLength;
137+ while (not Result) and (i <= TextLen) do begin
138+ TextIdx := i;
139+ PatternIdx := FPatternLen;
140+ while (PatternIdx >= 1) do begin
141+ if _Text.GetChar(TextIdx) = FPattern[PatternIdx] then begin
142+ PatternIdx := PatternIdx - 1;
143+ TextIdx := TextIdx - 1;
144+ end else
145+ PatternIdx := -1;
146+ if PatternIdx = 0 then begin
147+ _Offset := TextIdx;
148+ s := _Text.GetString(_Offset, FPatternLen);
149+ Result := True;
150+ Exit;
151+ end;
152+ i := i + FSkip[integer(_Text.GetChar(i))];
153+ end;
154+ end;
155+end;
156+
157+var
158+ frm: Tf_BMSearchTest;
159+
160+{ Tf_BMSearchTest }
161+
162+class procedure Tf_BMSearchTest.Execute(_Owner: TWinControl; const _Pattern: string;
163+ _Callback: TOnSearchEvent);
164+begin
165+ if not Assigned(frm) then begin
166+ frm := Tf_BMSearchTest.Create(_Owner);
167+ TForm_CenterOn(frm, _Owner);
168+ end;
169+ frm.SetData(_Pattern, _Callback);
170+ frm.Show;
171+end;
172+
173+constructor Tf_BMSearchTest.Create(_Owner: TComponent);
174+begin
175+ inherited;
176+
177+ TranslateComponent(Self);
178+
179+ m_Text.SelStart := 0;
180+ m_Text.SelLength := 0;
181+end;
182+
183+procedure Tf_BMSearchTest.SetData(const _Pattern: string; _Callback: TOnSearchEvent);
184+begin
185+ ed_Pattern.Text := _Pattern;
186+ FCallback := _Callback;
187+end;
188+
189+procedure Tf_BMSearchTest.b_FindClick(Sender: TObject);
190+var
191+ Pattern: string;
192+ Search: TBMSearch;
193+ Offset: Int64;
194+ Text: ITextBuffer;
195+begin
196+ Pattern := ed_Pattern.Text;
197+ Search := TBMSearch.Create(Pattern);
198+ try
199+ Offset := m_Text.SelStart + m_Text.SelLength + 1;
200+ Text := TStringBuffer.Create(m_Text.Lines.Text);
201+ if Search.Find(Text, Offset) then begin
202+ m_Text.SelStart := Offset;
203+ m_Text.SelLength := Length(Pattern);
204+ end;
205+ finally
206+ FreeAndNil(Search);
207+ end;
208+ m_Text.SetFocus;
209+ Exit;
210+
211+ FCallback(Self, ed_Pattern.Text);
212+end;
213+
214+end.
--- trunk/src/w_LargeTextViewer.pas (revision 271)
+++ trunk/src/w_LargeTextViewer.pas (revision 272)
@@ -92,7 +92,7 @@
9292 ClipBrd,
9393 u_dzClassUtils,
9494 w_GotoLine,
95- w_Search;
95+ w_BMSearchTest;
9696
9797 { TIndexerThread }
9898
@@ -166,7 +166,7 @@
166166
167167 procedure Tf_LargeTextViewer.act_LineFindExecute(Sender: TObject);
168168 begin
169- Tf_Search.Execute(Self, 'while', OnFind);
169+ Tf_BMSearchTest.Execute(Self, 'while', OnFind);
170170 end;
171171
172172 procedure Tf_LargeTextViewer.OnFind(_Sender: TObject; const _Pattern: string);
Show on old repository browser