#include "WCString.h" #include using namespace SRFramework; WCString::WCString(void) : char_copy(NULL) , data(L" ") { } WCString::~WCString(void) { if(char_copy) delete [] char_copy; } WCString::WCString(const char * rhs) : char_copy(NULL) { unsigned int len = strlen(rhs); unsigned int i = 0; if(data.size() < len) data.resize(len); for(i = 0; i < len; i++){ data[i] = (wchar_t)rhs[i]; } } WCString::WCString(const WCString &rhs) : data(rhs.data) , char_copy(NULL) { } WCString::WCString(const wchar_t * rhs) : char_copy(NULL) { unsigned int len = 0; unsigned int i = 0; // This is so dangerous... while(rhs[len]) len++; if(data.size() < len) data.resize(len); for(i = 0; i < len; i++){ data[i] = rhs[i]; } } BOOL WCString::contains(const WCString &rhs) const { return wcsstr(this->w_str(), rhs.w_str()) != NULL; } WCString::WCString(const std::string &rhs) : char_copy(NULL) { unsigned int len = rhs.length(); unsigned int i = 0; if(data.size() < len) data.resize(len); for(i = 0; i < len; i++){ data[i] = (wchar_t)rhs[i]; } } std::string WCString::to_string() { unsigned int i = 0; std::string retval; retval.resize(data.length()); for(i = 0; i < data.length(); i++) retval[i] = (char)data[i]; retval[i] = 0; return retval; } WCString &WCString::operator=(const WCString &rhs) { if(this != &rhs) data = rhs.data; return *this; } const wchar_t *WCString::w_str() const { return data.c_str(); } const char *WCString::c_str() const { unsigned int i = 0; if(char_copy) delete [] char_copy; char_copy = new char[data.length() + 1]; for(i = 0; i < data.length(); i++) char_copy[i] = (char)data[i]; char_copy[i] = 0; return char_copy; } WCString &WCString::operator=(const std::string &rhs) { unsigned int i = 0; data.clear(); if(rhs.length() > data.size()) data.resize(rhs.length()); for(i = 0; i < rhs.length(); i++) data[i] = (wchar_t)rhs[i]; return *this; } WCString &WCString::operator=(const wchar_t *rhs) { unsigned int i = 0; unsigned int len = 0; // This is so dangerous... while(rhs[len]) len++; data.clear(); if(len > data.size()) data.resize(len); for(i = 0; i < len; i++) data[i] = rhs[i]; return *this; } WCString &WCString::operator=(const char *rhs) { unsigned int i = 0; unsigned int len = 0; // This is so dangerous... while(rhs[len]) len++; data.clear(); if(len > data.size()) data.resize(len); for(i = 0; i < len; i++) data[i] = (wchar_t)rhs[i]; return *this; } WCString &WCString::operator+=(const WCString &rhs) { unsigned int i = 0; unsigned int di = data.length(); unsigned int ri = rhs.length(); if(this == &rhs) return *this; if(data.size() < rhs.length() + di) data.resize(rhs.length() + di); for(i = 0; i < rhs.length(); i++){ data[di + i] = rhs.data[i]; } return *this; } WCString &WCString::operator+=(const std::string &rhs) { unsigned int i = 0; unsigned int di = data.length(); if(rhs.length() + di > data.size()) data.resize(rhs.length() + di); for(i = 0; i < rhs.length(); i++) data[di + i] = (wchar_t)rhs[i]; return *this; } WCString &WCString::operator+=(const wchar_t *rhs) { unsigned int i = 0; unsigned int len = 0; unsigned int di = data.length(); // This is so dangerous... while(rhs[len]) len++; if(len + di > data.size()) data.resize(len + di); for(i = 0; i < len; i++) data[di + i] = rhs[i]; //data[di + i] = 0; return *this; } WCString &WCString::operator+=(const char *rhs) { unsigned int i = 0; unsigned int len = 0; unsigned int di = data.length(); // This is so dangerous... while(rhs[len]) len++; if(len + di > data.size()) data.resize(len + di); for(i = 0; i < len; i++) data[di + i] = (wchar_t)rhs[i]; return *this; } WCString WCString::operator+(const WCString &rhs) { WCString retval = *this; retval += rhs; return retval; } WCString WCString::operator+(const std::string &rhs) { WCString retval = *this; retval += rhs; return retval; } WCString WCString::operator+(const wchar_t *rhs) { WCString retval = *this; retval += rhs; return retval; } WCString WCString::operator+(const char *rhs) { WCString retval = *this; retval += rhs; return retval; }