25 #ifndef GOBY_MOOS_MOOS_STRING_H
26 #define GOBY_MOOS_MOOS_STRING_H
40 <<
" Key: " <<
msg.GetKey() <<
" Type: " << (
msg.IsDouble() ?
"double" :
"string")
42 << (
msg.IsDouble() ? goby::util::as<std::string>(
msg.GetDouble()) :
msg.GetString())
44 << time::convert<boost::posix_time::ptime>(
msg.GetTime() * boost::units::si::seconds)
45 <<
" Community: " <<
msg.GetCommunity()
46 <<
" Source: " <<
msg.m_sSrc
47 <<
" Source Aux: " <<
msg.GetSourceAux();
74 std::string::size_type start_pos = 0;
76 !(start_pos == 0 || start_pos == std::string::npos ||
str[start_pos - 1] ==
','))
80 boost::iterator_range<std::string::const_iterator> result =
81 boost::ifind_nth(
str, std::string(key +
"="), match);
82 start_pos = (result) ? result.begin() -
str.begin() : std::string::npos;
86 if (start_pos != std::string::npos)
90 std::string chopped =
str.substr(start_pos);
96 std::string::size_type equal_pos = chopped.find(
"=");
99 bool is_array = (equal_pos + 1 < chopped.length() && chopped[equal_pos + 1] ==
'{');
101 if (equal_pos != std::string::npos)
105 std::string chopped_twice = chopped.substr(equal_pos);
111 std::string::size_type end_pos =
112 (is_array) ? chopped_twice.find(
"}") : chopped_twice.find(
",");
116 out = (is_array) ? chopped_twice.substr(2, end_pos - 2)
117 : chopped_twice.substr(1, end_pos - 1);
128 template <
typename T>
137 out = boost::lexical_cast<T>(s);
139 catch (boost::bad_lexical_cast&)
154 out = goby::util::as<bool>(s);
162 for (std::string::iterator it = s.end() - 1; it != s.begin() - 1; --it)