From 5d9614cbf46da34857e5975e683d92d56a40bdd5 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Thu, 8 Jul 2010 15:21:10 +0000 Subject: [PATCH] Smileys parsing improved --- Builder/IISMainHandler/build.txt | 2 +- Builder/IISUploadHandler/build.txt | 2 +- Common/UBBParser.cs | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt index 26f252b..4aeea8c 100644 --- a/Builder/IISMainHandler/build.txt +++ b/Builder/IISMainHandler/build.txt @@ -1 +1 @@ -649 \ No newline at end of file +650 \ No newline at end of file diff --git a/Builder/IISUploadHandler/build.txt b/Builder/IISUploadHandler/build.txt index be6c136..e41567f 100644 --- a/Builder/IISUploadHandler/build.txt +++ b/Builder/IISUploadHandler/build.txt @@ -1 +1 @@ -383 \ No newline at end of file +384 \ No newline at end of file diff --git a/Common/UBBParser.cs b/Common/UBBParser.cs index 4a8e3db..411487a 100644 --- a/Common/UBBParser.cs +++ b/Common/UBBParser.cs @@ -5,6 +5,7 @@ using System.Text; using System.Web; using System.Text.RegularExpressions; using PJonDevelopment.BBCode; +using System.IO; namespace FLocal.Common { public static class UBBParser { @@ -22,7 +23,7 @@ namespace FLocal.Common { { ":D", "laugh" }, { ";)", "wink" }, { ":p", "tongue" }, - { ":cool:", "cool" }, + /*{ ":cool:", "cool" }, { ":crazy:", "crazy" }, { ":mad:", "mad" }, { ":shocked:", "shocked" }, @@ -30,11 +31,22 @@ namespace FLocal.Common { { ":grin:", "grin" }, { ":ooo:", "ooo" }, { ":confused:", "confused" }, - { ":lol:", "lol" }, + { ":lol:", "lol" },*/ }; private static readonly Dictionary SMILEYS_DATA = (from smile in SMILEYS select new KeyValuePair(new Regex("(^|\\s|>)" + Regex.Escape(smile.Key) + "($|\\s|<)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "\""" + match.Groups[2])).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + private static readonly Regex SMILEYS_MATCHER = new Regex("(^|\\s|>)\\:(\\w+)\\:($|\\s|<)", RegexOptions.Compiled | RegexOptions.Singleline); + + private static string SMILEYS_REPLACE(Match match) { + FileInfo smiley = new FileInfo(Config.instance.dataDir + "Static\\smileys\\" + match.Groups[2] + ".gif"); + if(smiley.Exists && smiley.FullName.StartsWith(Config.instance.dataDir + "Static\\smileys\\")) { + return match.Groups[1] + "\""" + match.Groups[3]; + } else { + return match.Value; + } + } + private static readonly Dictionary TYPOGRAPHICS = new Dictionary { { new Regex("(\\s+)--?(\\s+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "–" + match.Groups[2] }, { new Regex("(\\s+)---(\\s+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "—" + match.Groups[2] }, @@ -59,6 +71,7 @@ namespace FLocal.Common { foreach(var smile in SMILEYS_DATA) { result = smile.Key.Replace(result, smile.Value); } + result = SMILEYS_MATCHER.Replace(result, SMILEYS_REPLACE); foreach(var kvp in TYPOGRAPHICS) { result = kvp.Key.Replace(result, kvp.Value); }