X-Git-Url: https://git.llucax.com/z.facultad/75.42/plaqui.git/blobdiff_plain/802f79cdb0d688127b8a639cd3173d801a1466cd..4404d8472c0088ec061b2f4f6527412f7ba23569:/Server/src/string.cpp?ds=sidebyside diff --git a/Server/src/string.cpp b/Server/src/string.cpp index 24904a7..97dd19f 100644 --- a/Server/src/string.cpp +++ b/Server/src/string.cpp @@ -28,15 +28,32 @@ #include "plaqui/server/string.h" #include #include +#include +#include #ifdef DEBUG # include #endif // DEBUG -using namespace PlaQui::Server; +using namespace std; -const std::string String::SPACE_CHARS = " \t\n\r"; - -String::String(const std::string& str): std::string(str.c_str()) { +namespace PlaQui { + +namespace Server { + +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) { @@ -46,12 +63,37 @@ String& String::trim(const String& clist) { } String& String::to_lower(void) { - std::transform(begin(), end(), begin(), tolower); + transform(begin(), end(), begin(), ::tolower); return *this; } String& String::to_upper(void) { - std::transform(begin(), end(), begin(), toupper); + transform(begin(), end(), begin(), ::toupper); 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(); +} + +} // namespace Server + +} // namespace PlaQui +