mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 22:42:38 +01:00
Now allows for phrases in user dictionary + Encoding methods in Utilities
git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@264 99eadd0c-20b8-1223-b5c4-2a2b2df33de2
This commit is contained in:
parent
ee33a68d7b
commit
17a0e86e0c
1
src/Forms/Main.Designer.cs
generated
1
src/Forms/Main.Designer.cs
generated
@ -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
|
||||
//
|
||||
|
@ -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,7 +2777,8 @@ 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");
|
||||
// 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("<br />", Environment.NewLine);
|
||||
// update.Text = HttpUtility.HtmlDecode(update.Text).Replace("<br />", Environment.NewLine);
|
||||
update.Text = Utilities.HtmlDecode(update.Text).Replace("<br />", Environment.NewLine);
|
||||
}
|
||||
if (update.User.Ip != _networkSession.CurrentUser.Ip || update.User.UserName != _networkSession.CurrentUser.UserName)
|
||||
{
|
||||
@ -8753,5 +8758,21 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
List<string> _skipAllList = new List<string>();
|
||||
Dictionary<string, string> _changeAllDictionary = new Dictionary<string, string>();
|
||||
List<string> _userWordList = new List<string>();
|
||||
List<string> _userPhraseList = new List<string>();
|
||||
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<string>();
|
||||
_userPhraseList = new List<string>();
|
||||
_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<string>();
|
||||
_userPhraseList = new List<string>();
|
||||
_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
|
||||
{
|
||||
|
@ -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("<br />", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds));
|
||||
Subtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("<br />", 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("<br />", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds));
|
||||
OriginalSubtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("<br />", 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("<br />", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds));
|
||||
Subtitle.Paragraphs.Add(new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("<br />", 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("<br />", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds);
|
||||
Paragraph p = new Paragraph(Utilities.HtmlDecode(sequence.Text).Replace("<br />", Environment.NewLine), sequence.StartMilliseconds, sequence.EndMilliseconds);
|
||||
Subtitle.Paragraphs.Add(p);
|
||||
}
|
||||
Subtitle.Renumber(1);
|
||||
|
@ -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
|
||||
{
|
||||
@ -1530,21 +1530,6 @@ 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
|
||||
@ -1697,5 +1682,393 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HTML-encodes a string
|
||||
/// </summary>
|
||||
/// <param name="text">Text string to encode</param>
|
||||
/// <returns>HTML-encoded text</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HTML-decodes a string
|
||||
/// </summary>
|
||||
/// <param name="text">Text string to encode</param>
|
||||
/// <returns>HTML-decoded text</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UrlEncodes a string without the requirement for System.Web
|
||||
/// </summary>
|
||||
public static string UrlEncode(string text)
|
||||
{
|
||||
return System.Uri.EscapeDataString(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UrlDecodes a string without requiring System.Web
|
||||
/// </summary>
|
||||
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<string> 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user