public estadoAtual buscaDicionario(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs e) { estadoAtual estado = new estadoAtual(); estado.resultados = new List <string>(); constroiRegex(); if (worker.CancellationPending) { e.Cancel = true; } else { foreach (string linhaAtual in arquivo) { if (buscaPalavra(linhaAtual.ToLowerInvariant()) == true) //filtro preliminar, mais rápido que uma regex { if (System.Text.RegularExpressions.Regex.IsMatch(linhaAtual, regexEscolhida, RegexOptions.IgnoreCase)) //segundo filtro com uma regex { estado.qtResultados++; if (linhaAtual.EndsWith("(P)/"))//ordena por popularidade { estado.resultados.Insert(0, linhaAtual); } else { estado.resultados.Add(linhaAtual); } } } } } return(estado); }
public estadoAtual buscaExemplos(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs e) { estadoAtual estado = new estadoAtual(); if (worker.CancellationPending) { e.Cancel = true; } else { constroiRegex(); estado.resultados = new List <string>(); estado.qtResultados = 0; string linhaTemp = ""; bool isASCII = termoBusca[0] <= 127; foreach (string linhaAtual in arquivo) { if (linhaAtual[0] == 'A') { if (isASCII) { if (buscaPalavra(linhaAtual.ToLowerInvariant()) == true) { if (System.Text.RegularExpressions.Regex.IsMatch(linhaAtual, regexEscolhida, RegexOptions.IgnoreCase)) { estado.qtResultados++; string[] linhas = linhaAtual.Split('\t'); //remove "A: " estado.resultados.Add(linhas[0].Substring(3)); foreach (Match match in Regex.Matches(linhas[1], regexB, RegexOptions.IgnoreCase)) { estado.resultados.Add(match.Groups["traducao"].ToString()); } } } } linhaTemp = linhaAtual; } else { if (linhaAtual[0] == 'B') { if (buscaPalavra(linhaAtual) == true) { estado.qtResultados++; string[] linhas = linhaTemp.Split('\t'); //remove "A: " estado.resultados.Add(linhas[0].Substring(3)); foreach (Match match in Regex.Matches(linhas[1], regexB, RegexOptions.IgnoreCase)) { estado.resultados.Add(match.Groups["traducao"].ToString()); } } } } } } return(estado); }