Changeset 0c7664e2841ae18fc47cb025ca4721a561ecdc99

Show
Ignore:
Timestamp:
01/06/07 23:44:54 (6 years ago)
Author:
Philipp Kern <phil@…>
Parents:
f764263e3b4d0680d590bcdbd6b325e94774691e
Children:
a046a0c50b4c83eaa0a435fb80e302aaf11bacc2
git-committer:
Philipp Kern <phil@0x539.de> / 2007-01-06T22:44:54Z+0000
Message:

[project @ User highlighting when name is mentioned in chat [fixes #6]]

Original author: Armin Burgmeier <armin@…>
Date: 2005-07-26 15:18:17+00:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/chat.cpp

    reba1437 r0c7664e  
    115115void Gobby::Chat::add_line(obby::user& user, const Glib::ustring& message) 
    116116{ 
    117         obby::user self = m_buffer->get_self(); 
    118         Glib::ustring colour; 
    119         // Highlight the message if the user's nickname is found in it, 
    120         // but not if the message is coming from the user itself. 
    121         if( (&user != &self) && 
    122             (message.find(self.get_name() ) != Glib::ustring::npos) ) 
    123                 colour = "darkred"; 
    124         else 
    125                 colour = "black"; 
     117        obby::user& self = m_buffer->get_self(); 
     118        Glib::ustring name = self.get_name(); 
     119 
     120        // Check if we have to highlight the line becasue the user's nick name 
     121        // was found in the the message. 
     122        Glib::ustring colour = "black"; 
     123 
     124        // Only check for highlighting if another user wrote this message 
     125        if(&self != &user) 
     126        { 
     127                Glib::ustring::size_type pos = 0; 
     128                while( (message.find(name, pos)) != Glib::ustring::npos) 
     129                { 
     130                        // Check that the found position is not part of another 
     131                        // word ('ck' should not be found in 'luck' and such). 
     132                        if(pos > 0 && Glib::Unicode::isalnum(message[pos - 1]) ) 
     133                                { ++ pos; continue; } 
     134 
     135                        if(pos + name.length() < message.length() && 
     136                           Glib::Unicode::isalnum(message[pos + name.length()])) 
     137                                { ++ pos; continue; } 
     138 
     139                        // Found occurence 
     140                        colour = "darkred"; 
     141                        break; 
     142                } 
     143        } 
    126144 
    127145        m_log_chat.log("<" + user.get_name() + "> " + message, colour);