| 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 |
| 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 ); |
| 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; |
| 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; |
| 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 |
| 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; |
| 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, '<>', '<>'); |
|
|
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 := ' '; |
|
|
|
|
|
PRes.FTitle := RemoveToken(Line, delimiter); |
|
|
end; |
|
| 334 |
|
|
| 335 |
(************************************************************************* |
(************************************************************************* |
| 336 |
* |
* |