public static int NaturalCompare(string a, string b) { RegularExpression regex = new RegularExpression("[0-9]+"); string[] aa = regex.Exec(a), bb = regex.Exec(b); if (aa != null && bb != null) { string aaa = a.Substr(0, a.IndexOf(aa[0])), bbb = b.Substr(0, b.IndexOf(bb[0])); if (aaa == bbb) { if (aa[0] == bb[0]) { return NaturalCompare(a.Substr(aaa.Length + aa[0].Length), b.Substr(bbb.Length + bb[0].Length)); } else { int ia = int.Parse(aa[0], 10), ib = int.Parse(bb[0], 10); if (ia == ib) { return bb[0].Length - aa[0].Length; } else { return ia - ib; } } } } return a.CompareTo(b); }
void CheckForEmailAddress() { Trace.Write("CheckingForEmailAddress"); RegularExpression regex = new RegularExpression(EmailRegex); string email = selector.Text.Trim(); if (regex.Test(email)) { Suggestion suggestion = new Suggestion(); suggestion.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + selector.Text.Trim() + " as a buddy", "When they join DontStayIn they will be added as one of your buddies. If you type a name after the email address you can use that in future to find this person."); suggestion.text = selector.Text; suggestion.value = "{'email': '" + selector.Text.Escape() + "'}"; suggestion.priority = selector.Text.Length * 100; for (int i = 0; i < selector.Suggestions.Count; i++) { if (selector.Suggestions[i].value.StartsWith("{'email': ")) { selector.Suggestions.RemoveAt(i); break; } } selector.AddSuggestion(suggestion); selector.DisplaySuggestionsInPopupMenu(); } if (oldOnSuggestionsRequested != null) oldOnSuggestionsRequested(); }
internal TokenInfo(RegularExpression definition, Lexicon lexicon, Lexer state, Token tag) { Lexicon = lexicon; Definition = definition; State = state; Tag = tag; }
public object Validate(string value, ValidationContext context) { if (ValidationUtil.StringIsNullOrEmpty(value)) { return true; // let the RequiredValidator handle this case } RegularExpression regExp = new RegularExpression(_pattern); string[] matches = regExp.Exec(value); return (!ValidationUtil.ArrayIsNullOrEmpty(matches) && matches[0].Length == value.Length); }
public Token DefineToken(RegularExpression regex, string description) { CodeContract.RequiresArgumentNotNull(regex, "regex"); int indexInState = m_tokens.Count; TokenInfo token = Lexicon.AddToken(regex, this, indexInState, description); m_tokens.Add(token); return token.Tag; }
public string Render(Dictionary data) { Dictionary transformed = TransformData(data); string itemTemplate = Document.GetElementById(view.clientId).InnerHTML; foreach (DictionaryEntry de in transformed) { RegularExpression regex = new RegularExpression("{" + de.Key + @"}", "g"); itemTemplate = itemTemplate.Unescape().Replace(regex, de.Value.ToString()); } return itemTemplate; }
public void RegularExpressionProducesRegularExpression() { var expression = new RegularExpression("/regularexpression/i"); Assert.AreEqual("/regularexpression/i", expression.Value); Assert.AreEqual("/regularexpression/i;", expression.ToString()); expression.Value = "/reg/"; Assert.AreEqual("/reg/;", expression.ToString()); }
public string Render(Dictionary<object, object> data) { Dictionary<object, object> transformed = TransformData(data); string itemTemplate = Document.GetElementById(view.clientId).InnerHTML; foreach (object key in transformed) { RegularExpression regex = new RegularExpression("{" + key.ToString() + @"}", "g"); itemTemplate = itemTemplate.Unescape().ReplaceRegex(regex, transformed[key].ToString()); } return itemTemplate; }
void CheckForEmailAddresses() { Trace.Write("CheckingForEmailAddresses"); RegularExpression regExp = new RegularExpression(@"\s|,|;| +", "g"); string text = selector.Text.Replace(regExp, " "); while (text.IndexOf(" ") > -1) { text = text.Replace(" ", " "); } text = text.Trim(); for (int i = selector.Suggestions.Count - 1; i > -1; i--) { Trace.Write(selector.Suggestions[i].value); if (selector.Suggestions[i].value.StartsWith("{'emails': ")) { selector.Suggestions.RemoveAt(i); break; } } RegularExpression regex = new RegularExpression(EmailsRegex); if (regex.Test(text)) { selector.Text = text; selector.Suggestions.Clear(); string[] emails = text.Split(" "); Suggestion suggestion = new Suggestion(); suggestion.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + emails.Length + " email addresses as buddies", "Next time you want to include these email addresses, just add all your buddies and they will be included."); suggestion.text = emails.Length + " email addresses as buddies"; suggestion.value = "{'emails': '" + text.Escape() + "', 'buddies':'true'}"; suggestion.priority = selector.Text.Length * 100; selector.AddSuggestion(suggestion); Suggestion suggestion2 = new Suggestion(); suggestion2.html = GetPicTitleDetailTemplateHtml(@"/gfx/icon40-inbox.png", "Add " + emails.Length + " email addresses, but NOT as buddies", "Next time you want to include these email addresses you'll have to copy them in again"); suggestion2.text = emails.Length + " email addresses"; suggestion2.value = "{'emails': '" + text.Escape() + "', 'buddies':'false'}"; suggestion2.priority = selector.Text.Length * 100; selector.AddSuggestion(suggestion2); selector.DisplaySuggestionsInPopupMenu(); } if (oldOnSuggestionsRequested != null) oldOnSuggestionsRequested(); }
public void OnNavigatedTo(NavigationContext navigationContext) { var id = navigationContext.Parameters["Edit"]; if (id != null) { var exp = libraryRepository.GetRegularExpressionById(id.ToString()); this.RegularExpression = exp; this.IsAddingNewItem = false; } else { var regexPattern = navigationContext.Parameters["Add"]; if (regexPattern != null) { var exp = new RegularExpression { Expression = regexPattern.ToString() }; this.RegularExpression = exp; this.IsAddingNewItem = true; } } this.navigationJournal = navigationContext.NavigationService.Journal; }
public static string[] Match(this string str, RegularExpression regex) { return null; }
public void SetUp() { regularExpression = new RegularExpression(); }
private void AdminUserChanged(jQueryEvent e) { RegularExpression regex = new RegularExpression("[^a-zA-Z0-9]"); string username = jQuery.Select("#install-admin-username").GetValue(); if (username == "" || regex.Test(username)) { jQuery.Select("#install-admin-username-check").Hide(); } else { jQuery.Select("#install-admin-username-check").Show(); } }
public string ReplaceRegex(RegularExpression regex, string replaceText) { return null; }
public int Search(RegularExpression regex) { return 0; }
void dateYearTextBoxKeyUpChange(bool change) { try { RegularExpression regex = new RegularExpression("[^0-9]", "g"); if (!regex.Test(view.DateYearTextBox.Value)) { int newYear = int.Parse(view.DateYearTextBox.Value, 10); if (newYear > 1900 && newYear < 2100) { if (newYear != Date.Year) { dateRefreshDays(newYear, Date.Month); int newDay = OptionDateDay ? getValueInt(view.DateDayDropDown) : 0; DateStub newDate = new DateStub(newYear, Date.Month, newDay); addHistory("Date", newDate.ToString()); //Moved to navigateDate //initialiseEventDropDown(); } } else { if (change) view.DateYearTextBox.Value = Date.Year.ToString(); } } else { if (change) view.DateYearTextBox.Value = Date.Year.ToString(); } } catch { if (change) view.DateYearTextBox.Value = Date.Year.ToString(); } }
private void SelectedRegularExpressionEventHandler(RegularExpression exp) { if (exp != null) { RegexPattern = exp.Expression; } }
internal Token AddToken(RegularExpression definition, LexerState state, int indexInState, string description) { int index = m_tokenList.Count; Token token = new Token(definition, this, index, state, description); m_tokenList.Add(token); return token; }
public static int Search(this string str, RegularExpression regex) { return 0; }
public static string Replace(this string str, RegularExpression regex, string newString) { return null; }
public string[] Match(RegularExpression regex) { return null; }
public Token DefineToken(RegularExpression regex) { return DefineToken(regex, null); }
public string ReplaceRegex(RegularExpression regex, StringReplaceCallback callback) { return null; }
public static RegularExpression generateRandomRegex(char[] alfabet, int depth=5) { bool wasmulti = false; RegularExpression begin = new RegularExpression("a"); for (int c = 0; c < depth; c++) { int type; if (wasmulti) type = r.Next(1, 2); else type = r.Next(1, 4); wasmulti = false; switch (type) { case 1: //ONE & DOT string terminal = ""; for (int i = 0; i < r.Next(1, 5); i++) { terminal = terminal + alfabet[r.Next(0, alfabet.Count())]; } begin = begin.dot(new RegularExpression(terminal)); break; case 2: //ONE & OR terminal = ""; for (int i = 0; i < r.Next(1, 5); i++) { terminal = terminal + alfabet[r.Next(0, alfabet.Count())]; } begin = begin.or(new RegularExpression(terminal)); break; case 3: //PLUS begin = begin.plus(); wasmulti = true; break; case 4: //STAR begin = begin.star(); wasmulti = true; break; } } return begin; }
public string[] Split(RegularExpression regex, int limit) { return null; }
public static void testRegExpThompson() { RegularExpression exp1, exp2, exp3, exp4, exp5, a, b, c, all, why; a = new RegularExpression("a"); b = new RegularExpression("b"); c = new RegularExpression("c"); //exp 1 (baa) exp1 = new RegularExpression("baa"); //exp 2 (ac) exp2 = new RegularExpression("ac"); //exp 4 (baa)+ exp4 = exp1.plus(); //exp 5 (ac)* exp5 = exp2.star(); //exp 3 (a|b|c)* exp3 = (a.or(b).or(c)).star(); //all (a|b|c)* (baa)+ (ca)* all = exp3.dot(exp4.dot(exp5)); why = new RegularExpression("baa").plus().star().plus(); foreach (String o in all.getLanguage(5)) { Console.Write(o + " "); } Automata<String> auto = new Automata<String>(); int num = 0; why.regexToNDFA(ref num,ref auto); return; }
internal TokenInfo AddToken(RegularExpression definition, Lexer state, int indexInState, string description) { int index = m_tokenList.Count; Token tag = new Token(index, description ?? definition.ToString(), state.Index); TokenInfo token = new TokenInfo(definition, this, state, tag); m_tokenList.Add(token); return token; }
public static void testRegularExpression() { RegularExpression exp1, exp2, exp3, exp4, exp5, a, b, all; a = new RegularExpression("a"); b = new RegularExpression("b"); // exp 1 baa exp1 = new RegularExpression("baa"); // exp 2 bb exp2 = new RegularExpression("bb"); // exp 3 baa | bb exp3 = exp1.or(exp2); //all = (a|b)* all = (a.or(b)).star(); // exp 4 (baa | bb)+ exp4 = exp3.plus(); // exp 4 (baa | bb)+ (a|b)* exp5 = exp4.dot(all); Console.WriteLine(exp5.ToString()); #region PRINTREGULAREXPRESSION Console.WriteLine("taal van (baa):"); foreach (String o in exp1.getLanguage(5)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); Console.WriteLine("taal van (bb):"); foreach (String o in exp2.getLanguage(5)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); Console.WriteLine("taal van (baa | bb):"); foreach (String o in exp3.getLanguage(5)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); Console.WriteLine("taal van (a|b)*:"); foreach (String o in all.getLanguage(5)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); Console.WriteLine("taal van (baa | bb)+:"); foreach (String o in exp5.getLanguage(5)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); Console.WriteLine("taal van (baa | bb)+ (a|b)*:"); foreach (String o in exp5.getLanguage(6)) { Console.Write(o + " "); } Console.WriteLine(""); Console.ReadLine(); #endregion }
private void SubmitButtonClicked(jQueryEvent e) { // return if anything is checking if (MySqlSettingChecking || SevenZipSettingChecking) { return; } if (!AllRequiredComponentLoaded) { ErrorModal.ShowError(Strings.Get("MissingRequiredComponent")); return; } if (!CanEnableZip && !CanEnableRar && !CanEnablePdf) { ErrorModal.ShowError(Strings.Get("NeedFileSupport")); return; } string username = jQuery.Select("#install-admin-username").GetValue(); string password = jQuery.Select("#install-admin-password").GetValue(); string password2 = jQuery.Select("#install-admin-password2").GetValue(); RegularExpression regex = new RegularExpression("[^a-zA-Z0-9]"); if (username == "" || regex.Test(username) || password.Length < 8 || password != password2) { ErrorModal.ShowError(Strings.Get("AdminUserSettingFailed")); return; } InstallRequest request = new InstallRequest(); request.mysqlServer = jQuery.Select("#install-mysql-server").GetValue(); request.mysqlPort = int.Parse(jQuery.Select("#install-mysql-port").GetValue(), 10); request.mysqlUser = jQuery.Select("#install-mysql-username").GetValue(); request.mysqlPassword = jQuery.Select("#install-mysql-password").GetValue(); request.mysqlDatabase = jQuery.Select("#install-mysql-database").GetValue(); request.sevenZipPath = jQuery.Select("#install-sevenzip-dll").GetValue(); request.zip = jQuery.Select("#install-zip-checkbox").Is(":checked"); request.rar = jQuery.Select("#install-rar-checkbox").Is(":checked"); request.pdf = jQuery.Select("#install-pdf-checkbox").Is(":checked"); request.admin = username; request.password = password; request.password2 = password2; new InstallingModal().SendInstallRequest(request); }
public static void testRegularExpressionThompson2() { //This is the regular expression ( (a|b|c|d)|(ab|ad|bc) )+ (aab) (c|cad|cb)* RegularExpression exp1, exp2, exp3, exp4, a, b, c, d, ab, ad, bc, abb, cad, cb,all; a = new RegularExpression("a"); b = new RegularExpression("b"); c = new RegularExpression("c"); d = new RegularExpression("d"); ab = new RegularExpression("ab"); ad = new RegularExpression("ad"); bc = new RegularExpression("bc"); abb = new RegularExpression("abb"); cad = new RegularExpression("cad"); cb = new RegularExpression("cb"); // (a|b|c|d) exp1 = (a.or(b).or(c).or(d)); // (ab|ad|bc) exp2 = (ab.or(ad).or(bc)); // (c|cad|cb)* exp3 = (c.or(cad).or(cb).star()); // ( (a|b|c|d) | (ab|ad|bc) )+ exp4 = (exp1.or(exp2).plus()); // Merge all = exp4.dot(abb.dot(exp3)); Automata<String> auto = new Automata<String>(); int num = 0; all.regexToNDFA(ref num, ref auto); generateAutomataImage(auto); return; }