00001 #include "SFString.h"
00002
00003 #include <iostream>
00004 #include <sstream>
00005
00006 using namespace X3DTK;
00007 using namespace std;
00008
00009 SFString::SFString()
00010 : string()
00011 {
00012 }
00013
00014 SFString::SFString(const char *s)
00015 : string(s)
00016 {
00017 }
00018
00019 SFString::SFString(const std::string &s)
00020 : string(s)
00021 {
00022 }
00023
00024 SFString::SFString(const SFString &s)
00025 : string(s)
00026 {
00027 }
00028
00029 SFString::operator const char *() const
00030 {
00031
00032 return this->data();
00033 }
00034
00035 int SFString::toInt() const
00036 {
00037 istringstream iss(*this, istringstream::in);
00038 int r;
00039 iss >> r;
00040 return r;
00041 }
00042
00043 unsigned int SFString::toUint() const
00044 {
00045 istringstream iss(*this, istringstream::in);
00046 unsigned int r;
00047 iss >> r;
00048 return r;
00049 }
00050
00051 float SFString::toFloat() const
00052 {
00053 istringstream iss(*this, istringstream::in);
00054 float r;
00055 iss >> r;
00056 return r;
00057 }
00058
00059 double SFString::toDouble() const
00060 {
00061 istringstream iss(*this, istringstream::in);
00062 double r;
00063 iss >> r;
00064 return r;
00065 }
00066
00067 SFString SFString::lower() const
00068 {
00069 SFString res(*this);
00070 for (SFString::iterator it = res.begin(); it != res.end(); ++it)
00071 if (((*it) > 64) && ((*it) < 91))
00072 *it = *it + 32;
00073
00074 return res;
00075 }
00076
00077 SFString SFString::upper() const
00078 {
00079 SFString res(*this);
00080 for (SFString::iterator it = res.begin(); it != res.end(); ++it)
00081 {
00082 if (((*it) > 96) && ((*it) < 123))
00083 *it = *it - 32;
00084 }
00085
00086 return res;
00087 }
00088
00089 SFString SFString::getPath() const
00090 {
00091 return this->substr(0, this->find_last_of('/'));
00092 }
00093
00094 SFString SFString::number(float f)
00095 {
00096 ostringstream oss;
00097 oss << f;
00098 return oss.str();
00099 }
00100
00101 SFString SFString::number(double d)
00102 {
00103 ostringstream oss;
00104 oss << d;
00105 return oss.str();
00106 }
00107
00108 SFString SFString::number(int i)
00109 {
00110 ostringstream oss;
00111 oss << i;
00112 return oss.str();
00113
00114 }
00115
00116 SFString SFString::number(unsigned int ui)
00117 {
00118 ostringstream oss;
00119 oss << ui;
00120 return oss.str();
00121 }