FIRE-15131: Added option to let keywords only match whole words

Fri, 12 Dec 2014 13:31:32 +0100

author
Ansariel
date
Fri, 12 Dec 2014 13:31:32 +0100
changeset 43067
fb0848585f7c
parent 43066
5583097f4bec
child 43068
ae61aa0cb9f0

FIRE-15131: Added option to let keywords only match whole words

indra/newview/app_settings/settings_per_account.xml file | annotate | diff | revisions
indra/newview/fskeywords.cpp file | annotate | diff | revisions
indra/newview/skins/default/xui/de/panel_preferences_chat.xml file | annotate | diff | revisions
indra/newview/skins/default/xui/en/panel_preferences_chat.xml file | annotate | diff | revisions
     1.1 --- a/indra/newview/app_settings/settings_per_account.xml	Fri Dec 12 09:36:00 2014 +0100
     1.2 +++ b/indra/newview/app_settings/settings_per_account.xml	Fri Dec 12 13:31:32 2014 +0100
     1.3 @@ -643,6 +643,17 @@
     1.4  		<key>Value</key>
     1.5  			<integer>0</integer>
     1.6  	</map>
     1.7 +	<key>FSKeywordMatchWholeWords</key>
     1.8 +	<map>
     1.9 +		<key>Comment</key>
    1.10 +			<string>Keywords will only match whole words</string>
    1.11 +		<key>Persist</key>
    1.12 +			<integer>1</integer>
    1.13 +		<key>Type</key>
    1.14 +			<string>Boolean</string>
    1.15 +		<key>Value</key>
    1.16 +			<integer>0</integer>
    1.17 +	</map>
    1.18  	<key>FSKeywords</key>
    1.19  	<map>
    1.20  		<key>Comment</key>
     2.1 --- a/indra/newview/fskeywords.cpp	Fri Dec 12 09:36:00 2014 +0100
     2.2 +++ b/indra/newview/fskeywords.cpp	Fri Dec 12 13:31:32 2014 +0100
     2.3 @@ -35,13 +35,12 @@
     2.4  #include "llviewercontrol.h"
     2.5  
     2.6  #include <boost/regex.hpp>
     2.7 -//#include <boost/algorithm/string/find.hpp> //for boost::ifind_first
     2.8 -
     2.9  
    2.10  FSKeywords::FSKeywords()
    2.11  {
    2.12  	gSavedPerAccountSettings.getControl("FSKeywords")->getSignal()->connect(boost::bind(&FSKeywords::updateKeywords, this));
    2.13  	gSavedPerAccountSettings.getControl("FSKeywordCaseSensitive")->getSignal()->connect(boost::bind(&FSKeywords::updateKeywords, this));
    2.14 +	gSavedPerAccountSettings.getControl("FSKeywordMatchWholeWords")->getSignal()->connect(boost::bind(&FSKeywords::updateKeywords, this));
    2.15  	updateKeywords();
    2.16  }
    2.17  
    2.18 @@ -51,6 +50,7 @@
    2.19  
    2.20  void FSKeywords::updateKeywords()
    2.21  {
    2.22 +	BOOL match_whole_words = gSavedPerAccountSettings.getBOOL("FSKeywordMatchWholeWords");
    2.23  	std::string s = gSavedPerAccountSettings.getString("FSKeywords");
    2.24  	if (!gSavedPerAccountSettings.getBOOL("FSKeywordCaseSensitive"))
    2.25  	{
    2.26 @@ -61,7 +61,14 @@
    2.27  	mWordList.clear();
    2.28  	while (begin != end)
    2.29  	{
    2.30 -		mWordList.push_back(*begin++);
    2.31 +		if (match_whole_words)
    2.32 +		{
    2.33 +			mWordList.push_back(boost::regex_replace(std::string(*begin++), boost::regex("[.^$|()\\[\\]{}*+?\\\\]"), "\\\\&", boost::match_default|boost::format_sed));
    2.34 +		}
    2.35 +		else
    2.36 +		{
    2.37 +			mWordList.push_back(*begin++);
    2.38 +		}
    2.39  	}
    2.40  }
    2.41  
    2.42 @@ -71,6 +78,7 @@
    2.43  	static LLCachedControl<bool> sFSKeywordInChat(gSavedPerAccountSettings, "FSKeywordInChat", false);
    2.44  	static LLCachedControl<bool> sFSKeywordInIM(gSavedPerAccountSettings, "FSKeywordInIM", false);
    2.45  	static LLCachedControl<bool> sFSKeywordCaseSensitive(gSavedPerAccountSettings, "FSKeywordCaseSensitive", false);
    2.46 +	static LLCachedControl<bool> sFSKeywordMatchWholeWords(gSavedPerAccountSettings, "FSKeywordMatchWholeWords", false);
    2.47  
    2.48  	if (!sFSKeywordOn ||
    2.49  		(is_local && !sFSKeywordInChat) ||
    2.50 @@ -86,13 +94,27 @@
    2.51  		LLStringUtil::toLower(source);
    2.52  	}
    2.53  
    2.54 -	for (std::vector<std::string>::iterator it = mWordList.begin(); it != mWordList.end(); ++it)
    2.55 +	if (sFSKeywordMatchWholeWords)
    2.56  	{
    2.57 -		if (source.find((*it)) != std::string::npos)
    2.58 +		for (std::vector<std::string>::iterator it = mWordList.begin(); it != mWordList.end(); ++it)
    2.59  		{
    2.60 -			return true;
    2.61 +			if (boost::regex_search(source, boost::regex("\\b" + (*it) + "\\b")))
    2.62 +			{
    2.63 +				return true;
    2.64 +			}
    2.65  		}
    2.66  	}
    2.67 +	else
    2.68 +	{
    2.69 +		for (std::vector<std::string>::iterator it = mWordList.begin(); it != mWordList.end(); ++it)
    2.70 +		{
    2.71 +			if (source.find((*it)) != std::string::npos)
    2.72 +			{
    2.73 +				return true;
    2.74 +			}
    2.75 +		}
    2.76 +	}
    2.77 +
    2.78  	return false;
    2.79  }
    2.80  
    2.81 @@ -101,7 +123,7 @@
    2.82  {
    2.83  	if (chat.mFromID != gAgentID || chat.mFromName == SYSTEM_FROM)
    2.84  	{
    2.85 -		if (!LLMuteList::getInstance()->isMuted(chat.mFromID) && !chat.mMuted)
    2.86 +		if (!chat.mMuted && !LLMuteList::getInstance()->isMuted(chat.mFromID))
    2.87  		{
    2.88  			static LLCachedControl<bool> PlayModeUISndFSKeywordSound(gSavedSettings, "PlayModeUISndFSKeywordSound");
    2.89  			if (PlayModeUISndFSKeywordSound)
     3.1 --- a/indra/newview/skins/default/xui/de/panel_preferences_chat.xml	Fri Dec 12 09:36:00 2014 +0100
     3.2 +++ b/indra/newview/skins/default/xui/de/panel_preferences_chat.xml	Fri Dec 12 13:31:32 2014 +0100
     3.3 @@ -267,6 +267,7 @@
     3.4  			<check_box name="FSKeywordInChat" label="Lokalen Chat auf Schüsselwörter prüfen"/>
     3.5  			<check_box name="FSKeywordInIM" label="Instant Messages und Gruppenchats auf Schlüsselwörter prüfen"/>
     3.6  			<check_box name="FSKeywordCaseSensitive" label="Groß-/Kleinschreibung bei Schlüsselwörtern beachten"/>
     3.7 +			<check_box name="FSKeywordMatchWholeWords" label="Nur ganze Wörter prüfen"/>
     3.8  			<text name="textFSKeywords">
     3.9  				Schlüsselwörter (getrennt durch Komma):
    3.10  			</text>
     4.1 --- a/indra/newview/skins/default/xui/en/panel_preferences_chat.xml	Fri Dec 12 09:36:00 2014 +0100
     4.2 +++ b/indra/newview/skins/default/xui/en/panel_preferences_chat.xml	Fri Dec 12 13:31:32 2014 +0100
     4.3 @@ -1780,6 +1780,17 @@
     4.4               control_name="FSKeywordCaseSensitive"
     4.5               name="FSKeywordCaseSensitive"
     4.6               label="All Keywords are case-sensitive"/>
     4.7 +            <check_box
     4.8 +             enabled_control="FSKeywordOn"
     4.9 +             layout="topleft"
    4.10 +             follows="left|top"
    4.11 +             top_delta="25"
    4.12 +             left="20"
    4.13 +             width="150"
    4.14 +             height="20"
    4.15 +             control_name="FSKeywordMatchWholeWords"
    4.16 +             name="FSKeywordMatchWholeWords"
    4.17 +             label="Only match whole words"/>
    4.18              <text
    4.19               layout="topleft"
    4.20               follows="left|top"

mercurial