Author: alink
Date: Sun Jun 29 21:48:20 2008
New Revision: 27595
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27595&view=rev
Log:
Starting to unify/clean the use of string_bool :
- Consider no, false, off, 0, 0.0 as false, empty as default, others as true
- This allow to optimize this very frequently called function, and so we may
use the same one in sensible areas too.
Modified:
trunk/src/serialization/string_utils.cpp
trunk/src/serialization/string_utils.hpp
Modified: trunk/src/serialization/string_utils.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/string_utils.cpp?rev=27595&r1=27594&r2=27595&view=diff
==============================================================================
--- trunk/src/serialization/string_utils.cpp (original)
+++ trunk/src/serialization/string_utils.cpp Sun Jun 29 21:48:20 2008
@@ -395,15 +395,14 @@
bool string_bool(const std::string& str, bool def) {
if (str.empty()) return def;
- if (str == "yes" || str == "on" || str == "true"
- || lexical_cast_default<int>(str, 0)) {
- return true;
- }
- if (str == "no" || str == "off" || str == "false"
- || !lexical_cast_default<int>(str, 1)) {
+
+ // yes/no is the standard, test it first
+ if (str == "yes") return true;
+ if (str == "no"|| str == "false" || str == "off" || str == "0" || str
== "0.0")
return false;
- }
- return def;
+
+ // all other non-empty string are considered as true
+ return true;
}
static bool is_username_char(char c) {
Modified: trunk/src/serialization/string_utils.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/string_utils.hpp?rev=27595&r1=27594&r2=27595&view=diff
==============================================================================
--- trunk/src/serialization/string_utils.hpp (original)
+++ trunk/src/serialization/string_utils.hpp Sun Jun 29 21:48:20 2008
@@ -67,6 +67,7 @@
std::string &strip(std::string &str);
//! Removes character 'c' from the first and last position of the string 'str'.
std::string& strip_char(std::string &str, const char c);
+//! Convert no, false, off, 0, 0.0 to false, empty to def, and others to true
bool string_bool(const std::string& str,bool def=false);
//! Try to complete the last word of 'text' with the 'wordlist'.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits