diff --git a/src/Forms/Main.Designer.cs b/src/Forms/Main.Designer.cs index 6260364be..b9fe7be2f 100644 --- a/src/Forms/Main.Designer.cs +++ b/src/Forms/Main.Designer.cs @@ -1272,6 +1272,7 @@ this.toolStripMenuItemSpellCheckMain.Name = "toolStripMenuItemSpellCheckMain"; this.toolStripMenuItemSpellCheckMain.Size = new System.Drawing.Size(80, 20); this.toolStripMenuItemSpellCheckMain.Text = "Spell check"; + this.toolStripMenuItemSpellCheckMain.DropDownOpening += new System.EventHandler(this.toolStripMenuItemSpellCheckMain_DropDownOpening); // // spellCheckToolStripMenuItem // diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 77b17c17f..fc36954dd 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -1741,6 +1741,9 @@ namespace Nikse.SubtitleEdit.Forms { ReloadFromSourceView(); SaveSubtitle(GetCurrentSubtitleFormat()); + + if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0) + saveOriginalToolStripMenuItem_Click(null, null); } private void ToolStripButtonSaveAsClick(object sender, EventArgs e) @@ -2774,8 +2777,9 @@ namespace Nikse.SubtitleEdit.Forms private static string GetTranslateStringFromNikseDk(string input) { // string url = String.Format("http://localhost:2782/mt/Translate.aspx?text={0}&langpair={1}", HttpUtility.UrlEncode(input), "svda"); - string url = String.Format("http://www.nikse.dk/mt/Translate.aspx?text={0}&langpair={1}", HttpUtility.UrlEncode(input), "svda"); - var webClient = new WebClient {Proxy = Utilities.GetProxy(), Encoding = System.Text.Encoding.UTF8}; +// string url = String.Format("http://www.nikse.dk/mt/Translate.aspx?text={0}&langpair={1}", HttpUtility.UrlEncode(input), "svda"); + string url = String.Format("http://www.nikse.dk/mt/Translate.aspx?text={0}&langpair={1}", Utilities.UrlEncode(input), "svda"); + var webClient = new WebClient { Proxy = Utilities.GetProxy(), Encoding = System.Text.Encoding.UTF8 }; return webClient.DownloadString(url); } @@ -7086,13 +7090,13 @@ namespace Nikse.SubtitleEdit.Forms private void buttonGoogleIt_Click(object sender, EventArgs e) { - System.Diagnostics.Process.Start("http://www.google.com/#q=" + HttpUtility.UrlEncode(textBoxSearchWord.Text)); + System.Diagnostics.Process.Start("http://www.google.com/#q=" + Utilities.UrlEncode(textBoxSearchWord.Text)); } private void buttonGoogleTranslateIt_Click(object sender, EventArgs e) { string languageId = Utilities.AutoDetectGoogleLanguage(_subtitle); - System.Diagnostics.Process.Start("http://translate.google.com/#auto|" + languageId + "|" + HttpUtility.UrlEncode(textBoxSearchWord.Text)); + System.Diagnostics.Process.Start("http://translate.google.com/#auto|" + languageId + "|" + Utilities.UrlEncode(textBoxSearchWord.Text)); } private void ButtonPlayCurrentClick(object sender, EventArgs e) @@ -7640,7 +7644,7 @@ namespace Nikse.SubtitleEdit.Forms { if (url.Contains("{0}")) { - url = string.Format(url, HttpUtility.UrlEncode(textBoxSearchWord.Text)); + url = string.Format(url, Utilities.UrlEncode(textBoxSearchWord.Text)); } System.Diagnostics.Process.Start(url); } @@ -8065,7 +8069,8 @@ namespace Nikse.SubtitleEdit.Forms { if (!update.Text.Contains(Environment.NewLine)) update.Text = update.Text.Replace("\n", Environment.NewLine); - update.Text = HttpUtility.HtmlDecode(update.Text).Replace("
", Environment.NewLine); +// update.Text = HttpUtility.HtmlDecode(update.Text).Replace("
", Environment.NewLine); + update.Text = Utilities.HtmlDecode(update.Text).Replace("
", Environment.NewLine); } if (update.User.Ip != _networkSession.CurrentUser.Ip || update.User.UserName != _networkSession.CurrentUser.UserName) { @@ -8751,6 +8756,22 @@ namespace Nikse.SubtitleEdit.Forms labelCharactersPerSecond.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelCharactersPerSecond.Width); labelTextLineTotal.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelTextLineTotal.Width); + } + + private void toolStripMenuItemSpellCheckMain_DropDownOpening(object sender, EventArgs e) + { + if (Configuration.Settings.General.SpellChecker.ToLower().Contains("word")) + { + toolStripSeparator9.Visible = false; + GetDictionariesToolStripMenuItem.Visible = false; + addWordToNamesetcListToolStripMenuItem.Visible = false; + } + else + { + toolStripSeparator9.Visible = true; + GetDictionariesToolStripMenuItem.Visible = true; + addWordToNamesetcListToolStripMenuItem.Visible = true; + } } } diff --git a/src/Forms/SpellCheck.cs b/src/Forms/SpellCheck.cs index 5e9e11f7e..4576e8456 100644 --- a/src/Forms/SpellCheck.cs +++ b/src/Forms/SpellCheck.cs @@ -32,6 +32,7 @@ namespace Nikse.SubtitleEdit.Forms List _skipAllList = new List(); Dictionary _changeAllDictionary = new Dictionary(); List _userWordList = new List(); + List _userPhraseList = new List(); XmlDocument _userWordDictionary = new XmlDocument(); string _prefix = string.Empty; string _postfix = string.Empty; @@ -216,12 +217,19 @@ namespace Nikse.SubtitleEdit.Forms _languageName = LanguageString; string dictionary = Utilities.DictionaryFolder + _languageName; _userWordList = new List(); + _userPhraseList = new List(); _userWordDictionary = new XmlDocument(); if (File.Exists(Utilities.DictionaryFolder + _languageName + "_user.xml")) { _userWordDictionary.Load(Utilities.DictionaryFolder + _languageName + "_user.xml"); foreach (XmlNode node in _userWordDictionary.DocumentElement.SelectNodes("word")) - _userWordList.Add(node.InnerText.ToLower()); + { + string word = node.InnerText.Trim().ToLower(); + if (word.Contains(" ")) + _userPhraseList.Add(word); + else + _userWordList.Add(word); + } } else { @@ -359,9 +367,13 @@ namespace Nikse.SubtitleEdit.Forms if (_userWordList.IndexOf(ChangeWord) < 0) { _noOfAddedWords++; - _userWordList.Add(ChangeWord.ToLower()); + string s = ChangeWord.Trim().ToLower(); + if (s.Contains(" ")) + _userPhraseList.Add(s); + else + _userWordList.Add(s); XmlNode node = _userWordDictionary.CreateElement("word"); - node.InnerText = ChangeWord.Trim().ToLower(); + node.InnerText = s; _userWordDictionary.DocumentElement.AppendChild(node); _userWordDictionary.Save(_dictionaryFolder + _languageName + "_user.xml"); } @@ -523,6 +535,10 @@ namespace Nikse.SubtitleEdit.Forms { _noOfNamesEtc++; } + else if (Utilities.IsWordInUserPhrases(_userPhraseList, _wordsIndex, _words)) + { + _noOfCorrectWords++; + } else { bool correct = _hunspell.Spell(_currentWord); @@ -660,12 +676,19 @@ namespace Nikse.SubtitleEdit.Forms } _userWordList = new List(); + _userPhraseList = new List(); _userWordDictionary = new XmlDocument(); if (File.Exists(dictionaryFolder + _languageName + "_user.xml")) { _userWordDictionary.Load(dictionaryFolder + _languageName + "_user.xml"); foreach (XmlNode node in _userWordDictionary.DocumentElement.SelectNodes("word")) - _userWordList.Add(node.InnerText.ToLower()); + { + string word = node.InnerText.Trim().ToLower(); + if (word.Contains(" ")) + _userPhraseList.Add(word); + else + _userWordList.Add(word); + } } else { diff --git a/src/Logic/Networking/NikseWebServiceSession.cs b/src/Logic/Networking/NikseWebServiceSession.cs index c4ecba55c..065211456 100644 --- a/src/Logic/Networking/NikseWebServiceSession.cs +++ b/src/Logic/Networking/NikseWebServiceSession.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Text; -using System.Web; namespace Nikse.SubtitleEdit.Logic.Networking { @@ -104,7 +103,7 @@ namespace Nikse.SubtitleEdit.Logic.Networking DateTime updateTime; Subtitle = new Subtitle(); foreach (var sequence in _seWs.GetSubtitle(sessionKey, out tempFileName, out updateTime)) - Subtitle.Paragraphs.Add(new Paragraph(HttpUtility.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); + Subtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); FileName = tempFileName; OriginalSubtitle = new Subtitle(); @@ -112,7 +111,7 @@ namespace Nikse.SubtitleEdit.Logic.Networking if (sequences != null) { foreach (var sequence in sequences) - OriginalSubtitle.Paragraphs.Add(new Paragraph(HttpUtility.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); + OriginalSubtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); } SessionId = sessionKey; @@ -162,7 +161,7 @@ namespace Nikse.SubtitleEdit.Logic.Networking if (sequences != null) { foreach (var sequence in sequences) - Subtitle.Paragraphs.Add(new Paragraph(HttpUtility.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); + Subtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds)); } return Subtitle; } @@ -175,7 +174,7 @@ namespace Nikse.SubtitleEdit.Logic.Networking var sequences = _seWs.GetSubtitle(SessionId, out FileName, out _seWsLastUpdate); foreach (var sequence in sequences) { - Paragraph p = new Paragraph(HttpUtility.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds); + Paragraph p = new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("
", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds); Subtitle.Paragraphs.Add(p); } Subtitle.Renumber(1); diff --git a/src/Logic/Utilities.cs b/src/Logic/Utilities.cs index 89761d354..216ec70dd 100644 --- a/src/Logic/Utilities.cs +++ b/src/Logic/Utilities.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Globalization; using System.IO; using System.Net; @@ -12,7 +13,6 @@ using Nikse.SubtitleEdit.Controls; using Nikse.SubtitleEdit.Forms; using Nikse.SubtitleEdit.Logic.SubtitleFormats; using Nikse.SubtitleEdit.Logic.VideoPlayers; -using System.Drawing; namespace Nikse.SubtitleEdit.Logic { @@ -225,7 +225,7 @@ namespace Nikse.SubtitleEdit.Logic public static string ReadTextFileViaUrlAndProxyIfAvailable(string url) { - var wc = new WebClient {Proxy = GetProxy()}; + var wc = new WebClient { Proxy = GetProxy() }; var ms = new MemoryStream(wc.DownloadData(url)); var reader = new StreamReader(ms); return reader.ReadToEnd().Trim(); @@ -246,19 +246,19 @@ namespace Nikse.SubtitleEdit.Logic } else proxy.UseDefaultCredentials = true; - + return proxy; } return null; } private static bool IsPartOfNumber(string s, int position) - { + { if (",.".Contains(s[position].ToString())) { - if (position > 0 && position < s.Length-1) + if (position > 0 && position < s.Length - 1) { - return "1234567890".Contains(s[position-1].ToString()) && "1234567890".Contains(s[position+1].ToString()); + return "1234567890".Contains(s[position - 1].ToString()) && "1234567890".Contains(s[position + 1].ToString()); } } return false; @@ -297,13 +297,13 @@ namespace Nikse.SubtitleEdit.Logic { if (mid + j + 4 < s.Length) { - if (s[mid + j] == '-' && s[mid + j + 1] == ' ' && s[mid + j- 1] == ' ') + if (s[mid + j] == '-' && s[mid + j + 1] == ' ' && s[mid + j - 1] == ' ') { string rest = s.Substring(mid + j + 1).TrimStart(); if (rest.Length > 0 && (rest.Substring(0, 1) == rest.Substring(0, 1).ToUpper())) - { - splitPos = mid + j; - break; + { + splitPos = mid + j; + break; } } } @@ -386,7 +386,7 @@ namespace Nikse.SubtitleEdit.Logic splitPos = mid; s = s.Insert(mid - 1, "-"); } - if (splitPos < s.Length-2) + if (splitPos < s.Length - 2) s = s.Substring(0, splitPos).TrimEnd() + Environment.NewLine + s.Substring(splitPos).Trim(); return s.TrimEnd(); } @@ -447,7 +447,7 @@ namespace Nikse.SubtitleEdit.Logic while (s.ToLower().Contains(""), startIndex + 4); + int endIndex = Math.Max(s.IndexOf(">"), startIndex + 4); s = s.Remove(startIndex, (endIndex - startIndex) + 1); } return s; @@ -455,7 +455,7 @@ namespace Nikse.SubtitleEdit.Logic public static Encoding GetEncodingFromFile(string fileName) { - Encoding encoding = Encoding.Default; + Encoding encoding = Encoding.Default; try { var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); @@ -464,13 +464,13 @@ namespace Nikse.SubtitleEdit.Logic file.Position = 0; file.Read(bom, 0, 12); if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf) - encoding = Encoding.UTF8; + encoding = Encoding.UTF8; else if (bom[0] == 0xff && bom[1] == 0xfe) - encoding = Encoding.Unicode; + encoding = Encoding.Unicode; else if (bom[0] == 0xfe && bom[1] == 0xff) // utf-16 and ucs-2 - encoding = Encoding.BigEndianUnicode; + encoding = Encoding.BigEndianUnicode; else if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) // ucs-4 - encoding = Encoding.UTF32; + encoding = Encoding.UTF32; else if (encoding == Encoding.Default && file.Length > 12) { int length = (int)file.Length; @@ -535,7 +535,7 @@ namespace Nikse.SubtitleEdit.Logic byte b = buffer[i]; if (b > 127) { - if (b >= 194 && b <=223 && buffer[i+1] >= 128 && buffer[i+1] <= 191) + if (b >= 194 && b <= 223 && buffer[i + 1] >= 128 && buffer[i + 1] <= 191) { // 2-byte sequence utf8Count++; i++; @@ -1300,7 +1300,7 @@ namespace Nikse.SubtitleEdit.Logic word = word.Trim(); if (word.Length > 1) { - var localNamesEtc = new List(); + var localNamesEtc = new List(); string userNamesEtcXmlFileName = LoadLocalNamesEtc(localNamesEtc, localNamesEtc, languageName); if (localNamesEtc.Contains(word)) @@ -1322,14 +1322,14 @@ namespace Nikse.SubtitleEdit.Logic { XmlNode node = namesEtcDoc.CreateElement("name"); node.InnerText = name; - de.AppendChild(node); + de.AppendChild(node); } namesEtcDoc.Save(userNamesEtcXmlFileName); } return true; } return false; - } + } public static string LoadNamesEtcWordLists(List namesEtcList, List namesEtcMultiWordList, string languageName) { @@ -1452,7 +1452,7 @@ namespace Nikse.SubtitleEdit.Logic string s = string.Empty; if (uppercase) - s += Configuration.Settings.General.UppercaseLetters; + s += Configuration.Settings.General.UppercaseLetters; if (lowercase) s += Configuration.Settings.General.UppercaseLetters.ToLower(); @@ -1498,7 +1498,7 @@ namespace Nikse.SubtitleEdit.Logic case 20: return Color.Maroon; default: return Color.Black; - } + } } internal static int GetNumber0To7FromUserName(string userName) @@ -1514,7 +1514,7 @@ namespace Nikse.SubtitleEdit.Logic return (int)(number % 8); } - internal static string GetRegExGroup( string regEx) + internal static string GetRegExGroup(string regEx) { int start = regEx.IndexOf("(?<"); if (start >= 0 && regEx.IndexOf(")", start) > start) @@ -1530,27 +1530,12 @@ namespace Nikse.SubtitleEdit.Logic return null; } - internal static string HtmlEncode(string value) - { - // call the normal HtmlEncode first - char[] chars = System.Web.HttpUtility.HtmlEncode(value).ToCharArray(); - StringBuilder encodedValue = new StringBuilder(); - foreach (char c in chars) - { - if (c > 127) // above normal ASCII - encodedValue.Append("&#" + (int)c + ";"); - else - encodedValue.Append(c); - } - return encodedValue.ToString(); - } - internal static string LowerCaseVowels - { - get + { + get { return "aeiouyæøåéóáôèòæøåäöïɤəɛʊʉɨ"; - } + } } internal static void SetButtonHeight(Control control, int newHeight, int level) @@ -1696,6 +1681,394 @@ namespace Nikse.SubtitleEdit.Logic } return null; } - + + /// + /// HTML-encodes a string + /// + /// Text string to encode + /// HTML-encoded text + internal static string HtmlEncode(string text) + { + if (text == null) + return string.Empty; + StringBuilder sb = new StringBuilder(text.Length); + int len = text.Length; + for (int i = 0; i < len; i++) + { + switch (text[i]) + { + case '<': + sb.Append("<"); + break; + case '>': + sb.Append(">"); + break; + case '"': + sb.Append("""); + break; + case '&': + sb.Append("&"); + break; + default: + if (text[i] > 127) + sb.Append("&#" + (int)text[i] + ";"); + else + sb.Append(text[i]); + break; + } + } + return sb.ToString(); + } + + /// + /// HTML-decodes a string + /// + /// Text string to encode + /// HTML-decoded text + internal static string HtmlDecode(string text) + { + if (text == null) + return string.Empty; + + StringBuilder sb = new StringBuilder(text.Length); + + int len = text.Length; + int i = 0; + while (i < len) + { + char c = text[i]; + int nextSemiColon = text.IndexOf(';', i+1); + if (c == '&' && nextSemiColon > 0 && nextSemiColon <= i + 8) + { + string code = text.Substring(i + 1, nextSemiColon - (i+1)); + i += code.Length + 2; + switch (code) // http://www.html-entities.com/ + http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references + { + case "lt": + sb.Append('<'); + break; + case "gt": + sb.Append('>'); + break; + case "quot": + sb.Append('"'); + break; + case "amp": + sb.Append('&'); + break; + case "apos": + sb.Append("'"); + break; + case "nbsp": + sb.Append(" "); + break; + case "ndash": + sb.Append("–"); + break; + case "mdash": + sb.Append("—"); + break; + case "iexcl": + sb.Append("¡"); + break; + case "iquest": + sb.Append("¿"); + break; + case "ldquo": + sb.Append("“"); + break; + case "rdquo": + sb.Append("”"); + break; + case "‘": + sb.Append("‘"); + break; + case "rsquo": + sb.Append("’"); + break; + case "laquo": + sb.Append("«"); + break; + case "raquo": + sb.Append("»"); + break; + case "cent": + sb.Append("¢"); + break; + case "copy": + sb.Append("©"); + break; + case "divide": + sb.Append("÷"); + break; + case "micro": + sb.Append("µ"); + break; + case "middot": + sb.Append("·"); + break; + case "para": + sb.Append("¶"); + break; + case "plusmn": + sb.Append("±"); + break; + case "euro": + sb.Append("€"); + break; + case "pound": + sb.Append("£"); + break; + case "reg": + sb.Append("®"); + break; + case "sect": + sb.Append("§"); + break; + case "trade": + sb.Append("™"); + break; + case "yen": + sb.Append("¥"); + break; + case "aacute": + sb.Append("á "); + break; + case "Aacute": + sb.Append("Á"); + break; + case "agrave": + sb.Append("à"); + break; + case "Agrave": + sb.Append("À"); + break; + case "acirc": + sb.Append("â"); + break; + case "Acirc": + sb.Append("Â"); + break; + case "aring": + sb.Append("å "); + break; + case "Aring": + sb.Append("Å"); + break; + case "atilde": + sb.Append("ã"); + break; + case "Atilde": + sb.Append("Ã"); + break; + case "auml": + sb.Append("ä"); + break; + case "Auml": + sb.Append("Ä"); + break; + case "aelig": + sb.Append("æ"); + break; + case "AElig": + sb.Append("Æ"); + break; + case "ccedil": + sb.Append("ç"); + break; + case "Ccedil": + sb.Append("Ç"); + break; + case "eacute": + sb.Append("é"); + break; + case "Eacute": + sb.Append("É"); + break; + case "egrave": + sb.Append("è"); + break; + case "Egrave": + sb.Append("È"); + break; + case "ecirc": + sb.Append("ê"); + break; + case "Ecirc": + sb.Append("Ê"); + break; + case "euml": + sb.Append("ë"); + break; + case "Euml": + sb.Append("Ë"); + break; + case "iacute": + sb.Append("í"); + break; + case "Iacute": + sb.Append("Í"); + break; + case "igrave": + sb.Append("ì"); + break; + case "Igrave": + sb.Append("Ì"); + break; + case "icirc": + sb.Append("î"); + break; + case "Icirc": + sb.Append("Î"); + break; + case "iuml": + sb.Append("iuml"); + break; + case "Iuml": + sb.Append("Ï"); + break; + case "ntilde": + sb.Append("ñ"); + break; + case "Ntilde": + sb.Append("Ñ"); + break; + case "oacute": + sb.Append("ó"); + break; + case "Oacute": + sb.Append("Ó"); + break; + case "ograve": + sb.Append("ò"); + break; + case "Ograve": + sb.Append("Ò"); + break; + case "ocirc": + sb.Append("ô"); + break; + case "Ocirc": + sb.Append("Ô"); + break; + case "oslash": + sb.Append("ø"); + break; + case "Oslash": + sb.Append("Ø"); + break; + case "otilde": + sb.Append("õ"); + break; + case "Otilde": + sb.Append("Õ"); + break; + case "ouml": + sb.Append("ö"); + break; + case "Ouml": + sb.Append("Ö"); + break; + case "szlig": + sb.Append("ß"); + break; + case "uacute": + sb.Append("ú"); + break; + case "Uacute": + sb.Append("Ú"); + break; + case "ugrave": + sb.Append("ù"); + break; + case "Ugrave": + sb.Append("Ù"); + break; + case "ucirc": + sb.Append("û"); + break; + case "Ucirc": + sb.Append("Û"); + break; + case "uuml": + sb.Append("ü"); + break; + case "Uuml": + sb.Append("Ü"); + break; + case "yuml": + sb.Append("ÿ"); + break; + case "": + sb.Append(""); + break; + default: + code = code.TrimStart('#'); + if (code.StartsWith("x") || code.StartsWith("X")) + { + code = code.TrimStart('x'); + code = code.TrimStart('X'); + try + { + int value = Convert.ToInt32(code, 16); + sb.Append(Convert.ToChar(value)); + } + catch + { + } + } + else if (IsInteger(code)) + { + sb.Append(Convert.ToChar(int.Parse(code))); + } + break; + } + } + else + { + sb.Append(c); + i++; + } + } + return sb.ToString(); + } + + /// + /// UrlEncodes a string without the requirement for System.Web + /// + public static string UrlEncode(string text) + { + return System.Uri.EscapeDataString(text); + } + + /// + /// UrlDecodes a string without requiring System.Web + /// + public static string UrlDecode(string text) + { + // pre-process for + sign space formatting since System.Uri doesn't handle it + // plus literals are encoded as %2b normally so this should be safe + text = text.Replace("+", " "); + return System.Uri.UnescapeDataString(text); + } + + internal static bool IsWordInUserPhrases(List userPhraseList, int index, string[] words) + { + string current = words[index]; + string prev = "-"; + if (index > 0) + prev = words[index-1]; + string next = "-"; + if (index < words.Length-1) + next = words[index+1]; + foreach (string userPhrase in userPhraseList) + { + if (userPhrase == current + " " + next) + return true; + if (userPhrase == prev + " " + current) + return true; + } + return false; + } } } \ No newline at end of file