Develop and Download Open Source Software

Browse CVS Repository

Diff of /gikonavigoeson/gikonavi/MojuUtils.pas

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

revision 1.19 by h677, Wed Dec 7 15:48:16 2005 UTC revision 1.20 by h677, Fri Dec 9 17:06:30 2005 UTC
# Line 14  unit MojuUtils; Line 14  unit MojuUtils;
14  interface  interface
15    
16  uses  uses
17          Windows, Classes, SysUtils, GikoSystem;          Windows, Classes, SysUtils;
18    
19          function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;          function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
20          function AnsiStrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;          function AnsiStrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
21          function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): string;          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;          function IgnoCaseReplaceString(const S: String; const OldPattern:String; const NewPattern: string): String;
23    
24          function CustomStringReplace(const S: String; const OldPattern: String; const  NewPattern: string; IgnoreCase : Boolean = False): String; overload;          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;          procedure CustomStringReplace(var S : TStringList;const OldPattern: String;const  NewPattern: string; IgnoreCase : Boolean = False); overload;
26    
27          function ZenToHan(const s: string): string;          function ZenToHan(const s: string): string;
28          function VaguePos(const Substr, S: string): Integer;          function VaguePos(const Substr: String; const S: string): Integer;
29    
30          function ReplaseNoValidateChar( inVal : String): String;          function ReplaseNoValidateChar( inVal : String): String;
31          function IsNoValidID( inID :String): Boolean;          function IsNoValidID( inID :String): Boolean;
32          //<font>タグを全て削除する          //<font>タグを全て削除する
33          function        DeleteFontTag( inSource : string) : string;          function DeleteFontTag( inSource : string) : string;
         procedure DivideStrLine(Line: string; PRes: PResRec);  
34          function RemoveToken(var s: string;const delimiter: string): string;          function RemoveToken(var s: string;const delimiter: string): string;
35    
36  implementation  implementation
# Line 111  begin Line 110  begin
110      Result := nil;      Result := nil;
111  end;  end;
112    
 {$R-}  
113  //高速文字列置換関数(大文字小文字の違いを無視しない)  //高速文字列置換関数(大文字小文字の違いを無視しない)
114  function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): string;  function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): String;
115  var  var
116      ReplaceCount: Integer;          ReplaceCount: Integer;
117      DestIndex: Integer;          DestIndex: Integer;
118      i, l: Integer;          i, l: Integer;
119      p, e, ps, pe: PChar;          p, e, ps, pe: PChar;
120      Count: Integer;          Count: Integer;
121            olen: Integer;
122  begin  begin
123          Result := S;          Result := S;
124          if OldPattern = '' then Exit;          olen := Length(OldPattern);
125            if olen = 0 then Exit;
126          p := PChar(S);          p := PChar(S);
127          e := p + Length(S);          e := p + Length(S);
128          ps := PChar(OldPattern);          ps := PChar(OldPattern);
129          pe := ps + Length(OldPattern);          pe := ps + olen;
130          ReplaceCount := 0;          ReplaceCount := 0;
131          while p < e do begin          while p < e do begin
132                  p := AnsiStrPosEx(p, e, ps, pe);                  p := AnsiStrPosEx(p, e, ps, pe);
133                  if p = nil then Break;                  if p = nil then Break;
134                  Inc(ReplaceCount);                  Inc(ReplaceCount);
135                  Inc(p, Length(OldPattern));                  Inc(p, olen);
136          end;          end;
137          if ReplaceCount = 0 then Exit;          if ReplaceCount = 0 then Exit;
138          SetString(Result, nil, Length(S) +          SetString(Result, nil, Length(S) +
139          (Length(NewPattern) - Length(OldPattern)) * ReplaceCount);          (Length(NewPattern) - olen) * ReplaceCount);
140          p := PChar(S);          p := PChar(S);
141          DestIndex := 1;          DestIndex := 1;
142          l := Length( NewPattern );          l := Length( NewPattern );
# Line 146  begin Line 146  begin
146                  Inc(p, Count);//p := pp;                  Inc(p, Count);//p := pp;
147                  Inc(DestIndex, Count);                  Inc(DestIndex, Count);
148                  Move(NewPattern[1], Result[DestIndex], l);                  Move(NewPattern[1], Result[DestIndex], l);
149                  Inc(p, Length(OldPattern));                  Inc(p, olen);
150                  Inc(DestIndex, l);                  Inc(DestIndex, l);
151      end;          end;
152      Move(p^, Result[DestIndex], e - p);          Move(p^, Result[DestIndex], e - p);
153  end;  end;
154  //高速文字列置換関数(大文字小文字の違いを無視する)  //高速文字列置換関数(大文字小文字の違いを無視する)
155  function IgnoCaseReplaceString(const S: String;const OldPattern:String;const NewPattern: string): string;  function IgnoCaseReplaceString(const S: String;const OldPattern:String;const NewPattern: string): String;
156  var  var
157          ReplaceCount: Integer;          ReplaceCount: Integer;
158          DestIndex: Integer;          DestIndex: Integer;
# Line 203  begin Line 203  begin
203          end;          end;
204          Move(p^, Result[DestIndex], e - p);          Move(p^, Result[DestIndex], e - p);
205  end;  end;
 {$IFDEF DEBUG}  
 {$R+}  
 {$ENDIF}  
   
