| 21 |
function ReplaceString(const S, OldPattern, NewPattern: string): string; |
function ReplaceString(const S, OldPattern, NewPattern: string): string; |
| 22 |
function IgnoCaseReplaceString(const S, OldPattern, NewPattern: string): string; |
function IgnoCaseReplaceString(const S, OldPattern, NewPattern: string): string; |
| 23 |
|
|
| 24 |
function CustomStringReplace(S , OldPattern: String;const NewPattern: string): String; overload; |
function CustomStringReplace(S , OldPattern: String;const NewPattern: string; IgnoreCase : Boolean = False): String; overload; |
| 25 |
function CustomStringReplace(S , OldPattern: String;const NewPattern: string; IgnoreCase : Boolean): String; overload; |
procedure CustomStringReplace(var S : TStringList; OldPattern: String;const NewPattern: string; IgnoreCase : Boolean = False); overload; |
|
procedure CustomStringReplace(var S : TStringList; OldPattern: String;const NewPattern: string);overload; |
|
|
procedure CustomStringReplace(var S : TStringList; OldPattern: String;const NewPattern: string; IgnoreCase : Boolean);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, 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>タグを全て削除する |
| 33 |
|
function DeleteFontTag( inSource : string) : string; |
| 34 |
|
|
| 35 |
implementation |
implementation |
| 36 |
// ポインター&アセンブラによる高速ポス |
// ポインター&アセンブラによる高速ポス |
| 37 |
function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar; |
function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar; |
| 38 |
asm |
asm |
| 39 |
PUSH EBX |
PUSH EBX |
| 40 |
PUSH ESI |
PUSH ESI |
| 41 |
PUSH EDI |
PUSH EDI |
| 42 |
|
|
| 43 |
MOV ESI,ECX { Point ESI to substr } |
MOV ESI,ECX { Point ESI to substr } |
| 44 |
MOV EDI,EAX { Point EDI to s } |
MOV EDI,EAX { Point EDI to s } |
| 45 |
|
|
| 46 |
MOV ECX,EDX { ECX = search length } |
MOV ECX,EDX { ECX = search length } |
| 47 |
SUB ECX,EAX |
SUB ECX,EAX |
| 121 |
begin |
begin |
| 122 |
Result := S; |
Result := S; |
| 123 |
if OldPattern = '' then Exit; |
if OldPattern = '' then Exit; |
| 124 |
p := PChar(S); |
p := PChar(S); |
| 125 |
e := p + Length(S); |
e := p + Length(S); |
| 126 |
ps := PChar(OldPattern); |
ps := PChar(OldPattern); |
| 127 |
pe := ps + Length(OldPattern); |
pe := ps + Length(OldPattern); |
| 128 |
ReplaceCount := 0; |
ReplaceCount := 0; |
| 129 |
while p < e do begin |
while p < e do begin |
| 130 |
p := AnsiStrPosEx(p, e, ps, pe); |
p := AnsiStrPosEx(p, e, ps, pe); |
| 131 |
if p = nil then Break; |
if p = nil then Break; |
| 132 |
Inc(ReplaceCount); |
Inc(ReplaceCount); |
| 133 |
Inc(p, Length(OldPattern)); |
Inc(p, Length(OldPattern)); |
| 134 |
end; |
end; |
| 135 |
if ReplaceCount = 0 then Exit; |
if ReplaceCount = 0 then Exit; |
| 136 |
SetString(Result, nil, Length(S) + |
SetString(Result, nil, Length(S) + |
| 137 |
(Length(NewPattern) - Length(OldPattern)) * ReplaceCount); |
(Length(NewPattern) - Length(OldPattern)) * ReplaceCount); |
| 138 |
p := PChar(S); |
p := PChar(S); |
| 139 |
DestIndex := 1; |
DestIndex := 1; |
| 205 |
{$R+} |
{$R+} |
| 206 |
{$ENDIF} |
{$ENDIF} |
| 207 |
|
|
|
//高速文字列置換関数(プリミティブ) |
|
|
function CustomStringReplace( |
|
|
S ,OldPattern: String; |
|
|
const NewPattern: string |
|
|
): String; |
|
|
|
|
|
begin |
|
|
Result := ReplaceString(S,OldPattern,NewPattern); |
|
|
end; |
|
|
|
|
| 208 |
//高速文字列置換関数(汎用版1) |
//高速文字列置換関数(汎用版1) |
| 209 |
function CustomStringReplace( |
function CustomStringReplace( |
| 210 |
S , OldPattern: String; |
S , OldPattern: String; |
| 243 |
S.EndUpdate; |
S.EndUpdate; |
| 244 |
end; |
end; |
| 245 |
|
|
|
//高速文字列置換関数(汎用版3) |
|
|
procedure CustomStringReplace( |
|
|
var S : TStringList; |
|
|
OldPattern: String; |
|
|
const NewPattern: string |
|
|
); |
|
|
var |
|
|
i : Integer; |
|
|
begin |
|
|
S.BeginUpdate; |
|
|
for i := 0 to S.Count - 1 do begin |
|
|
S.Strings[i] := ReplaceString(S.Strings[i], OldPattern,NewPattern);; |
|
|
end; |
|
|
S.EndUpdate; |
|
|
end; |
|
|
|
|
| 246 |
(************************************************************************* |
(************************************************************************* |
| 247 |
* 全角→半角 |
* 全角→半角 |
| 248 |
* from HotZonu |
* from HotZonu |
| 281 |
Result := CustomStringReplace(inVal, '\', '¥'); |
Result := CustomStringReplace(inVal, '\', '¥'); |
| 282 |
Result := CustomStringReplace(Result, '/', '/'); |
Result := CustomStringReplace(Result, '/', '/'); |
| 283 |
Result := CustomStringReplace(Result, '*', '*'); |
Result := CustomStringReplace(Result, '*', '*'); |
| 284 |
Result := CustomStringReplace(Result, '>', '>'); |
Result := CustomStringReplace(Result, '>', '>'); |
| 285 |
Result := CustomStringReplace(Result, '<', '<'); |
Result := CustomStringReplace(Result, '<', '<'); |
| 286 |
Result := CustomStringReplace(Result, '|', '|'); |
Result := CustomStringReplace(Result, '|', '|'); |
| 287 |
end; |
end; |
| 288 |
(************************************************************************* |
(************************************************************************* |
| 289 |
* 無効なIDかのチェック(無効例:ID:??? , ID:???0) |
* 無効なIDかのチェック(無効例:ID:??? , ID:???0) |
| 290 |
*************************************************************************) |
*************************************************************************) |
| 291 |
function IsNoValidID( inID :String): Boolean; |
function IsNoValidID( inID :String): Boolean; |
| 292 |
begin |
begin |
| 293 |
inID := Trim(inID); |
inID := Trim(inID); |
| 294 |
if inID = '' then Result := True |
if inID = '' then Result := True |
| 295 |
else begin |
else begin |
| 296 |
inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) ); |
inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) ); |
| 297 |
inID := CustomStringReplace(inID, '?', ''); |
inID := CustomStringReplace(inID, '?', ''); |
| 298 |
if (inID = '') or (inID = '0') then Result := True |
if (inID = '') or (inID = '0') then Result := True |
| 299 |
else Result := False; |
else Result := False; |
| 300 |
end; |
end; |
| 301 |
|
end; |
| 302 |
|
|
| 303 |
|
// ************************************************************************* |
| 304 |
|
// HTML中の<font>タグを削除する |
| 305 |
|
// ************************************************************************* |
| 306 |
|
function DeleteFontTag( |
| 307 |
|
inSource : string //タグを削除する文字列 |
| 308 |
|
) : string; //タグ削除語の文字列 |
| 309 |
|
var |
| 310 |
|
pos : Integer; |
| 311 |
|
begin |
| 312 |
|
Result := ''; |
| 313 |
|
|
| 314 |
|
//</font>を削除 |
| 315 |
|
inSource := CustomStringReplace( inSource, '</font>', '', True); |
| 316 |
|
//<font を全て小文字に変換する |
| 317 |
|
inSource := CustomStringReplace( inSource, '<font', '<font', True); |
| 318 |
|
//<font 〜 を削除する |
| 319 |
|
pos := AnsiPos('<font', inSource); |
| 320 |
|
while (pos > 0) do begin |
| 321 |
|
Result := Result + Copy(inSource, 1, pos - 1); |
| 322 |
|
Delete(inSource, 1, pos); |
| 323 |
|
//タグを閉じる'>'までを削除 |
| 324 |
|
pos := AnsiPos('>', inSource); |
| 325 |
|
Delete(inSource, 1, pos); |
| 326 |
|
pos := AnsiPos('<font', inSource); |
| 327 |
|
end; |
| 328 |
|
|
| 329 |
|
Result := Result + inSource; |
| 330 |
|
|
| 331 |
|
|
| 332 |
end; |
end; |
| 333 |
|
// ************************************************************************* |
| 334 |
|
|
| 335 |
|
|
| 336 |
end. |
end. |