Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/MojuUtils.pas

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


Revision 1.21 - (hide annotations) (download) (as text)
Wed Feb 1 15:23:49 2006 UTC (18 years, 2 months ago) by h677
Branch: MAIN
CVS Tags: v1_52_0_646, v1_52_0_644, v1_52_0_647, v1_52_0_648, v1_52_0_645
Changes since 1.20: +16 -1 lines
File MIME type: text/x-pascal
ノートン先生の誤反応対策で「お気に入り」「履歴」「送信ログ」のスレッドタイトルの
[&]["]をそれぞれ[&]["]に置換するように変更

1 h677 1.1 unit MojuUtils;
2 h677 1.3 //******************************************************************************
3 h677 1.5 // ??絖???臀???∽? CustomStringReplace
4 h677 1.3 // 篏帥???鴻????
5     //??CustomStringReplace(
6     //?? ??????絖???鐚?String???????StringList),
7     //?? 罎?膣∽??絖???鐚?String),
8     // 臀????絖???鐚?String),
9     // 紊ф??絖?絨??絖?鐚?Boolean)True:?阪?ャ????????false or ?????阪?ャ????
10     //
11     // Delphi-ML???篋?69334????c???????潟?若????筝吾?????????障??????
12     //******************************************************************************
13 h677 1.1
14     interface
15    
16     uses
17 h677 1.20 Windows, Classes, SysUtils;
18 h677 1.2
19 h677 1.5 function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
20     function AnsiStrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
21 h677 1.20 function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): String;
22     function IgnoCaseReplaceString(const S: String; const OldPattern:String; const NewPattern: string): String;
23 h677 1.5
24 h677 1.18 function CustomStringReplace(const S: String; const OldPattern: String; const NewPattern: string; IgnoreCase : Boolean = False): String; overload;
25     procedure CustomStringReplace(var S : TStringList;const OldPattern: String;const NewPattern: string; IgnoreCase : Boolean = False); overload;
26 h677 1.1
27 h677 1.5 function ZenToHan(const s: string): string;
28 h677 1.20 function VaguePos(const Substr: String; const S: string): Integer;
29 h677 1.1
30 h677 1.11 function ReplaseNoValidateChar( inVal : String): String;
31     function IsNoValidID( inID :String): Boolean;
32     //<font>?帥?違?????????ゃ????
33 h677 1.20 function DeleteFontTag( inSource : string) : string;
34 h677 1.13 function RemoveToken(var s: string;const delimiter: string): string;
35 h677 1.21 // ?≦???(& -> &amp; " -> &auot; ?????????)
36     function Sanitize(const s: String): String;
37     // ?≦???茹i??&amp; -> & &auot; -> " ?????????)
38     function UnSanitize(const s: String): String;
39 h677 1.11
40 h677 1.1 implementation
41 h677 1.5 // ???ゃ?潟?帥?種??≪?祉?潟??????????蕭???????/span>
42 h677 1.2 function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
43     asm
44 h677 1.11 PUSH EBX
45 h677 1.5 PUSH ESI
46 h677 1.11 PUSH EDI
47 h677 1.2
48 h677 1.11 MOV ESI,ECX { Point ESI to substr }
49     MOV EDI,EAX { Point EDI to s }
50 h677 1.2
51 h677 1.13 MOV ECX,EDX { ECX = search length }
52 h677 1.2 SUB ECX,EAX
53    
54     MOV EDX,SubstrEnd
55     SUB EDX,ESI
56    
57     DEC EDX { EDX = Length(substr) - 1 }
58     JS @@fail { < 0 ? return 0 }
59     MOV AL,[ESI] { AL = first char of substr }
60     INC ESI { Point ESI to 2'nd char of substr }
61    
62     SUB ECX,EDX { #positions in s to look at }
63     { = Length(s) - Length(substr) + 1 }
64     JLE @@fail
65     @@loop:
66     REPNE SCASB
67     JNE @@fail
68     MOV EBX,ECX { save outer loop counter }
69     PUSH ESI { save outer loop substr pointer }
70     PUSH EDI { save outer loop s pointer }
71    
72     MOV ECX,EDX
73     REPE CMPSB
74     POP EDI { restore outer loop s pointer }
75     POP ESI { restore outer loop substr pointer }
76     JE @@found
77     MOV ECX,EBX { restore outer loop counter }
78     JMP @@loop
79    
80     @@fail:
81     XOR EAX,EAX
82     JMP @@exit
83    
84     @@found:
85     MOV EAX,EDI { EDI points of char after match }
86     DEC EAX
87     @@exit:
88     POP EDI
89     POP ESI
90     POP EBX
91     end;
92 h677 1.5 //??AnsiPos???????
93 h677 1.2 function AnsiStrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
94     var
95 h677 1.3 L2: Cardinal;
96     ByteType : TMbcsByteType;
97 h677 1.2 begin
98 h677 1.3 Result := nil;
99     if (StrStart = nil) or (StrStart^ = #0) or
100     (SubstrStart = nil) or (SubstrStart^ = #0) then Exit;
101    
102     L2 := SubstrEnd - SubstrStart;
103     Result := StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd);
104    
105     while (Result <> nil) and (StrEnd - Result >= L2) do begin
106     ByteType := StrByteType(StrStart, Integer(Result-StrStart));
107     if (ByteType <> mbTrailByte) and
108     (CompareString(LOCALE_USER_DEFAULT, SORT_STRINGSORT, Result, L2, SubstrStart, L2) = 2)
109     then Exit;
110     if (ByteType = mbLeadByte) then Inc(Result);
111     Inc(Result);
112     Result := StrPosEx(Result, StrEnd, SubStrStart, SubStrEnd);
113     end;
114     Result := nil;
115 h677 1.2 end;
116    
117 h677 1.5 //蕭?????絖???臀???∽?逸?紊ф??絖?絨??絖??????????∴???????鐚?
118 h677 1.20 function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): String;
119 h677 1.2 var
120 h677 1.20 ReplaceCount: Integer;
121     DestIndex: Integer;
122     i, l: Integer;
123     p, e, ps, pe: PChar;
124     Count: Integer;
125     olen: Integer;
126 h677 1.2 begin
127 h677 1.18 Result := S;
128 h677 1.20 olen := Length(OldPattern);
129     if olen = 0 then Exit;
130 h677 1.11 p := PChar(S);
131     e := p + Length(S);
132     ps := PChar(OldPattern);
133 h677 1.20 pe := ps + olen;
134 h677 1.11 ReplaceCount := 0;
135     while p < e do begin
136     p := AnsiStrPosEx(p, e, ps, pe);
137     if p = nil then Break;
138     Inc(ReplaceCount);
139 h677 1.20 Inc(p, olen);
140 h677 1.11 end;
141     if ReplaceCount = 0 then Exit;
142     SetString(Result, nil, Length(S) +
143 h677 1.20 (Length(NewPattern) - olen) * ReplaceCount);
144 h677 1.18 p := PChar(S);
145     DestIndex := 1;
146     l := Length( NewPattern );
147     for i := 0 to ReplaceCount - 1 do begin
148     Count := AnsiStrPosEx(p, e, ps, pe) - p;
149     Move(p^, Result[DestIndex], Count);
150     Inc(p, Count);//p := pp;
151     Inc(DestIndex, Count);
152     Move(NewPattern[1], Result[DestIndex], l);
153 h677 1.20 Inc(p, olen);
154 h677 1.18 Inc(DestIndex, l);
155 h677 1.20 end;
156     Move(p^, Result[DestIndex], e - p);
157 h677 1.1 end;
158 h677 1.5 //蕭?????絖???臀???∽?逸?紊ф??絖?絨??絖??????????∴?????鐚?
159 h677 1.20 function IgnoCaseReplaceString(const S: String;const OldPattern:String;const NewPattern: string): String;
160 h677 1.3 var
161 h677 1.5 ReplaceCount: Integer;
162     DestIndex: Integer;
163     i, l: Integer;
164     p, e{, ps, pe}: PChar;
165     p2, e2, ps2, pe2: PChar;
166     Count: Integer;
167     bufferS : String;
168     bufferOldPattern : String;
169 h677 1.3 begin
170 h677 1.5 Result := S;
171     bufferS := AnsiLowerCase(S);
172     bufferOldPattern := AnsiLowerCase(OldPattern);
173    
174     if OldPattern = '' then Exit;
175     p := PChar(S);
176     p2 := PChar(bufferS);
177     e := p + Length(S);
178     e2 := p2 + Length(bufferS);
179     //ps := PChar(OldPattern);
180     ps2 := PChar(bufferOldPattern);
181     //pe := ps + Length(OldPattern);
182     pe2 := ps2 + Length(bufferOldPattern);
183    
184     ReplaceCount := 0;
185     while p2 < e2 do begin
186     p2 := AnsiStrPosEx(p2, e2, ps2, pe2);
187     if p2 = nil then Break;
188     Inc(ReplaceCount);
189     Inc(p2, Length(bufferOldPattern));
190     end;
191     if ReplaceCount = 0 then Exit;
192     SetString(Result, nil, Length(bufferS) +
193     (Length(NewPattern) - Length(bufferOldPattern)) * ReplaceCount);
194     p2 := PChar(bufferS);
195     DestIndex := 1;
196     l := Length( NewPattern );
197     for i := 0 to ReplaceCount - 1 do begin
198     Count := AnsiStrPosEx(p2, e2, ps2, pe2) - p2;
199     Move(p^, Result[DestIndex], Count);
200     Inc(p, Count);//p := pp;
201     Inc(p2, Count);//p := pp;
202     Inc(DestIndex, Count);
203     Move(NewPattern[1], Result[DestIndex], l);
204     Inc(p, Length(OldPattern));
205     Inc(p2, Length(OldPattern));
206     Inc(DestIndex, l);
207     end;
208     Move(p^, Result[DestIndex], e - p);
209 h677 1.3 end;
210 h677 1.5 //蕭?????絖???臀???∽?逸?羆?????鐚?鐚?
211 h677 1.3 function CustomStringReplace(
212 h677 1.18 const S :String;
213     const OldPattern: String;
214 h677 1.5 const NewPattern: string;
215     IgnoreCase : Boolean
216 h677 1.3 ): String;
217     begin
218 h677 1.5 if not IgnoreCase then begin
219     Result := ReplaceString(S,OldPattern,NewPattern);
220     end else begin
221     Result := IgnoCaseReplaceString(S,OldPattern,NewPattern);
222     end;
223 h677 1.3 end;
224    
225 h677 1.5 //蕭?????絖???臀???∽?逸?羆?????鐚?鐚?
226 h677 1.3 procedure CustomStringReplace(
227     var S : TStringList;
228 h677 1.18 const OldPattern: String;
229 h677 1.5 const NewPattern: string;
230     IgnoreCase : Boolean
231 h677 1.3 );
232     var
233 h677 1.5 i : Integer;
234 h677 1.3 begin
235 h677 1.5 S.BeginUpdate;
236     if not IgnoreCase then begin
237     for i := 0 to S.Count - 1 do begin
238     S.Strings[i] := ReplaceString(S.Strings[i], OldPattern,NewPattern);
239     end;
240     end else begin
241     for i := 0 to S.Count - 1 do begin
242     S.Strings[i] := IgnoCaseReplaceString(S.Strings[i], OldPattern,NewPattern);
243     end;
244     end;
245     S.EndUpdate;
246 h677 1.3 end;
247    
248 h677 1.5 (*************************************************************************
249     * ???????茹?
250     * from HotZonu
251     *************************************************************************)
252     function ZenToHan(const s: string): string;
253     var
254 yoffy 1.8 ChrLen : Integer;
255 h677 1.5 begin
256 h677 1.15 SetLength(Result, Length(s));
257 yoffy 1.8 ChrLen := Windows.LCMapString(
258 h677 1.5 GetUserDefaultLCID(),
259     // LCMAP_HALFWIDTH,
260     LCMAP_HALFWIDTH or LCMAP_KATAKANA or LCMAP_LOWERCASE,
261     PChar(s),
262 yoffy 1.8 Length(s),
263 h677 1.15 PChar(Result),
264     Length(Result)
265 h677 1.5 );
266 h677 1.15 SetLength(Result, ChrLen);
267 h677 1.3 end;
268    
269 h677 1.5 (*************************************************************************
270     * ?????茹??蚊?????????????????阪?ャ??????????Pos
271     *************************************************************************)
272 h677 1.20 function VaguePos(const Substr:String; const S: string): Integer;
273 h677 1.5 begin
274     Result := AnsiPos(ZenToHan(Substr), ZenToHan(S));
275     end;
276 h677 1.9 (*************************************************************************
277 h677 1.12 * FAT/NTFS?????<?ゃ??????┗??????????絖?鐚?\,/,:,.,;,*,>,<,|鐚????????舟??????
278 h677 1.9 *************************************************************************)
279     function ReplaseNoValidateChar( inVal : String): String;
280     begin
281     Result := CustomStringReplace(inVal, '\', '鐃?#39;);
282 h677 1.12 Result := CustomStringReplace(Result, '/', '鐚?39;);
283     Result := CustomStringReplace(Result, ':', '鐚?');
284     Result := CustomStringReplace(Result, '.', '鐚?#39;);
285     Result := CustomStringReplace(Result, ';', '鐚?');
286 h677 1.9 Result := CustomStringReplace(Result, '*', '鐚?');
287 h677 1.11 Result := CustomStringReplace(Result, '>', '鐚?');
288     Result := CustomStringReplace(Result, '<', '鐚?');
289     Result := CustomStringReplace(Result, '|', '鐔?');
290 h677 1.9 end;
291 h677 1.10 (*************************************************************************
292     * ?≦?鴻??D???????с??????≦?剛?鐚?ID:??? , ID:???0)
293     *************************************************************************)
294     function IsNoValidID( inID :String): Boolean;
295     begin
296 h677 1.11 inID := Trim(inID);
297     if inID = '' then Result := True
298     else begin
299     inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) );
300     inID := CustomStringReplace(inID, '?', '');
301     if (inID = '') or (inID = '0') then Result := True
302     else Result := False;
303     end;
304     end;
305    
306     // *************************************************************************
307     // HTML筝???lt;font>?帥?違?????ゃ????
308     // *************************************************************************
309     function DeleteFontTag(
310     inSource : string //?帥?違?????ゃ??????絖???
311     ) : string; //?帥?医???よ?????絖???
312     var
313     pos : Integer;
314     begin
315     Result := '';
316    
317     //</font>??????/span>
318     inSource := CustomStringReplace( inSource, '</font>', '', True);
319     //<font ?????????絖??????????
320     inSource := CustomStringReplace( inSource, '<font', '<font', True);
321     //<font ?? ?????ゃ????
322     pos := AnsiPos('<font', inSource);
323     while (pos > 0) do begin
324     Result := Result + Copy(inSource, 1, pos - 1);
325     Delete(inSource, 1, pos);
326     //?帥?違????????'>'?障?с??????/span>
327     pos := AnsiPos('>', inSource);
328     Delete(inSource, 1, pos);
329     pos := AnsiPos('<font', inSource);
330     end;
331    
332     Result := Result + inSource;
333    
334    
335 h677 1.10 end;
336 h677 1.11 // *************************************************************************
337    
338 h677 1.13
339     (*************************************************************************
340     *
341     *?????????泣?ゃ??????????????/span>
342     *************************************************************************)
343     function RemoveToken(var s: string;const delimiter: string): string;
344     var
345     p: Integer;
346 h677 1.14 pos : PChar;
347     pds, pde : PChar;
348     pss, pse : PChar;
349 h677 1.13 begin
350 h677 1.14 pss := PChar(s);
351     pse := pss + Length(s);
352     pds := PChar(delimiter);
353     pde := pds + Length(delimiter);
354    
355     pos := AnsiStrPosEx(pss, pse, pds, pde);
356     if pos <> nil then begin
357     p := pos - pss;
358     SetString(Result, pss, p);
359     Delete(s, 1, p + Length(delimiter));
360     end else begin
361     Result := s;
362     s := '';
363     end;
364 h677 1.13 end;
365 h677 1.21 //! ?≦???(& -> &amp; " -> &auot; ?????????)
366     function Sanitize(const s: String): String;
367     begin
368     Result := CustomStringReplace(s, '&', '&amp;');
369     Result := CustomStringReplace(Result, '"', '&quot;');
370     end;
371     //! ?≦???茹i??&amp; -> & &auot; -> " ?????????)
372     function UnSanitize(const s: String): String;
373     begin
374     Result := CustomStringReplace(s, '&quot;', '"');
375     Result := CustomStringReplace(Result, '&amp;', '&');
376     end;
377 h677 1.10
378 h677 1.1 end.

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