Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/AbonUnit.pas

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


Revision 1.2 - (show annotations) (download) (as text)
Tue Aug 12 14:13:53 2003 UTC (20 years, 8 months ago) by h677
Branch: MAIN
Changes since 1.1: +90 -35 lines
File MIME type: text/x-pascal
あぼーんの時にスタイル崩れの原因を取ったりするようなコードにした

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

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