#include "plaqui/server/string.h"
#include <cctype>
#include <algorithm>
+#include <iterator>
+#include <sstream>
#ifdef DEBUG
# include <iostream>
#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<string>& v, const string& sep) {
+ (*this) = join(v, sep);
}
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> String::split(char sep) const {
+ vector<string> 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<string>& v, const string& sep) {
+ stringstream ss;
+ std::copy(v.begin(), v.end(), ostream_iterator<string>(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