function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
function AnsiStrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
- function ReplaceString(const S, OldPattern, NewPattern: string): string;
- function IgnoCaseReplaceString(const S, OldPattern, NewPattern: string): string;
+ function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): String;
+ function IgnoCaseReplaceString(const S: String; const OldPattern:String; const NewPattern: string): String;
- function CustomStringReplace(S , OldPattern: String;const NewPattern: string): String; overload;
- function CustomStringReplace(S , OldPattern: String;const NewPattern: string; IgnoreCase : Boolean): String; 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;
+ function CustomStringReplace(const S: String; const OldPattern: String; const NewPattern: string; IgnoreCase : Boolean = False): String; overload;
+ procedure CustomStringReplace(var S : TStringList;const OldPattern: String;const NewPattern: string; IgnoreCase : Boolean = False); overload;
function ZenToHan(const s: string): string;
- function VaguePos(const Substr, S: string): Integer;
+ function VaguePos(const Substr: String; const S: string): Integer;
+
+ function ReplaseNoValidateChar( inVal : String): String;
+ function IsNoValidID( inID :String): Boolean;
+ //<font>\83^\83O\82ð\91S\82Ä\8dí\8f\9c\82·\82é
+ function DeleteFontTag( inSource : string) : string;
+ function RemoveToken(var s: string;const delimiter: string): string;
+ // \96³\8aQ\89»(& -> & " -> &auot; \82É\95Ï\8a·\82·\82é)
+ function Sanitize(const s: String): String;
+ // \96³\8aQ\89»\89ð\8f\9c(& -> & &auot; -> " \82É\95Ï\8a·\82·\82é)
+ function UnSanitize(const s: String): String;
implementation
// \83|\83C\83\93\83^\81[\81\95\83A\83Z\83\93\83u\83\89\82É\82æ\82é\8d\82\91¬\83|\83X
function StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd: PChar): PChar;
asm
- PUSH EBX
+ PUSH EBX
PUSH ESI
- PUSH EDI
+ PUSH EDI
- MOV ESI,ECX { Point ESI to substr }
- MOV EDI,EAX { Point EDI to s }
+ MOV ESI,ECX { Point ESI to substr }
+ MOV EDI,EAX { Point EDI to s }
- MOV ECX,EDX { ECX = search length }
+ MOV ECX,EDX { ECX = search length }
SUB ECX,EAX
MOV EDX,SubstrEnd
Result := StrPosEx(StrStart, StrEnd, SubstrStart, SubstrEnd);
while (Result <> nil) and (StrEnd - Result >= L2) do begin
- ByteType := StrByteType(StrStart, Integer(Result-StrStart));
- if (ByteType <> mbTrailByte) and
- (CompareString(LOCALE_USER_DEFAULT, SORT_STRINGSORT, Result, L2, SubstrStart, L2) = 2)
- then Exit;
+ ByteType := StrByteType(StrStart, Integer(Result-StrStart));
+ if (ByteType <> mbTrailByte) and
+ (CompareString(LOCALE_USER_DEFAULT, SORT_STRINGSORT, Result, L2, SubstrStart, L2) = 2)
+ then Exit;
if (ByteType = mbLeadByte) then Inc(Result);
Inc(Result);
Result := StrPosEx(Result, StrEnd, SubStrStart, SubStrEnd);
Result := nil;
end;
-{$R-}
//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\91å\95¶\8e\9a\8f¬\95¶\8e\9a\82Ì\88á\82¢\82ð\96³\8e\8b\82µ\82È\82¢\81j
-function ReplaceString(const S, OldPattern, NewPattern: string): string;
+function ReplaceString(const S: String; const OldPattern: String; const NewPattern: string): String;
var
- ReplaceCount: Integer;
- DestIndex: Integer;
- i, l: Integer;
- p, e, ps, pe: PChar;
- Count: Integer;
+ ReplaceCount: Integer;
+ DestIndex: Integer;
+ i, l: Integer;
+ p, e, ps, pe: PChar;
+ Count: Integer;
+ olen: Integer;
begin
- Result := S;
- if OldPattern = '' then Exit;
- p := PChar(S);
- e := p + Length(S);
- ps := PChar(OldPattern);
- pe := ps + Length(OldPattern);
- ReplaceCount := 0;
- while p < e do begin
- p := AnsiStrPosEx(p, e, ps, pe);
- if p = nil then Break;
- Inc(ReplaceCount);
- Inc(p, Length(OldPattern));
- end;
- if ReplaceCount = 0 then Exit;
- SetString(Result, nil, Length(S) +
- (Length(NewPattern) - Length(OldPattern)) * ReplaceCount);
- p := PChar(S);
- DestIndex := 1;
- l := Length( NewPattern );
- for i := 0 to ReplaceCount - 1 do begin
- Count := AnsiStrPosEx(p, e, ps, pe) - p;
- Move(p^, Result[DestIndex], Count);
- Inc(p, Count);//p := pp;
- Inc(DestIndex, Count);
- Move(NewPattern[1], Result[DestIndex], l);
- Inc(p, Length(OldPattern));
- Inc(DestIndex, l);
- end;
- Move(p^, Result[DestIndex], e - p);
+ Result := S;
+ olen := Length(OldPattern);
+ if olen = 0 then Exit;
+ p := PChar(S);
+ e := p + Length(S);
+ ps := PChar(OldPattern);
+ pe := ps + olen;
+ ReplaceCount := 0;
+ while p < e do begin
+ p := AnsiStrPosEx(p, e, ps, pe);
+ if p = nil then Break;
+ Inc(ReplaceCount);
+ Inc(p, olen);
+ end;
+ if ReplaceCount = 0 then Exit;
+ SetString(Result, nil, Length(S) +
+ (Length(NewPattern) - olen) * ReplaceCount);
+ p := PChar(S);
+ DestIndex := 1;
+ l := Length( NewPattern );
+ for i := 0 to ReplaceCount - 1 do begin
+ Count := AnsiStrPosEx(p, e, ps, pe) - p;
+ Move(p^, Result[DestIndex], Count);
+ Inc(p, Count);//p := pp;
+ Inc(DestIndex, Count);
+ Move(NewPattern[1], Result[DestIndex], l);
+ Inc(p, olen);
+ Inc(DestIndex, l);
+ end;
+ Move(p^, Result[DestIndex], e - p);
end;
//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\91å\95¶\8e\9a\8f¬\95¶\8e\9a\82Ì\88á\82¢\82ð\96³\8e\8b\82·\82é\81j
-function IgnoCaseReplaceString(const S, OldPattern, NewPattern: string): string;
+function IgnoCaseReplaceString(const S: String;const OldPattern:String;const NewPattern: string): String;
var
ReplaceCount: Integer;
DestIndex: Integer;
end;
Move(p^, Result[DestIndex], e - p);
end;
-{$IFDEF DEBUG}
-{$R+}
-{$ENDIF}
-
-//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\83v\83\8a\83~\83e\83B\83u\81j
-function CustomStringReplace(
- S ,OldPattern: String;
- const NewPattern: string
-): String;
-
-begin
- Result := ReplaceString(S,OldPattern,NewPattern);
-end;
-
//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\94Ä\97p\94Å\82P\81j
function CustomStringReplace(
- S , OldPattern: String;
+ const S :String;
+ const OldPattern: String;
const NewPattern: string;
IgnoreCase : Boolean
): String;
begin
- Result := '';
if not IgnoreCase then begin
Result := ReplaceString(S,OldPattern,NewPattern);
end else begin
//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\94Ä\97p\94Å\82Q\81j
procedure CustomStringReplace(
var S : TStringList;
- OldPattern: String;
+ const OldPattern: String;
const NewPattern: string;
IgnoreCase : Boolean
);
S.EndUpdate;
end;
-//\8d\82\91¬\95¶\8e\9a\97ñ\92u\8a·\8aÖ\90\94\81i\94Ä\97p\94Å\82R\81j
-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;
-
(*************************************************************************
* \91S\8ap\81¨\94¼\8ap
* from HotZonu
*************************************************************************)
function ZenToHan(const s: string): string;
var
- //Chr: array [0..1024] of char;
- Chr: string;
ChrLen : Integer;
begin
- SetLength(Chr, Length(s));
+ SetLength(Result, Length(s));
ChrLen := Windows.LCMapString(
GetUserDefaultLCID(),
// LCMAP_HALFWIDTH,
LCMAP_HALFWIDTH or LCMAP_KATAKANA or LCMAP_LOWERCASE,
PChar(s),
Length(s),
- PChar(Chr),
- Length(Chr)
+ PChar(Result),
+ Length(Result)
);
- Result := Copy(Chr, 1, ChrLen);
+ SetLength(Result, ChrLen);
end;
(*************************************************************************
* \91S\8ap\94¼\8ap\82Ð\82ç\82ª\82È\82©\82½\82©\82È\82ð\8bæ\95Ê\82µ\82È\82¢\90¦\82¢Pos
*************************************************************************)
-function VaguePos(const Substr, S: string): Integer;
+function VaguePos(const Substr:String; const S: string): Integer;
begin
Result := AnsiPos(ZenToHan(Substr), ZenToHan(S));
end;
+(*************************************************************************
+ * FAT/NTFS\82Ì\83t\83@\83C\83\8b\96¼\82É\8b\96\82³\82ê\82È\82¢\95¶\8e\9a\81i\,/,:,.,;,*,>,<,|\81j\82ð\91S\8ap\82É\92u\8a·\82·\82é
+ *************************************************************************)
+function ReplaseNoValidateChar( inVal : String): String;
+begin
+ Result := CustomStringReplace(inVal, '\', '\81\8f');
+ Result := CustomStringReplace(Result, '/', '\81^');
+ Result := CustomStringReplace(Result, ':', '\81F');
+ Result := CustomStringReplace(Result, '.', '\81D');
+ Result := CustomStringReplace(Result, ';', '\81G');
+ Result := CustomStringReplace(Result, '*', '\81\96');
+ Result := CustomStringReplace(Result, '>', '\81\84');
+ Result := CustomStringReplace(Result, '<', '\81\83');
+ Result := CustomStringReplace(Result, '|', '\81b');
+ Result := CustomStringReplace(Result, #9, '');
+end;
+(*************************************************************************
+ * \96³\8cø\82ÈID\82©\82Ì\83`\83F\83b\83N\81i\96³\8cø\97á\81FID:??? , ID:???X)
+ *************************************************************************)
+function IsNoValidID( inID :String): Boolean;
+var
+ bTail : Boolean;
+begin
+ Result := True;
+ inID := Trim(inID);
+ if (Length(inID) > 0) then begin
+ inID := Copy(inID, AnsiPos(':', inID) + 1, Length(inID) );
+ bTail := False;
+ // \96\96\94ö\82ª?\88È\8aO\82©
+ if Length(inID) > 0 then begin
+ bTail := (inID[Length(inID)] <> '?');
+ end;
+ inID := CustomStringReplace(inID, '?', '');
+ if (Length(inID) > 0) and (not
+ ((Length(inID) = 1) and (bTail))) then begin
+ Result := False;
+ end;
+ end;
+end;
+
+// *************************************************************************
+// HTML\92\86\82Ì<font>\83^\83O\82ð\8dí\8f\9c\82·\82é
+// *************************************************************************
+function DeleteFontTag(
+ inSource : string //\83^\83O\82ð\8dí\8f\9c\82·\82é\95¶\8e\9a\97ñ
+) : string; //\83^\83O\8dí\8f\9c\8cê\82Ì\95¶\8e\9a\97ñ
+var
+ pos : Integer;
+begin
+ Result := '';
+
+ //</font>\82ð\8dí\8f\9c
+ inSource := CustomStringReplace( inSource, '</font>', '', True);
+ //<font \82ð\91S\82Ä\8f¬\95¶\8e\9a\82É\95Ï\8a·\82·\82é
+ inSource := CustomStringReplace( inSource, '<font', '<font', True);
+ //<font \81` \82ð\8dí\8f\9c\82·\82é
+ pos := AnsiPos('<font', inSource);
+ while (pos > 0) do begin
+ Result := Result + Copy(inSource, 1, pos - 1);
+ Delete(inSource, 1, pos);
+ //\83^\83O\82ð\95Â\82¶\82é'>'\82Ü\82Å\82ð\8dí\8f\9c
+ pos := AnsiPos('>', inSource);
+ Delete(inSource, 1, pos);
+ pos := AnsiPos('<font', inSource);
+ end;
+
+ Result := Result + inSource;
+
+
+end;
+// *************************************************************************
+
+
+(*************************************************************************
+ *
+ *\82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
+ *************************************************************************)
+function RemoveToken(var s: string;const delimiter: string): string;
+var
+ p: Integer;
+ pos : PChar;
+ pds, pde : PChar;
+ pss, pse : PChar;
+begin
+ pss := PChar(s);
+ pse := pss + Length(s);
+ pds := PChar(delimiter);
+ pde := pds + Length(delimiter);
+
+ pos := StrPosEx(pss, pse, pds, pde);
+ if pos <> nil then begin
+ p := pos - pss;
+ SetString(Result, pss, p);
+ Delete(s, 1, p + Length(delimiter));
+ if (Length(Result) > 0) then begin
+ if (StrByteType(PChar(Result), Length(Result)-1) = mbLeadByte) then begin
+ SetLength(Result, Length(Result) - 1);
+ end;
+ end;
+ end else begin
+ Result := s;
+ s := '';
+ end;
+end;
+
+//! \96³\8aQ\89»(& -> & " -> " \82É\95Ï\8a·\82·\82é)
+function Sanitize(const s: String): String;
+begin
+ // \97]\95ª\82É\83T\83j\83^\83C\83Y\82³\82ê\82È\82¢\82æ\82¤\82É\82¢\82Á\82½\82ñ\8c³\82É\96ß\82·
+ Result := UnSanitize(s);
+ Result := CustomStringReplace(Result, '&', '&');
+ Result := CustomStringReplace(Result, '"', '"');
+end;
+//! \96³\8aQ\89»\89ð\8f\9c(& -> & " -> " \82É\95Ï\8a·\82·\82é)
+function UnSanitize(const s: String): String;
+begin
+ Result := CustomStringReplace(s, '"', '"');
+ Result := CustomStringReplace(Result, '&', '&');
+end;
end.