Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/AbonUnit.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.8 - (hide annotations) (download) (as text)
Mon Aug 18 08:13:38 2003 UTC (20 years, 8 months ago) by h677
Branch: MAIN
Changes since 1.7: +1 -37 lines
File MIME type: text/x-pascal
連続する同英字をNGにする機能の有効性が低いので削除した

1 h677 1.1 unit AbonUnit;
2    
3     interface
4     uses
5 h677 1.2 Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
6 h677 1.1
7     type
8     TAbon = class(TObject)
9     private
10     { Private 絎h? }
11     Froot : String;
12     FNGwordpath : String;
13 h677 1.2 Ftokens : array of array of string;
14 h677 1.1 FAbonString : String;
15 h677 1.2 FCutoffNum : Integer; //?????遺札筝??g??????????怨???NG???若????????
16 h677 1.3 FDeleterlo : Boolean; //&rlo;????????
17     FReplaceul :Boolean ; //<ul>?帥?違??<br>?帥?違??舟????????
18     FReverse : Boolean ; //NG???若???с?????若?????????????荵≪????????
19     FAbonPopupRes : Boolean; //???鴻???????≪?????????????若?若????????
20     FCreateNGwordFile : Boolean; //??絎???????path??G???若??txt???<???c??????????????????????????
21 h677 1.1 procedure SetTokens(index: integer ; argline:String);
22    
23     public
24     { Public 絎h? }
25     constructor Create; // ?潟?潟?鴻????????/span>
26     destructor Destroy; override; // ???鴻????????/span>
27 h677 1.3 property Deleterlo: Boolean read FDeleterlo write FDeleterlo default false;
28     property Replaceul: Boolean read FReplaceul write FReplaceul default false;
29     property Reverse: Boolean read FReverse write FReverse default false;
30 h677 1.4 property CreateNGwordFile: Boolean read FCreateNGwordFile write FCreateNGwordFile;
31 h677 1.3 property AbonString : String read FAbonString write FAbonString;
32     property AbonPopupRes : Boolean read FAbonPopupRes write FAbonPopupRes default false;
33 h677 1.1 procedure Setroot(root :String);
34     function Getroot() : String;
35     procedure SetNGwordpath(path :String);
36     function GetNGwordpath() : String;
37     function LoadFromNGwordFile(path :String) : Boolean;
38     function ReLoadFromNGwordFile() : Boolean;
39 yoffy 1.6 procedure LoadFromStringList( bufstl : TStringList );
40 h677 1.3 function CheckAbonPopupRes(line : String) :Boolean;
41 h677 1.1 function FindNGwords(line : String) : Boolean; //1???ゃ?潟???ょ????
42 h677 1.3 function Cutoff(line : String) : Boolean; //CutOff?や札筝??????????掩?違??筝????с??????true
43     //???若????????
44 h677 1.7 procedure Execute(var ThreadStrings : TStringList); overload;
45     procedure Execute(var ThreadStrings : TStringList; NGwords : TStringList); overload;
46     procedure Execute(var ThreadStrings : TStringList; NGwords : TStrings); overload;
47 h677 1.1 //--
48     function ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; overload;//DAT???<?ゃ?????眼????????
49     function ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT???<?ゃ?????眼????????
50     function ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT???<?ゃ?????眼????????
51     function ReverseExecuteFile(datfilepath : String) : Boolean; overload; //DAT???<?ゃ?????眼????????
52     function ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; overload; //DAT???<?ゃ?????眼????????
53     function ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; overload; //DAT???<?ゃ?????眼????????
54     //--
55     procedure EditNGwords(); //NGword.txt???????
56     function ShowAllTokens() : String; //???????亥??/span>
57     end;
58     var
59     Abon1 :TAbon;
60    
61     implementation
62    
63     constructor TAbon.Create;
64     begin
65     // ??????
66     FAbonString := '&nbsp;<>&nbsp;<>&nbsp;<>&nbsp;&nbsp;<><>';
67 h677 1.4 FCreateNGwordFile := true;
68 h677 1.1 end;
69    
70     destructor TAbon.Destroy;
71     begin
72     inherited;
73     end;
74    
75    
76    
77     //root??xe??????????????
78     procedure TAbon.Setroot(root :String);
79     begin
80     Froot := root;
81     end;
82     function TAbon.Getroot() : String;
83     begin
84     Result := Froot;
85     end;
86     //NGwordpath??Gword.txt??????????/span>
87     procedure TAbon.SetNGwordpath(path :String);
88     begin
89     FNGwordpath := path;
90     LoadFromNGwordFile(FNGwordpath);
91     end;
92     function TAbon.GetNGwordpath() : String;
93     begin
94     Result := FNGwordpath;
95     end;
96     //NGword???<?ゃ??????粋昭??/span>
97     function TAbon.LoadFromNGwordFile(path :String) : boolean;
98     var
99     bufstl : TStringList;
100     i : integer;
101     begin
102     if AnsiPos(':\',path) <> 2 then begin //?????ゃ???????????????鴻???<??????/span>
103     if Getroot() = '' then begin
104     Result := false; //root???鴻??荐????????????????false
105     Exit;
106     end else begin
107     if (Froot[Length(Froot)] = '\') and (path[1] = '\') then begin //????????????/span>
108     Delete(path,1,1);
109     end;
110     Insert( Getroot(), path , 1);//root???鴻???水??/span>
111     end;
112     end;
113     bufstl := TStringList.Create;
114     try
115     bufstl.LoadFromFile(path);
116 yoffy 1.6 LoadFromStringList( bufstl );
117    
118     except
119     if CreateNGwordFile = true then begin
120     bufstl.SaveToFile(path);
121     end;
122     bufstl.Free;
123     Result := false;
124     Exit;
125     end;
126     bufstl.Free;
127     Result := true;
128     end;
129     //NGword???鴻??茯??粋昭??/span>
130     procedure TAbon.LoadFromStringList( bufstl : TStringList );
131     var
132     i : integer;
133     begin
134     try
135 h677 1.3 for i := bufstl.Count -1 downto 0 do begin
136     if bufstl.Strings[i] = '' then begin
137     bufstl.Delete(i);
138     end;
139     end;
140 h677 1.2 SetLength(Ftokens,bufstl.Count);
141 h677 1.1 for i := 0 to bufstl.Count -1 do begin
142     SetTokens(i , bufstl.Strings[i]);
143     end;
144    
145     except
146     Exit;
147     end;
148     end;
149     //NGwordpath???≪??┃絎??????????????????????若?????∽??/span>
150     function TAbon.ReLoadFromNGwordFile() : boolean;
151     begin
152     if GetNGwordpath() ='' then begin
153     Result := false;
154     end else begin
155     Result := LoadFromNGwordFile( GetNGwordpath() );
156     end;
157     end;
158    
159     //筝?茵???賢?????若???潟?????????????祉????
160     procedure TAbon.SetTokens(index: integer ; argline : String);
161     var
162     ret : Integer;
163     bufstl : TStringList;
164     i : Integer;
165     begin
166     bufstl := TStringList.Create;
167     bufstl.Delimiter := #9; //?阪????絖??????帥??????┃絎?
168     bufstl.DelimitedText := argline;
169     ret := bufstl.Count;
170 h677 1.2 SetLength(Ftokens[index],ret);
171 h677 1.1 for i := 0 to bufstl.Count - 1 do begin
172 h677 1.2 Ftokens[index][i] := bufstl.Strings[i];
173 h677 1.1 end;
174     bufstl.Free;
175    
176     end;
177 h677 1.8 //Debug???<??????G???若?????障??????????
178 h677 1.1 function TAbon.ShowAllTokens() : String;
179     var
180     i : Integer;
181     j : Integer;
182     ret : String;
183     begin
184 h677 1.2 for i := 0 to High(Ftokens) do begin
185     for j := 0 to High(Ftokens[i]) do begin
186     ret := ret + Ftokens[i][j];
187 h677 1.1 end;
188     end;
189     Result := ret;
190    
191    
192    
193     end;
194    
195     //****************************************************************************//
196     //NG???若???????障????????true??菴?????
197     function TAbon.FindNGwords(line : String) : Boolean;
198     var
199     i : Integer;
200     j : Integer;
201     hit : Boolean;
202     begin
203     hit := false;
204     if AnsiPos(FAbonString,line) <> 1 then begin
205 h677 1.2 for i := 0 to High(Ftokens) do begin
206 h677 1.1 hit := true;
207 h677 1.2 for j := 0 to High(Ftokens[i]) do begin
208     if AnsiPos(Ftokens[i][j],line) = 0 then begin
209 h677 1.1 hit := false;
210     break;
211     end;
212     end;
213     if hit = true then begin
214     break;
215     end;
216     end;
217     end;
218     Result := hit;
219    
220     end;
221 h677 1.3 //CutOff?や札筝??????????掩?違??筝????с??????true
222     function TAbon.Cutoff(line : String) : Boolean;
223 h677 1.2 var
224     i : Integer;
225     sheed : AnsiChar;
226     buf : String;
227 h677 1.3 ret : Bool;
228 h677 1.2 begin
229 h677 1.3 ret := false;
230 h677 1.2 if FCutoffNum <> 0 then begin
231     for i := 65 to 90 do begin
232     sheed := Chr(i);
233     buf := DupeString(sheed, FCutoffNum);
234     if AnsiContainsText(line, buf) = true then begin
235 h677 1.3 ret := true;
236 h677 1.2 break;
237     end;
238     end;
239     end;
240     Result := ret;
241     end;
242 h677 1.1 //??鮎?????若???ゃ??rue??????NG???若??????????????????菴?????
243 h677 1.7 procedure TAbon.Execute(var ThreadStrings : TStringList);
244 h677 1.1 var
245     i : Integer;
246 h677 1.5 j : Integer;
247 h677 1.2 bufline : String;
248     begin
249 h677 1.7 //FRetStrings.Clear;
250 h677 1.1
251 h677 1.7 for i:=0 to ThreadStrings.Count - 1 do begin
252     if FindNGwords(ThreadStrings.Strings[i]) <> Reverse then begin
253     ThreadStrings.Strings[i] := FAbonString;
254     end else begin
255     bufline := ThreadStrings.Strings[i];
256     if Deleterlo = true then begin
257     bufline := AnsiReplaceText( bufline,'&rlo;','' );
258 h677 1.1 end;
259 h677 1.7 if Replaceul = true then begin
260     bufline := AnsiReplaceText( bufline,'<ul>','<br>' );
261     bufline := AnsiReplaceText( bufline,'</ul>','<br>' );
262 h677 1.1 end;
263 h677 1.7 ThreadStrings.Strings[i] := bufline;
264 h677 1.1 end;
265 h677 1.7 end;
266 h677 1.1
267     end;
268 h677 1.7 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStringList);
269 h677 1.1 var
270     i : Integer;
271     begin
272 h677 1.2 SetLength(Ftokens,NGwords.Count);
273 h677 1.1 for i := 0 to NGwords.Count -1 do begin
274     SetTokens(i , NGwords.Strings[i]);
275     end;
276 h677 1.7 Execute(ThreadStrings);
277 h677 1.1
278     end;
279 h677 1.7 procedure TAbon.Execute(var ThreadStrings : TStringList; NGwords : TStrings);
280 h677 1.1 var
281     i : Integer;
282     buf : TStringList;
283     begin
284     buf := TStringList.Create;
285     buf.AddStrings(NGwords);
286 h677 1.2 SetLength(Ftokens,buf.Count);
287 h677 1.1 for i := 0 to buf.Count -1 do begin
288     SetTokens(i , buf.Strings[i]);
289     end;
290 h677 1.7 Execute(ThreadStrings);
291 h677 1.1 buf.Free;
292     end;
293    
294    
295     //****************************************************************************//
296     //DAT???眼????????絅眼??===========================================================
297     //NG???若???????????鴻???????????若?若?????水??/span>
298     function TAbon.ExecuteFile(datfilepath : String; NGwordpath : String) : Boolean; //DAT???<?ゃ?????眼????????
299     var
300     datstl : TStringList;
301     ret : Boolean;
302     i : Integer;
303     begin
304     datstl := TStringList.Create;
305     ret := true;
306     try
307     try
308     datstl.LoadFromFile(datfilepath);
309     for i := 0 to datstl.Count -1 do begin
310     if FindNGwords(datstl.Strings[i]) = true then begin
311     datstl.Strings[i] := FAbonString + datstl.Strings[i]
312     end;
313     end;
314    
315     datstl.SaveToFile(datfilepath);
316     except
317     ret := false;
318     end;
319     finally
320     datstl.Free;
321     end;
322     Result := ret;
323    
324     end;
325     //??絎??????????合?????????????若?若???水??/span>
326     function TAbon.ExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT???<?ゃ?????眼????????
327     var
328     datstl : TStringList;
329     ret : Boolean;
330     begin
331     ret := true;
332     datstl := TStringList.Create;
333     try
334     try
335     datstl.LoadFromFile(datfilepath);
336     if (resnum > 0) and (resnum <= datstl.Count) then begin
337     if AnsiPos(FAbonString, datstl.Strings[resnum-1]) <> 1 then begin
338     datstl.Strings[resnum-1] := FAbonString + datstl.Strings[resnum-1];
339     end;
340     end;
341     datstl.SaveToFile(datfilepath);
342     except
343     ret := false;
344     end;
345     finally
346     datstl.Free;
347     end;
348     Result := ret;
349     end;
350     //firstres????count???????鴻???????????若?若???水??/span>
351     function TAbon.ExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean; //DAT???<?ゃ?????眼????????
352     var
353     datstl : TStringList;
354     i : Integer;
355     endnum : Integer; //腟?????????合??/span>
356     ret : Boolean;
357     begin
358     ret := true;
359     datstl := TStringList.Create;
360     try
361     try
362     datstl.LoadFromFile(datfilepath);
363     if (firstres > 0) and (firstres <= datstl.Count) then begin
364     if firstres + count -1 > datstl.Count then begin
365     endnum := datstl.Count;
366     end else if count <= 0 then begin
367     endnum := firstres + 1;
368     end else begin
369     endnum := firstres + count -1;
370     end;
371    
372     for i := firstres to endnum do begin
373     if AnsiPos(FAbonString, datstl.Strings[i-1]) <> 1 then begin
374     datstl.Strings[i-1] := FAbonString + datstl.Strings[i-1];
375     end;
376     end;
377     end;
378     datstl.SaveToFile(datfilepath);
379     except
380     ret := false;
381     end;
382     finally
383     datstl.Free;
384     end;
385     Result := ret;
386     end;
387     //DAT???眼????????絅眼??==========?????障??========================================
388    
389     //?????祉??絅眼??==================================================================
390     function TAbon.ReverseExecuteFile(datfilepath : String) : Boolean; //DAT???<?ゃ?????眼????????
391     var
392     datstl : TStringList;
393     i : Integer;
394     buf : String;
395     ret : Boolean;
396     begin
397     ret := true;
398     datstl := TStringList.Create;
399     try
400     try
401     datstl.LoadFromFile(datfilepath);
402     for i:=0 to datstl.Count -1 do begin
403     if AnsiPos(FAbonString, datstl.Strings[i]) = 1 then begin
404     buf := datstl.Strings[i];
405     Delete(buf,1,Length(FAbonString));
406     datstl.Strings[i] := buf;
407     end;
408     end;
409     datstl.SaveToFile(datfilepath);
410     except
411     ret := false;
412     end;
413     finally
414     datstl.Free;
415     end;
416     Result := ret;
417    
418     end;
419     function TAbon.ReverseExecuteFile(datfilepath : String; resnum : Integer) : Boolean; //DAT???<?ゃ?????眼????????
420     var
421     datstl : TStringList;
422     buf : String;
423     ret : Boolean;
424     begin
425     ret := true;
426     datstl := TStringList.Create;
427     try
428     try
429     datstl.LoadFromFile(datfilepath);
430     if (resnum > 0) and (resnum <= datstl.Count) then begin
431     if AnsiPos(FAbonString, datstl.Strings[resnum-1]) = 1 then begin
432     buf := datstl.Strings[resnum-1];
433     Delete(buf,1,Length(FAbonString));
434     datstl.Strings[resnum-1] := buf;
435     end;
436     end;
437     datstl.SaveToFile(datfilepath);
438     except
439     ret := false;
440     end;
441     finally
442     datstl.Free;
443     end;
444     Result := ret;
445    
446     end;
447     function TAbon.ReverseExecuteFile(datfilepath : String; firstres : Integer; count : Integer) : Boolean;//DAT???<?ゃ?????眼????????
448     var
449     datstl : TStringList;
450     i : Integer;
451     endnum : Integer; //腟?????????合??/span>
452     buf : String;
453     ret : Boolean;
454     begin
455     ret := true;
456     datstl := TStringList.Create;
457     try
458     try
459     datstl.LoadFromFile(datfilepath);
460     if (firstres > 0) and (firstres <= datstl.Count) then begin
461     if firstres + count -1 > datstl.Count then begin
462     endnum := datstl.Count;
463     end else if count <= 0 then begin
464     endnum := firstres + 1;
465     end else begin
466     endnum := firstres + count -1;
467     end;
468     for i := firstres to endnum do begin
469     if AnsiPos(FAbonString, datstl.Strings[i-1]) = 1 then begin
470     buf := datstl.Strings[i-1];
471     Delete(buf,1,Length(FAbonString));
472     datstl.Strings[i-1] := buf;
473     end;
474     end;
475     end;
476     datstl.SaveToFile(datfilepath);
477     except
478     ret := false;
479     end;
480     finally
481     datstl.Free;
482     end;
483     Result := ret;
484     end;
485     //?????祉??絅眼??=================?????障??========================================
486     //?上???祉??????????????NGword.txt??????span>
487     procedure TAbon.EditNGwords();
488     begin
489     ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
490     end;
491 h677 1.3 function TAbon.CheckAbonPopupRes(line : String) :Boolean;
492     var
493     i : Integer;
494     begin
495     if FCutoffNum = 0 then begin
496     if AbonPopupRes = true then begin
497     Result := FindNGwords(line);
498     end else begin
499     Result := false;
500     end;
501     end else begin
502     if AbonPopupRes = true then begin
503     Result := FindNGwords(line);
504     if Result = false then begin
505     for i := 0 to 2 do begin
506     Delete(line,1,Ansipos('<>',line)+1);
507     end;
508     Delete(line,Ansipos('<>',line),Length(line)-Ansipos('<>',line)+1);
509     Result := Cutoff(line);
510     end;
511     end else begin
512     Result := false;
513     end;
514     end;
515     end;
516 h677 1.1
517    
518     end.
519    

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