public void MigemoAllCharTest() { if (!Migemo.IsEnable()) { var solutionDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location).FullName).FullName).FullName).FullName; var migemoDllPath = Path.Combine(solutionDir, "assemblies", "Migemo"); var migemoDictionaryPath = Path.Combine(solutionDir, "assemblies", "Migemo", "dict", "migemo-dict"); //Console.WriteLine(settings.MigemoDllPath); //Console.WriteLine(settings.MigemoDictionaryPath); Migemo.Initialize(migemoDllPath, migemoDictionaryPath); } if (!Migemo.IsEnable()) { // Fail: Migemo initialize Assert.Fail(); } for (var test = Convert.ToChar(0); test <= 255; test++) { try { var ret = Migemo.GetRegex(test.ToString()); //Console.WriteLine("{0}, {1}", test, ret.ToString()); } catch { Assert.Fail(); } } }
//public static RegexModel GetInstance() //{ // if (regexModel == null) // { // regexModel = new RegexModel(); // } // return regexModel; //} /// <summary> /// /// </summary> /// <param name="pattern"></param> /// <returns></returns> public Regex GetRegex(string pattern) { if (migemo != null && pattern.StartsWith("/") && !pattern.EndsWith("/")) { return(migemo.GetRegex(pattern.Substring(1))); } else { return(new Regex(pattern)); } }
public void Execute(IEnumerable <string> args) { var arg = args.ToList()[0]; var regex = _migmemo.GetRegex(arg); foreach (var s in GetRegistlations()) { Debug.WriteLine(s); var t = regex.Match(s).ToString(); regex.IsMatch(s); } string[] matches = GetRegistlations().Select(s => s).Where(s => s.Contains(regex.Match(s).ToString()) && !string.IsNullOrEmpty(regex.Match(s).ToString()) || s.IndexOf(arg, StringComparison.OrdinalIgnoreCase) >= 0).ToArray(); using (var form = new CandidateForm(matches)) { form.ShowDialog(); } }
private IEnumerable <IHUDItem> Filter(IEnumerable <IHUDItem> list, params string[] inputs) { Regex regex; if (CanUseMigemo(inputs[0])) { regex = Migemo.GetRegex(inputs[0]); } else { var input = Regex.Escape(inputs[0]); regex = new Regex(input, RegexOptions.IgnoreCase); } var select = list.Where(hudItem => { var match = regex.Match(hudItem.DisplayText); if (match.Success) { if (hudItem == null) { return(false); } hudItem.ColoredStart = match.Index; hudItem.ColoredLength = match.Length; } return(match.Success); }); if (inputs.Length > 1) { return(Filter(select, inputs.Skip(1).ToArray())); } else { return(select); } }
public override object Invoke(object[] args) { bool result = false; try { result = migemo.GetRegex(args[0].ToString()).IsMatch(args[1].ToString()); if (!result && usermigemo != null) { result = usermigemo.GetRegex(args[0].ToString()).IsMatch(args[1].ToString()); } } catch (ArgumentException) { // 正規表現の解析に失敗した return(false); } return(result); }
private List <Result> QuerySync(Query query) { var results = new List <Result>(); if (!string.IsNullOrEmpty(query.Search)) { var keyword = query.Search; if (_settings.MaxSearchCount <= 0) { _settings.MaxSearchCount = 50; } try { // Migemo Search if (keyword.Length >= 3) { //Log.Info($"|Wox.Plugin.MigemoSearch|Query beafore=<{ keyword }>"); Regex regex = _migemo_api.GetRegex(keyword); keyword = "@" + regex.ToString(); // @ is regex prefix //Log.Info($"|Wox.Plugin.MigemoSearch|Query after=<{ keyword }>"); } var searchList = _everything_api.Search(keyword, maxCount: _settings.MaxSearchCount).ToList(); foreach (var s in searchList) { var path = s.FullPath; string workingDir = null; if (_settings.UseLocationAsWorkingDir) { workingDir = Path.GetDirectoryName(path); } Result r = new Result(); r.Title = Path.GetFileName(path); r.SubTitle = keyword; r.IcoPath = path; r.Action = c => { bool hide; try { Process.Start(new ProcessStartInfo { FileName = path, UseShellExecute = true, WorkingDirectory = workingDir }); hide = true; } catch (Win32Exception) { var name = $"Plugin: {_context.CurrentPluginMetadata.Name}"; var message = "Can't open this file"; _context.API.ShowMsg(name, message, string.Empty); hide = false; } return(hide); }; r.ContextData = s; results.Add(r); } } catch (IPCErrorException) { results.Add(new Result { Title = _context.API.GetTranslation("wox_plugin_migemosearch_is_not_running"), IcoPath = "Images\\warning.png" }); } catch (Exception e) { results.Add(new Result { Title = _context.API.GetTranslation("wox_plugin_migemosearch_query_error"), SubTitle = e.Message, Action = _ => { Clipboard.SetText(e.Message + "\r\n" + e.StackTrace); _context.API.ShowMsg(_context.API.GetTranslation("wox_plugin_migemosearch_copied"), null, string.Empty); return(false); }, IcoPath = "Images\\error.png" }); } } _everything_api.Reset(); return(results); }