206  //高速文字列置換関数(汎用版1)  //高速文字列置換関数(汎用版1)
207  function CustomStringReplace(  function CustomStringReplace(
208          const S :String;          const S :String;
# Line 215  function CustomStringReplace( Line 211  function CustomStringReplace(
211          IgnoreCase : Boolean          IgnoreCase : Boolean
212  ): String;  ): String;
213  begin  begin
         Result := '';  
214          if not IgnoreCase then begin          if not IgnoreCase then begin
215                  Result := ReplaceString(S,OldPattern,NewPattern);                  Result := ReplaceString(S,OldPattern,NewPattern);
216          end else begin          end else begin
# Line 270  end; Line 265  end;
265  (*************************************************************************  (*************************************************************************
266   * 全角半角ひらがなかたかなを区別しない凄いPos   * 全角半角ひらがなかたかなを区別しない凄いPos
267   *************************************************************************)   *************************************************************************)
268  function VaguePos(const Substr, S: string): Integer;  function VaguePos(const Substr:String; const S: string): Integer;
269  begin  begin
270          Result := AnsiPos(ZenToHan(Substr), ZenToHan(S));          Result := AnsiPos(ZenToHan(Substr), ZenToHan(S));
271  end;  end;
# Line 336  begin Line 331  begin
331  end;  end;
332  // *************************************************************************  // *************************************************************************
333    
 {!  
 \brief datファイルの一ラインを分解  
 \param Line datファイルを構成する 1 行  
 \return     レス情報  
 }  
 procedure DivideStrLine(Line: string; PRes: PResRec);  
 const  
         delimiter = '<>';  
 var  
         pds, pde : PChar;  
         pss, pse : PChar;  
         ppos : PChar;  
 begin  
         //固定  
         PRes.FType := glt2chNew;  
   
         pss := PChar(Line);  
         pse := pss + Length(Line);  
         pds := PChar(delimiter);  
         pde := pds + Length(delimiter);  
   
         ppos := AnsiStrPosEx(pss, pse, pds, pde);  
         if (ppos = nil) then begin  
                 Line := CustomStringReplace(Line, '<>', '&lt;&gt;');  
                 Line := CustomStringReplace(Line, ',', '<>');  
                 Line := CustomStringReplace(Line, '@`', ',');  
         end;  
         //Trimしてはいけない気がする byもじゅ  
         PRes.FName := RemoveToken(Line, delimiter);  
         PRes.FMailTo := RemoveToken(Line, delimiter);  
         PRes.FDateTime := RemoveToken(Line, delimiter);  
         PRes.FBody := RemoveToken(Line, delimiter);  
         //2ちゃんねるとかだと、本文の先頭に1つ半角空白が入っているので削除する  
         //他の掲示板で、レス自体の空白かもしれないけどそれは諦める  
         PRes.FBody := TrimLeft(PRes.FBody);  
         //空だと問題が起きるから、空白を設定する  
         if PRes.FBody = '' then  
                 PRes.FBody := '&nbsp;';  
   
         PRes.FTitle := RemoveToken(Line, delimiter);  
 end;  
334    
335  (*************************************************************************  (*************************************************************************
336   *   *

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

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