OSDN Git Service

DeleteFontTagを共通関数化してこっちに移動
authorh677 <h677>
Wed, 22 Jun 2005 15:25:17 +0000 (15:25 +0000)
committerh677 <h677>
Wed, 22 Jun 2005 15:25:17 +0000 (15:25 +0000)
MojuUtils.pas

index 4f0637d..136fe09 100644 (file)
@@ -31,8 +31,9 @@ uses
 
        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;
 
-       procedure LoadFromFile(Strings: TStrings; const FileName: 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;
@@ -122,19 +123,19 @@ var
 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) +
+       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;
@@ -326,114 +327,38 @@ begin
                else Result := False;
        end;
 end;
-{***********************************************************************
-\8d\82\91¬\82ÈLoadFromFile\81@\81F\81@\83\81\83\82\83\8a\82Ì\8eg\97p\97Ê\82ª\83t\83@\83C\83\8b\83T\83C\83Y\81@+\81@8kB
-***********************************************************************}
-procedure LoadFromFile(Strings: TStrings; const FileName: String);
-const
-       BufferSize = $2000;
+
+// *************************************************************************
+// 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
-       I, ReadCount, LineCount: Integer;
-       LineRemained: Boolean;
-       S, Str: String;
-       Buffer, P, Start: PChar;
-       Fs: TFileStream;
+       pos : Integer;
 begin
-       Strings.BeginUpdate;
-       try
-               Strings.Clear;
-               Fs := TFileStream.Create(FileName, fmOpenRead);
-               try
-                       Buffer := StrAlloc(BufferSize + 1);
-                       try
-                               // #13#10 \82ð\83J\83E\83\93\83g\82·\82é #26 \88È\8d~\82Í\93Ç\82Ý\8d\9e\82Ü\82È\82¢
-                               LineCount := 0;
-                               LineRemained := False;
-                               repeat
-                                       ReadCount := Fs.Read(Buffer^, BufferSize);
-                                       if ReadCount > 0 then
-                                               LineRemained := False;
-                                       Buffer[ReadCount] := #0;
-                                       P := Buffer;
-                                       // \83o\83b\83t\83@\82É\82æ\82Á\82Ä #13#10 \82ª\95ª\92f\82³\82ê\82½\8fê\8d\87\82Ì\82½\82ß\82É
-                                       if P^ = #10 then Inc(P);
-
-                                       while not(P^ in [#0, #26]) do
-                                       begin
-
-                                               while not (P^ in [#0, #10, #13, #26]) do Inc(P);
-
-                                               if P^ in [#10, #13] then
-                                                       Inc(LineCount)
-                                               else
-                                                       LineRemained := True;
-
-                                               if P^ = #13 then Inc(P);
-
-                                               if P^ = #10 then Inc(P);
-                                       end;
-                                       if P^ = #26 then Break;
-                               until ReadCount = 0;
-
-                               if LineRemained then
-                                         Inc(LineCount);
-
-                               // \8eæ\93¾\82µ\82½\8ds\90\94\95ª\82Ì Capacity \82ð\8am\95Û
-                               for I := 0 to LineCount - 1 do
-                                       Strings.Add('');
-
-                               // \83o\83b\83t\83@\82ð\97\98\97p\82µ\82Ä\93Ç\82Ý\8d\9e\82Ý #26 \88È\8d~\82Í\93Ç\82Ý\8d\9e\82Ü\82È\82¢
-                               Fs.Seek(0, 0);
-                               LineCount := 0;
-                               Str := '';
-                               repeat
-                                       ReadCount := Fs.Read(Buffer^, BufferSize);
-                                       Buffer[ReadCount] := #0;
-                                       P := Buffer;
-                                       // \83o\83b\83t\83@\82É\82æ\82Á\82Ä #13#10 \82ª\95ª\92f\82³\82ê\82½\8fê\8d\87\82Ì\82½\82ß\82É
-                                       if P^ = #10 then Inc(P);
-
-                                       while not(P^ in [#0, #26]) do
-                                       begin
-                                               Start := P;
-                                               while not (P^ in [#0, #10, #13, #26]) do Inc(P);
-
-                                               SetString(S, Start, P - Start);
-                                               if P^ in [#0, #26] then
-                                                       Str := S
-                                               else
-                                               begin
-                                                       if Str <> '' then
-                                                       begin
-                                                               S := Str + S;
-                                                               Str := '';
-                                                       end;
-                                                       Strings[LineCount] := S;
-                                                       Inc(LineCount);
-                                               end;
-
-                                               if P^ = #13 then Inc(P);
-
-                                               if P^ = #10 then Inc(P);
-                                       end;
-
-                                       if P^ = #26 then Break;
-
-                               until ReadCount = 0;
-
-                               if Str <> '' then
-                                       Strings[LineCount] := Str;
-                         finally
-                               StrDispose(Buffer);
-                         end;
-               finally
-                       Fs.Free;
-               end;
-       finally
-               Strings.EndUpdate;
+       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;
-end;
 
+       Result := Result + inSource;
+
+
+end;
+// *************************************************************************
 
 
 end.