Beispiel #1
0
        //--------------------------------------------------------------------
        // その他正規表現検索
        static public SearchResult RegexSearch(SearchType type, string searchword)
        {
            SearchResult result;


            char[] any1 = new char[] { '.', '*', '?', '+', '[', '{' };
            char[] any2 = new char[] { '.', '*', '?', '+', ']', '}' };

            int leftPos  = searchword.IndexOfAny(any1);
            int rightPos = searchword.LastIndexOfAny(any2);
            int strLen   = searchword.Length;

            // あいう[か-く]まみ
            // 0 1 2 34 56 78 9
            //  leftPos:3    rightPos:7  strLen:9
            //    head : あいう
            //    tail : まみ
            //  if(leftPos+1==rightPos){
            //      return null;
            //  }

            string head = searchword.Substring(0, leftPos);
            string tail = searchword.Remove(0, rightPos + 1);

            KJ_dict.filterRegexword = searchword;

            // filterのデリゲート生成
            FilterDelegate dictFilter = new FilterDelegate(KJ_dict.RegexFilter);

            KJ_dict.SetFilter(dictFilter);

            // 長い方を優先に、前方一致または後方一致をかけ、
            // その結果からfilterを使い絞込みを行う。
            if (head.Length >= tail.Length)
            {
                result = KJ_dict.DictSearch(SearchType.forward, head);
            }
            else
            {
                result = KJ_dict.DictSearch(SearchType.backward, tail);
            }


            return(result);
        }
Beispiel #2
0
// for RichTextBoxEx
//        private void AddText(string text)
//        {
//            if (this.richTextBox2.InvokeRequired)
//            {
//                AddTextCallback d = new AddTextCallback(AddText);
//                this.Invoke(d, new object[] { text });
//            }
//            else
//            {
//                this.richTextBox2.SelectedText = text;
//               // this.richTextBox2.Text += text;
//            }
//        }
//        private void AddLink(string text)
//        {
//            if (this.richTextBox2.InvokeRequired)
//            {
//                AddlinkCallback d = new AddlinkCallback(AddLink);
//                this.Invoke(d, new object[] { text });
//            }
//            else
//            {
//                this.richTextBox2.InsertLink(text);
//            }
//        }

        //--------------------------------------------------------------------
        // 検索用スレッド
        //   (正規表現検索に入ると時間がかかる場合があるため別スレッドにする)
        public void form_search_thread()
        {
            Cursor preCursor = Cursor.Current;

            //  検索中を示すためタイトルを変える
            this.Text = this.searchingLabel;

            String searchword = this.inputArea.Text;


            searchword = searchword.Trim();
            if (searchword == "")
            {
                richTextBox2.Text = "";

                //  検索中を示すタイトルを戻す
#if !EDICT
                this.Text = "KJ_dictform";
#else
                this.Text = "KJ_Edict";
#endif
                // 検索語がない
                return;
            }

#if EDICT
            // 大文字→小文字変換する。
            //   There had to be times... のように
            //   文頭の大文字始まりの単語を引けるように。
            searchword = searchword.ToLower();
#endif

            // 検索の種別
            SearchType searchType = SearchType.forward;   //default

            if (this.radioButton1.Checked == true)
            {
                searchType = SearchType.full;       // 完全一致
            }
            if (this.radioButton2.Checked == true)
            {
                searchType = SearchType.forward;    // 前方一致
            }
            if (this.radioButton3.Checked == true)
            {
                searchType = SearchType.backward;   // 後方一致
            }
            if (this.radioButton4.Checked == true)
            {
                searchType = SearchType.part;       // 部分一致
            }


            SearchResult result;

            if (searchword.IndexOf("*") < 0 &&
                searchword.IndexOf("+") < 0 &&
                searchword.IndexOf(".") < 0 &&
                searchword.IndexOf("^") < 0 &&
                searchword.IndexOf("$") < 0 &&
                searchword.IndexOf("(") < 0 &&
                searchword.IndexOf("[") < 0 &&
                searchword.IndexOf("{") < 0 &&
                searchword.IndexOf("?") < 0)
            {
                // 通常検索
                result = KJ_dict.DictSearch(searchType, searchword);
            }
            else
            {
                // 正規表現検索
                result = RegexSearch(searchword);
            }

            // make result text
            //     MakeResultText(searchword, searchType, result); // for RichTextBoxEx
            this.SetText(MakeResultText(searchword, searchType, result));

            //  検索中を示す背景色とタイトルを戻す
            this.BackColor = System.Drawing.SystemColors.Control;
#if !EDICT
            this.Text = "KJ_dictform";
#else
            this.Text = "KJ_Edict";
#endif
        }