1 #ifndef YAPOG_STRINGHELPER_HXX
2 # define YAPOG_STRINGHELPER_HXX
6 # include <boost/lexical_cast.hpp>
20 std::ostringstream oss;
30 String::const_iterator it1 = s1.begin();
31 String::const_iterator it2 = s2.begin();
33 while ((it1 != s1.end()) && (it2 != s2.end())) {
34 if(::toupper(*it1) != ::toupper(*it2))
35 return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1;
40 size_t size1 = s1.size();
41 size_t size2 = s2.size();
45 return (size1 < size2) ? -1 : 1;
51 String::iterator it = s.begin();
60 s.erase(s.begin(), it);
67 String::reverse_iterator it = s.rbegin();
69 while (it != s.rend())
75 String::difference_type diff = s.rend() - it;
76 s.erase(s.begin() + diff, s.end());
100 template <
typename T>
107 template <
typename T>
110 return boost::lexical_cast <T> (str);
118 case Direction::North:
return "North";
133 if (str ==
"North")
return Direction::North;
145 inline ExperienceType StringHelper::Parse<ExperienceType> (
const String& str)
152 if (str ==
"Erratic")
return ExperienceType::Erratic;
153 YAPOG_THROW(
"Not a valid experience type: " + str);
157 inline String StringHelper::ToString<Time> (
const Time& value)
164 if (value.GetValue () > 59)
166 m =
static_cast<uint>(value.GetValue () / 60);
167 s =
static_cast<uint>(value.GetValue ()) % 60;
177 s =
static_cast<uint>(value.GetValue ());
183 result += ToString (h) +
":";
188 result += ToString (m) +
":";
193 result += ToString (s);
200 #endif // YAPOG_STRINGHELPER_HXX