OSDN Git Service

・スレタイにタブ文字があるスレッドをHTML化して保存できない問題を修正
[gikonavigoeson/gikonavi.git] / AbonUnit.pas
index 7ed4958..a6a92f6 100644 (file)
@@ -7,7 +7,8 @@ unit AbonUnit;
 
 interface
 uses
-    Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils;
+    Windows,Messages, ShellAPI, SysUtils, Classes,StdCtrls,StrUtils,
+    Forms, Controls;
 
 type
        TIndiviAbon = class( TObject )
@@ -106,7 +107,7 @@ type
        procedure AddIndividualAbon( ResNum : Integer ; option : Integer; SetResNumFile : String);
        function CheckIndividualAbonList(ResNum : Integer) : Boolean;
 
-       procedure EditNGwords();  //NGword.txt\82ð\8aJ\82­\81B
+       function EditNGwords(Owner: TForm): Boolean;  //NGword.txt\82ð\8aJ\82­\81B
        function ShowAllTokens() : String;  //\83f\83o\83b\83O\97p
        //--
        procedure GoHome();//List\82Ì\82P\8ds\96Ú\82ð\93Ç\82Þ
@@ -121,10 +122,13 @@ var
        Abon1 :TAbon;
 const
        NGwordListFileName : String = 'NGwords.list';
+    DEF_REGEXP:  String = '{{REGEXP}}';
 
 implementation
 
-uses MojuUtils, GikoSystem, GikoBayesian, Setting;
+uses MojuUtils, GikoSystem, GikoBayesian, Setting,
+  NgEditor,
+  bmRegExp;
 
 function InvidiAbonListSort( item1, item2 : Pointer ) : Integer;
 begin
@@ -375,8 +379,10 @@ var
        i : Integer;
        pos : Integer;
        buftoken : String;
+    RegExp: Boolean;
 begin
        bufstl := TStringList.Create;
