From 4248653537ce89aa09e482ae027d2553d0d2a7bd Mon Sep 17 00:00:00 2001 From: Haibo Date: Sun, 27 May 2018 01:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20String=20=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=88=B0=20const=20char*=20=E5=92=8C=20char*=20?= =?UTF-8?q?=E7=9A=84=E8=BF=90=E7=AE=97=E7=AC=A6=E9=87=8D=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Common/String.cpp | 16 +++++++++++++++- core/e2dcommon.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/Common/String.cpp b/core/Common/String.cpp index a8e59e26..066c5c4a 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -333,6 +333,20 @@ e2d::String::operator wchar_t*() const return const_cast(_str.c_str()); } +e2d::String::operator const char*() const +{ + static std::string strTmp; + strTmp = static_cast(_bstr_t(_str.c_str())); + return strTmp.c_str(); +} + +e2d::String::operator char*() const +{ + static std::string strTmp; + strTmp = static_cast(_bstr_t(_str.c_str())); + return const_cast(strTmp.c_str()); +} + bool e2d::String::isEmpty() const { return _str.empty(); @@ -450,7 +464,7 @@ void e2d::String::replace(const String & from, const String & to) return; size_t start_pos = 0; - while ((start_pos = _str.find((const wchar_t *)from, start_pos)) != std::string::npos) + while ((start_pos = _str.find((const wchar_t *)from, start_pos)) != std::wstring::npos) { _str.replace(start_pos, from._str.length(), (const wchar_t *)to); start_pos += to._str.length(); diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 643b2d44..900c679f 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -238,6 +238,8 @@ public: // 类型转换操作符 E2D_OP_EXPLICIT operator const wchar_t* () const; E2D_OP_EXPLICIT operator wchar_t* () const; + E2D_OP_EXPLICIT operator const char* () const; + E2D_OP_EXPLICIT operator char* () const; // 比较运算符 bool operator== (const String &) const;