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.1 - (show annotations) (download) (as text)
Tue Aug 12 07:58:32 2003 UTC (20 years, 8 months ago) by h677
Branch: MAIN
File MIME type: text/x-pascal
あぼ〜ん処理クラス

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

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