X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/d3ea2ff01c51df0df95cd23157267048e2c2fdcd..e4f66a8221e3f2156d89a7a358073863503b2564:/Server/src/string.cpp diff --git a/Server/src/string.cpp b/Server/src/string.cpp index cd2eaad..8f9b2db 100644 --- a/Server/src/string.cpp +++ b/Server/src/string.cpp @@ -28,6 +28,8 @@ #include "plaqui/server/string.h" #include #include +#include +#include #ifdef DEBUG # include #endif // DEBUG @@ -43,10 +45,17 @@ const string String::SPACE_CHARS = " \t\n\r"; String::~String(void) { } +String::String(void) { +} + String::String(const string& str): string(str.c_str()) { } +String::String(const vector& v, const string& sep) { + (*this) = join(v, sep); +} + String& String::trim(const String& clist) { erase(0, find_first_not_of(clist)); erase(find_last_not_of(clist) + 1); @@ -63,6 +72,42 @@ String& String::to_upper(void) { return *this; } +vector String::split(char sep) const { + vector v; + String::size_type start = 0; + String::size_type end = find(sep); + while (end != String::npos) { + v.push_back(substr(start, end - start)); + start = end + 1; + end = find(sep, start); + } + if (start != length()) { + v.push_back(substr(start, end - start)); + } + return v; +} + +String String::join(const vector& v, const string& sep) { + stringstream ss; + std::copy(v.begin(), v.end(), ostream_iterator(ss, sep.c_str())); + return ss.str(); +} + +/* +template < class T > T& String::to(T& p) const { + stringstream ss(*this); + ss >> p; + return p; +} + +template < class T > String& String::from(const T& p) { + stringstream ss; + ss << p; + ss >> (*this); + return *this; +} +*/ + } // namespace Server } // namespace PlaQui