[Tkabber-dev] r1935 - in trunk/tkabber: . plugins/richtext

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon May 17 09:02:30 MSD 2010


Author: sergei
Date: 2010-05-17 09:02:30 +0400 (Mon, 17 May 2010)
New Revision: 1935

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/richtext/emoticons.tcl
Log:
	* plugins/richtext/emoticons.tcl: Started optimizing emoticons matching
	  code.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2010-04-30 08:21:19 UTC (rev 1934)
+++ trunk/tkabber/ChangeLog	2010-05-17 05:02:30 UTC (rev 1935)
@@ -1,3 +1,8 @@
+2010-05-17  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/richtext/emoticons.tcl: Started optimizing emoticons matching
+	  code.
+
 2010-04-30  Sergei Golovan  <sgolovan at nes.ru>
 
 	* default.tcl: Fixed DDE command argument (thanks to Jan Zachorowski)

Modified: trunk/tkabber/plugins/richtext/emoticons.tcl
===================================================================
--- trunk/tkabber/plugins/richtext/emoticons.tcl	2010-04-30 08:21:19 UTC (rev 1934)
+++ trunk/tkabber/plugins/richtext/emoticons.tcl	2010-05-17 05:02:30 UTC (rev 1935)
@@ -41,7 +41,8 @@
 
     custom::defvar options(match_whole_word) 1 \
 	[::msgcat::mc "Use only whole words for emoticons."] \
-	-group Emoticons -type boolean
+	-group Emoticons -type boolean \
+	-command [namespace current]::on_regex_mode_changed
 
     custom::defvar options(handle_lol) 0 \
 	[::msgcat::mc "Handle ROTFL/LOL smileys -- those like :))) --\
@@ -76,6 +77,10 @@
 
     incr images($image)
 
+    rebuild_faces_regex
+
+    return
+
     if {$faces_regexp != ""} {
 	append faces_regexp |
     }
@@ -447,15 +452,9 @@
     if {$faces_regexp == ""} {return false}
 
     upvar 1 $fsVar fs $feVar fe
-    foreach inds [regexp -all -inline -indices -start $at -- $faces_regexp $what] {
-	lassign $inds fsv fev
-	if {!$options(match_whole_word) || \
-	    ([string is space [string index $what [expr {$fsv-1}]]] && \
-	     [string is space [string index $what [expr {$fev+1}]]])} {
-	    set fs $fsv
-	    set fe $fev
-	    return true
-	}
+    foreach {ign inds} [regexp -inline -indices -start $at -- $faces_regexp $what] {
+	lassign $inds fs fe
+	return true
     }
     return false
 }
@@ -631,9 +630,18 @@
 
     set faces_regexp ""
 
+    if {$options(match_whole_word)} {
+	append faces_regexp {(?:^|\s)}
+    }
+
+    append faces_regexp {(}
+
+    set q 0
     foreach face [array names emoticons] {
-	if {$faces_regexp != ""} {
+	if {$q} {
 	    append faces_regexp |
+	} else {
+	    set q 1
 	}
 
 	append faces_regexp [re_escape $face]
@@ -642,6 +650,16 @@
 	    append faces_regexp +
 	}
     }
+
+    append faces_regexp {)}
+
+    if {$options(match_whole_word)} {
+	append faces_regexp {(?:\s|$)}
+    }
+
+    if {!$q} {
+	set faces_regexp ""
+    }
 }
 
 # Returns a string with its rightmost repeated characters collapsed into one.



More information about the Tkabber-dev mailing list