+    RegExp := False;
        try
                if Length(argline) > 0 then begin
                        pos := AnsiPos(#9,argline);
@@ -384,6 +390,9 @@ begin
                                buftoken := Copy(argline,1,pos-1);
                                Delete(argline,1,pos);
                                if Length(buftoken) > 0 then begin
+                    if (buftoken = DEF_REGEXP) then begin
+                        RegExp := True;
+                    end else
                     // >> \82Å\8en\82Ü\82é\83g\81[\83N\83\93\82Í\83R\83\81\83\93\83g\88µ\82¢\82Å\96³\8e\8b\82·\82é
                     if AnsiPos('>>', buftoken) <> 1 then begin
                                        bufstl.Append(buftoken);
@@ -400,12 +409,30 @@ begin
                 end;
                        end;
                        ret := bufstl.Count;
+            if (RegExp = True) then
+                ret := ret + 1;
                        SetLength(Ftokens[index],ret);
-                       for i := 0 to bufstl.Count - 1  do begin
-                               if IgnoreKana then
-                                       Ftokens[index][i] := ZenToHan(bufstl.Strings[i])
-                               else
-                    Ftokens[index][i] := bufstl.Strings[i];
+                       for i := 0 to ret - 1  do begin
+                if (RegExp = True) then begin
+                    if (i = 0) then begin
+                        if (bufstl.Strings[0] = '') then
+                            Ftokens[index][0] := ''
+                        else
+                            Ftokens[index][0] := DEF_REGEXP;
+                    end else if (i = 1) then begin
+                        if (bufstl.Strings[0] = '') then
+                            Ftokens[index][1] := DEF_REGEXP
+                        else
+                            Ftokens[index][1] := bufstl.Strings[0];
+                    end else begin
+                        Ftokens[index][i] := bufstl.Strings[i - 1];
+                    end;
+                end else begin
+                    if IgnoreKana then
+                        Ftokens[index][i] := ZenToHan(bufstl.Strings[i])
+                    else
+                        Ftokens[index][i] := bufstl.Strings[i];
+                end;
                        end;
                end;
        finally
@@ -443,6 +470,10 @@ var
        pos : PChar;
        pts, pte : PChar;
        trgLen : Integer;
+    RegExp: Boolean;
+    AWKStr: TAWKStr;
+       RStart: Integer;
+       RLength: Integer;
 begin
        hit := false;
        if AnsiStrPosEx(PChar(line), PChar(line)+Length(line), FpAbons, FpAbone) = nil then begin
@@ -453,6 +484,8 @@ begin
                        target := line;
 
                trgLen := Length(target);
+        RegExp := False;
+        AWKStr := nil;
 
                for lines := 0 to High(Ftokens) do begin
             if Length(Ftokens[lines]) = 0 then begin
@@ -465,29 +498,58 @@ begin
 
                        if Ftokens[lines][0] <> ''  then begin
                                Invisible := false;
-                               start := 0;
+                if (Ftokens[lines][0] = DEF_REGEXP) then begin
+                    RegExp := True;
+                               start := 1;
+                end else begin
+                               start := 0;
+                end;
                        end else begin
                                Invisible := true;
-                               start := 1;
+                if (High(Ftokens) > 0) and (Ftokens[lines][1] = DEF_REGEXP) then begin
+                    RegExp := True;
+                               start := 2;
+                end else begin
+                               start := 1;
+                end;
                        end;
 
+            if (RegExp = True) and (AWKStr = nil) then begin
+               AWKStr := TAWKStr.Create(nil);
+            end;
+
                        for cells := start to High(Ftokens[lines]) do begin
-                               pos := AnsiStrPosEx(pts, pte,
-                                               PChar(Ftokens[lines][cells]), PChar(Ftokens[lines][cells]) + Length(Ftokens[lines][cells]));
-                               if pos = nil then begin
-                                       hit := false;
-                                       break;
-                               end else begin
-                                       Delete(bufline, pos - pte + 1, Length(Ftokens[lines][cells]));
-                                       pts := PChar(bufline);
-                                       pte := pts + Length(bufline);
-                               end;
+                if (RegExp = False) then begin
+                    pos := AnsiStrPosEx(pts, pte,
+                            PChar(Ftokens[lines][cells]), PChar(Ftokens[lines][cells]) + Length(Ftokens[lines][cells]));
+                    if pos = nil then begin
+                        hit := false;
+                        break;
+                    end else begin
+                        Delete(bufline, pos - pte + 1, Length(Ftokens[lines][cells]));
+                        pts := PChar(bufline);
+                        pte := pts + Length(bufline);
+                    end;
+                end else begin
+                    try
+                        AWKStr.RegExp := Ftokens[lines][cells];
+                        if (AWKStr.Match(AWKStr.ProcessEscSeq(target), RStart, RLength) < 1) then
+                            hit := False;   // \83}\83b\83`\82µ\82È\82¢
+                       except
+                        hit := False;
+                    end;
+                    if (hit = False) then
+                        Break;      // 1\82Â\82Å\82à\83}\83b\83`\82µ\82È\82¢\8fê\8d\87\82Í\82 \82Ú\81[\82ñ\82µ\82È\82¢
+                end;
                        end;
                        if hit = true then begin
                                NGwordsLineNum := lines + 1;
                                break;
                        end;
                end;
+
+        if (AWKStr <> nil) then
+           FreeAndNil(AWKStr);
        end;
        Result := hit;
 end;
@@ -572,9 +634,28 @@ end;
 
 //****************************************************************************//
 //\8c»\8dÝ\83Z\83b\83g\82³\82ê\82Ä\82¢\82éNGword.txt\82ð\8aJ\82­
-procedure TAbon.EditNGwords();
+function TAbon.EditNGwords(Owner: TForm): Boolean;
+var
+    Dlg: TNgEdit;
+    ReLoad: Boolean;
 begin
-       ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
+    ReLoad := False;
+
+    if (GikoSys.Setting.NGTextEditor = False) then begin
+        Dlg := TNgEdit.Create(Owner);
+
+        Dlg.SetFilePath(FNGwordpath);
+        if (Dlg.ShowModal = mrOk) then begin
+            if (Dlg.GetReload = True) then
+                ReLoad := True;
+        end;
+
+        Dlg.Free;
+    end else begin
+           ShellExecute(0 ,nil,PChar(FNGwordpath),nil,nil,SW_SHOW);
+    end;
+
+    Result := ReLoad;
 end;
 //\83|\83b\83v\83A\83b\83v\97p\94»\92è\8aÖ\90\94
 function TAbon.CheckAbonPopupRes(line : String) :Boolean;