[smuxi: 110/111] Engine: treat empty LinkFormat and TextFormat the same as null



commit 0c8c4810560ee7f63cb05e17229383b8dc7569a0
Author: Mirco Bauer <meebey meebey net>
Date:   Sat Feb 15 14:24:51 2014 +0100

    Engine: treat empty LinkFormat and TextFormat the same as null

 src/Engine/Messages/MessageBuilder.cs |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/src/Engine/Messages/MessageBuilder.cs b/src/Engine/Messages/MessageBuilder.cs
index 6b1f9b7..49bce15 100644
--- a/src/Engine/Messages/MessageBuilder.cs
+++ b/src/Engine/Messages/MessageBuilder.cs
@@ -1,6 +1,6 @@
 // Smuxi - Smart MUltipleXed Irc
 // 
-// Copyright (c) 2010-2013 Mirco Bauer <meebey meebey net>
+// Copyright (c) 2010-2014 Mirco Bauer <meebey meebey net>
 // Copyright (c) 2013 Oliver Schneider <mail oli-obk de>
 // 
 // Full GPL License: <http://www.gnu.org/licenses/gpl.txt>
@@ -884,16 +884,16 @@ namespace Smuxi.Engine
                 }
                 
                 string url;
-                if (link.LinkFormat != null) {
-                    url = String.Format(link.LinkFormat, groupValues);
-                } else {
+                if (String.IsNullOrEmpty(link.LinkFormat)) {
                     url = linkMatch.Value;
+                } else {
+                    url = String.Format(link.LinkFormat, groupValues);
                 }
                 string text;
-                if (link.TextFormat != null) {
-                    text = String.Format(link.TextFormat, groupValues);
+                if (String.IsNullOrEmpty(link.TextFormat)) {
+                    text = linkMatch.Value;
                 } else {
-                    text = (linkMatch.Value == url) ? null : linkMatch.Value;
+                    text = String.Format(link.TextFormat, groupValues);
                 }
 
                 if (lastindex != linkMatch.Index) {
@@ -911,6 +911,8 @@ namespace Smuxi.Engine
                 
                 MessagePartModel model;
                 if (link.MessagePartType == typeof(UrlMessagePartModel)) {
+                    // no need to set URL and text if they are the same
+                    text = text == url ? null : text;
                     model = new UrlMessagePartModel(url, text);
                 } else if (link.MessagePartType == typeof(ImageMessagePartModel)) {
                     model = new ImageMessagePartModel(url, text);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]