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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon May 17 18:46:44 MSD 2010


Author: sergei
Date: 2010-05-17 18:46:44 +0400 (Mon, 17 May 2010)
New Revision: 1936

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/richtext/emoticons.tcl
Log:
	* plugins/richtext/emoticons.tcl: Use a single rexexp call for a
	  message chunk. Returned to the old way of storing emoticons regexp.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2010-05-17 05:02:30 UTC (rev 1935)
+++ trunk/tkabber/ChangeLog	2010-05-17 14:46:44 UTC (rev 1936)
@@ -3,6 +3,9 @@
 	* plugins/richtext/emoticons.tcl: Started optimizing emoticons matching
 	  code.
 
+	* plugins/richtext/emoticons.tcl: Use a single rexexp call for a
+	  message chunk. Returned to the old way of storing emoticons regexp.
+
 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-05-17 05:02:30 UTC (rev 1935)
+++ trunk/tkabber/plugins/richtext/emoticons.tcl	2010-05-17 14:46:44 UTC (rev 1936)
@@ -77,10 +77,6 @@
 
     incr images($image)
 
-    rebuild_faces_regex
-
-    return
-
     if {$faces_regexp != ""} {
 	append faces_regexp |
     }
@@ -413,6 +409,8 @@
 }
 
 proc emoticons::process_emoticons {atLevel accName} {
+    variable options
+    variable faces_regexp
     upvar #$atLevel $accName chunks
 
     set out {}
@@ -423,17 +421,27 @@
 	    continue
 	}
 
-	set ix 0; set fs 0; set fe 0
-	while {[spot_face $s $ix fs fe]} {
-	    if {$fs - $ix > 0} {
-		# dump chunk before emoticon:
-		lappend out [string range $s $ix [expr {$fs - 1}]] $type $tags
+	set ix 0
+	if {$faces_regexp != ""} {
+	    if {$options(match_whole_word)} {
+		set regexp (?:^|\\s)($faces_regexp)(?=\\s|\$)
+	    } else {
+		set regexp ($faces_regexp)
 	    }
 
-	    # dump emoticon:
-	    lappend out [string range $s $fs $fe] emoticon $tags
+	    foreach {ign inds} [regexp -all -inline -indices -- $regexp $s] {
+		lassign $inds fs fe
 
-	    set ix [expr {$fe + 1}]
+		if {$fs - $ix > 0} {
+		    # dump chunk before emoticon:
+		    lappend out [string range $s $ix [expr {$fs - 1}]] $type $tags
+		}
+
+		# dump emoticon:
+		lappend out [string range $s $fs $fe] emoticon $tags
+
+		set ix [expr {$fe + 1}]
+	    }
 	}
 
 	if {[string length $s] - $ix > 0} {
@@ -445,20 +453,6 @@
     set chunks $out
 }
 
-proc emoticons::spot_face {what at fsVar feVar} {
-    variable options
-    variable faces_regexp
-
-    if {$faces_regexp == ""} {return false}
-
-    upvar 1 $fsVar fs $feVar fe
-    foreach {ign inds} [regexp -inline -indices -start $at -- $faces_regexp $what] {
-	lassign $inds fs fe
-	return true
-    }
-    return false
-}
-
 proc emoticons::render_emoticon {w type word tags} {
     variable options
 
@@ -630,18 +624,9 @@
 
     set faces_regexp ""
 
-    if {$options(match_whole_word)} {
-	append faces_regexp {(?:^|\s)}
-    }
-
-    append faces_regexp {(}
-
-    set q 0
     foreach face [array names emoticons] {
-	if {$q} {
+	if {$faces_regexp != ""} {
 	    append faces_regexp |
-	} else {
-	    set q 1
 	}
 
 	append faces_regexp [re_escape $face]
@@ -650,16 +635,6 @@
 	    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