Fix Convert::ToString.

Fixes #5054
This commit is contained in:
Gunnar Beutner 2013-11-11 13:04:18 +01:00
parent e4b5fe74ff
commit 4f1cb83f31
6 changed files with 27 additions and 5 deletions

View File

@ -114,7 +114,7 @@ void StatusDataWriter::DumpTimePeriod(std::ostream& fp, const TimePeriod::Ptr& t
String key;
Value value;
BOOST_FOREACH(boost::tie(key, value), ranges) {
fp << "\t" << key << "\t" << Convert::ToString(value) << "\n";
fp << "\t" << key << "\t" << value << "\n";
}
}
@ -151,7 +151,7 @@ void StatusDataWriter::DumpCommand(std::ostream& fp, const Command::Ptr& command
fp << " \"" << CompatUtility::EscapeString(arg) << "\"";
}
} else if (!commandLine.IsEmpty()) {
fp << CompatUtility::EscapeString(Convert::ToString(commandLine));
fp << CompatUtility::EscapeString(commandLine);
} else {
fp << "<internal>";
}
@ -543,7 +543,7 @@ void StatusDataWriter::DumpCustomAttributes(std::ostream& fp, const DynamicObjec
key != "icon_image" && key != "icon_image_alt" && key != "statusmap_image" && "2d_coords")
fp << "_";
fp << key << "\t" << Convert::ToString(value) << "\n";
fp << key << "\t" << value << "\n";
}
}

View File

@ -557,7 +557,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
}
cols += key;
values += Convert::ToString(value);
values += value;
} else {
if (!first)
qbuf << ", ";

View File

@ -566,7 +566,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query)
}
cols += key;
values += Convert::ToString(value);
values += value;
} else {
if (!first)
qbuf << ", ";

View File

@ -27,3 +27,12 @@ bool Convert::ToBool(const String& val)
return (ToLong(val) != 0);
}
String Convert::ToString(const String& val)
{
return val;
}
String Convert::ToString(const Value& val)
{
return val;
}

View File

@ -55,6 +55,9 @@ public:
return boost::lexical_cast<String>(val);
}
static String ToString(const String& val);
static String ToString(const Value& val);
private:
Convert(void);
};

View File

@ -31,6 +31,8 @@ BOOST_AUTO_TEST_CASE(tolong)
BOOST_CHECK_THROW(Convert::ToLong(" 7"), boost::exception);
BOOST_CHECK(Convert::ToLong("-7") == -7);
BOOST_CHECK_THROW(Convert::ToLong("7a"), boost::exception);
BOOST_CHECK(Convert::ToLong(Value(-7)) == -7);
}
BOOST_AUTO_TEST_CASE(todouble)
@ -38,6 +40,7 @@ BOOST_AUTO_TEST_CASE(todouble)
BOOST_CHECK_THROW(Convert::ToDouble(" 7.3"), boost::exception);
BOOST_CHECK(Convert::ToDouble("-7.3") == -7.3);
BOOST_CHECK_THROW(Convert::ToDouble("7.3a"), boost::exception);
BOOST_CHECK(Convert::ToDouble(Value(-7.3)) == -7.3);
}
BOOST_AUTO_TEST_CASE(tostring)
@ -45,6 +48,11 @@ BOOST_AUTO_TEST_CASE(tostring)
BOOST_CHECK(Convert::ToString(7) == "7");
BOOST_CHECK(Convert::ToString(7.5) == "7.5");
BOOST_CHECK(Convert::ToString("hello") == "hello");
BOOST_CHECK(Convert::ToString(Value(7)) == "7");
BOOST_CHECK(Convert::ToString(Value(7.5)) == "7.5");
BOOST_CHECK(Convert::ToString(Value("hello")) == "hello");
BOOST_CHECK(Convert::ToString(Value("hello hello")) == "hello hello");
}
BOOST_AUTO_TEST_CASE(tobool)
@ -53,6 +61,8 @@ BOOST_AUTO_TEST_CASE(tobool)
BOOST_CHECK(Convert::ToBool("0") == false);
BOOST_CHECK(Convert::ToBool("1") == true);
BOOST_CHECK(Convert::ToBool("2") == true);
BOOST_CHECK(Convert::ToBool(Value(true)) == true);
BOOST_CHECK(Convert::ToBool(Value(false)) == false);
}
BOOST_AUTO_TEST_SUITE_END()