diff --git a/core/Common/String.cpp b/core/Common/String.cpp index 864b3a30..6200aaf1 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -37,19 +37,19 @@ e2d::String::~String() e2d::String &e2d::String::operator=(const wchar_t *str) { m_str = str; - return *this; + return (*this); } e2d::String & e2d::String::operator=(const char *cstr) { m_str = static_cast(_bstr_t(cstr)); - return *this; + return (*this); } e2d::String & e2d::String::operator=(const String &str) { m_str = str.m_str; - return *this; + return (*this); } bool e2d::String::operator==(const wchar_t *str) @@ -192,27 +192,56 @@ bool e2d::String::operator<=(const String &str) const e2d::String & e2d::String::operator<<(const String &str) { - return this->append(str); + m_str += str.m_str; + return (*this); } e2d::String & e2d::String::operator<<(const wchar_t *str) { - return this->append(str); + m_str += str; + return (*this); } e2d::String & e2d::String::operator<<(wchar_t *str) { - return this->append(str); + m_str += str; + return (*this); } -e2d::String & e2d::String::operator<<(const char * value) +e2d::String & e2d::String::operator<<(const char * cstr) { - return this->append(value); + m_str += static_cast(_bstr_t(cstr)); + return (*this); } -e2d::String & e2d::String::operator<<(char * value) +e2d::String & e2d::String::operator<<(char * cstr) { - return this->append(value); + m_str += static_cast(_bstr_t(cstr)); + return (*this); +} + +e2d::String & e2d::String::operator<<(int value) +{ + (*this) += String::toString(value); + return (*this); +} + +e2d::String & e2d::String::operator<<(unsigned int value) +{ + (*this) += String::toString(value); + return (*this); +} + +e2d::String & e2d::String::operator<<(float value) +{ + (*this) += String::toString(value); + return (*this); +} + +e2d::String & e2d::String::operator<<(double value) +{ + (*this) += String::toString(value); + return (*this); } e2d::String::operator const wchar_t*() const @@ -352,36 +381,6 @@ void e2d::String::clear() m_str.clear(); } -e2d::String & e2d::String::append(const wchar_t * str) -{ - m_str += str; - return *this; -} - -e2d::String & e2d::String::append(wchar_t * str) -{ - m_str += str; - return *this; -} - -e2d::String & e2d::String::append(const char * str) -{ - m_str += static_cast(_bstr_t(str)); - return *this; -} - -e2d::String & e2d::String::append(char * str) -{ - m_str += static_cast(_bstr_t(str)); - return *this; -} - -e2d::String & e2d::String::append(const e2d::String & str) -{ - m_str += str.m_str; - return (*this); -} - std::wostream & e2d::operator<<(std::wostream &cout, const String &str) { cout << str.m_str; diff --git a/core/ecommon.h b/core/ecommon.h index 525dbd63..b2cb3609 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -111,35 +111,6 @@ public: // 获取 ANSI 字符串 std::string getCString() const; - // 后接字符串 - String& append( - const String &str - ); - - // 后接字符串 - String& append( - const char * cstr - ); - - // 后接字符串 - String& append( - char * cstr - ); - - // 后接字符串 - String& append( - const wchar_t *str - ); - - // 后接字符串 - String& append( - wchar_t *str - ); - - // 后接字符串 - template - String& append(const T &value); - // 获取裁剪字符串 String subtract( int offset, /* 偏移量 */ @@ -211,17 +182,19 @@ public: bool operator< (const String &) const; bool operator<= (const String &) const; - // << 运算符 + // << 运算符(后接字符串) String& operator<< (const String &); String& operator<< (const char *); String& operator<< (char *); String& operator<< (const wchar_t *); String& operator<< (wchar_t *); - template - String& operator<< (const T value) { return this->append<>(value); } + String& operator<< (int value); + String& operator<< (unsigned int value); + String& operator<< (float value); + String& operator<< (double value); // 其他运算符 - wchar_t &operator[] (int); + wchar_t& operator[] (int); friend std::ostream& operator<< (std::ostream &, const String &); friend std::wostream& operator<< (std::wostream &, const String &); @@ -734,14 +707,6 @@ protected: }; // String 类模板函数定义 -template -inline e2d::String & e2d::String::append(const T & value) -{ - std::wostringstream ss; - ss << value; - m_str += ss.str(); - return (*this); -} template inline e2d::String e2d::String::toString(const T value)