#include "SFString.h" #include #include #include using namespace X3DTK; using namespace std; SFString::SFString() : string() { } SFString::SFString(const char *s) : string(s) { } SFString::SFString(const unsigned char *s) : string() { ostringstream oss; oss << s; *this = oss.str(); } SFString::SFString(const std::string &s) : string(s) { } SFString::SFString(const SFString &s) : string(s) { } SFString::operator const char *() const { return this->data(); } int SFString::toInt() const { istringstream iss(*this, istringstream::in); int r; iss >> r; return r; } unsigned int SFString::toUint() const { istringstream iss(*this, istringstream::in); unsigned int r; iss >> r; return r; } float SFString::toFloat() const { istringstream iss(*this, istringstream::in); float r; iss >> r; return r; } double SFString::toDouble() const { istringstream iss(*this, istringstream::in); double r; iss >> r; return r; } SFString SFString::toSFString() const { return "\"" + *this + "\""; } SFString SFString::lower() const { SFString res(*this); for (SFString::iterator it = res.begin(); it != res.end(); ++it) if (((*it) > 64) && ((*it) < 91)) *it = *it + 32; return res; } SFString SFString::upper() const { SFString res(*this); for (SFString::iterator it = res.begin(); it != res.end(); ++it) { if (((*it) > 96) && ((*it) < 123)) *it = *it - 32; } return res; } SFString SFString::getName() const { SFString file = this->substr(this->find_last_of('/') + 1, size()); return file.substr(0, file.find_last_of('.')); } SFString SFString::getExtension() const { return this->substr(this->find_last_of('.') + 1, size()); } SFString SFString::getFile() const { return this->substr(this->find_last_of('/') + 1, size()); } SFString SFString::getPath() const { SFString file; if (find_last_of('/') >= size()) file = "./" + *this; else file = *this; return file.substr(0, file.find_last_of('/')) + "/"; } SFString SFString::number(float f) { ostringstream oss; oss << f; return oss.str(); } SFString SFString::number(double d) { ostringstream oss; oss << d; return oss.str(); } SFString SFString::number(int i) { ostringstream oss; oss << i; return oss.str(); } SFString SFString::number(unsigned int ui) { ostringstream oss; oss << ui; return oss.str(); }