using System; using System.Linq; using System.Text; using System.Collections.Generic; using FooEditEngine; namespace FooEditEngine { /// /// 補完候補作成用便利クラス /// public static class CompleteHelper { /// /// KeywordManager.Operatorsで区切られた単語を補完候補に追加する /// /// /// /// public static void AddCompleteWords(CompleteCollection items, IList Operators, string s) { if (items == null || Operators == null) return; char[] seps = new char[Operators.Count]; Operators.CopyTo(seps, 0); string[] words = s.Split(seps, StringSplitOptions.RemoveEmptyEntries); foreach (string word in words) CompleteHelper.AddComleteWord(items, word); } /// /// 補完候補を追加する /// /// /// public static void AddComleteWord(CompleteCollection items, string word) { CompleteWord newItem = new CompleteWord(word); if (items.Contains(newItem) == false && CompleteHelper.IsVaildWord(word)) items.Add(newItem); } /// /// ドキュメントから単語リストを作成する /// /// /// /// /// public static string GetWord(Document doc, int startIndex,char[] sep) { if (doc.Length == 0) return null; StringBuilder word = new StringBuilder(); for (int i = startIndex; i >= 0; i--) { if(sep.Contains(doc[i])) { return word.ToString(); } word.Insert(0,doc[i]); } if (word.Length > 0) return word.ToString(); else return null; } static bool IsVaildWord(string s) { if (s.Length == 0 || s == string.Empty) return false; if (!Char.IsLetter(s[0])) return false; for (int i = 1; i < s.Length; i++) { if (!Char.IsLetterOrDigit(s[i])) return false; } return true; } } }