summaryrefslogtreecommitdiff
path: root/core/fxcrt/include
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/include')
-rw-r--r--core/fxcrt/include/fx_basic.h10
-rw-r--r--core/fxcrt/include/fx_string.h30
2 files changed, 24 insertions, 16 deletions
diff --git a/core/fxcrt/include/fx_basic.h b/core/fxcrt/include/fx_basic.h
index feeb6e756d..2ef11beb27 100644
--- a/core/fxcrt/include/fx_basic.h
+++ b/core/fxcrt/include/fx_basic.h
@@ -27,8 +27,8 @@ class CFX_BinaryBuf {
void Clear();
void EstimateSize(FX_STRSIZE size, FX_STRSIZE alloc_step = 0);
void AppendBlock(const void* pBuf, FX_STRSIZE size);
- void AppendString(const CFX_ByteStringC& str) {
- AppendBlock(str.GetPtr(), str.GetLength());
+ void AppendString(const CFX_ByteString& str) {
+ AppendBlock(str.c_str(), str.GetLength());
}
void AppendByte(uint8_t byte) {
@@ -63,6 +63,12 @@ class CFX_ByteTextBuf : public CFX_BinaryBuf {
CFX_ByteTextBuf& operator<<(int i);
CFX_ByteTextBuf& operator<<(uint32_t i);
CFX_ByteTextBuf& operator<<(double f);
+ CFX_ByteTextBuf& operator<<(const FX_CHAR* pStr) {
+ return *this << CFX_ByteStringC(pStr);
+ }
+ CFX_ByteTextBuf& operator<<(const CFX_ByteString& str) {
+ return *this << str.AsByteStringC();
+ }
CFX_ByteTextBuf& operator<<(const CFX_ByteStringC& lpsz);
CFX_ByteTextBuf& operator<<(const CFX_ByteTextBuf& buf);
};
diff --git a/core/fxcrt/include/fx_string.h b/core/fxcrt/include/fx_string.h
index 9aa67845f8..cbf8c4de2f 100644
--- a/core/fxcrt/include/fx_string.h
+++ b/core/fxcrt/include/fx_string.h
@@ -61,8 +61,6 @@ class CFX_ByteStringC {
m_Length = src.m_Length;
}
- CFX_ByteStringC(const CFX_ByteString& src);
-
CFX_ByteStringC& operator=(const FX_CHAR* src) {
m_Ptr = (const uint8_t*)src;
m_Length = m_Ptr ? FXSYS_strlen(src) : 0;
@@ -167,12 +165,14 @@ class CFX_ByteString {
static CFX_ByteString FromUnicode(const CFX_WideString& str);
// Explicit conversion to C-style string.
+ // Note: |this| must outlive the use of the result.
const FX_CHAR* c_str() const { return m_pData ? m_pData->m_String : ""; }
// Implicit conversion to C-style string -- deprecated.
operator const FX_CHAR*() const { return m_pData ? m_pData->m_String : ""; }
// Explicit conversion to uint8_t*.
+ // Note: |this| must outlive the use of the result.
const uint8_t* raw_str() const {
return m_pData ? reinterpret_cast<const uint8_t*>(m_pData->m_String)
: nullptr;
@@ -184,6 +184,12 @@ class CFX_ByteString {
: nullptr;
}
+ // Explicit conversion to CFX_ByteStringC.
+ // Note: |this| must outlive the use of the result.
+ CFX_ByteStringC AsByteStringC() const {
+ return CFX_ByteStringC(raw_str(), GetLength());
+ }
+
FX_STRSIZE GetLength() const { return m_pData ? m_pData->m_nDataLength : 0; }
bool IsEmpty() const { return !GetLength(); }
@@ -330,10 +336,6 @@ class CFX_ByteString {
friend class fxcrt_ByteStringConcat_Test;
};
-inline CFX_ByteStringC::CFX_ByteStringC(const CFX_ByteString& src) {
- m_Ptr = (const uint8_t*)src;
- m_Length = src.GetLength();
-}
inline CFX_ByteStringC& CFX_ByteStringC::operator=(const CFX_ByteString& src) {
m_Ptr = (const uint8_t*)src;
m_Length = src.GetLength();
@@ -373,29 +375,29 @@ inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteStringC& str2) {
}
inline CFX_ByteString operator+(const CFX_ByteString& str1,
const CFX_ByteString& str2) {
- return CFX_ByteString(str1, str2);
+ return CFX_ByteString(str1.AsByteStringC(), str2.AsByteStringC());
}
inline CFX_ByteString operator+(const CFX_ByteString& str1, FX_CHAR ch) {
- return CFX_ByteString(str1, CFX_ByteStringC(ch));
+ return CFX_ByteString(str1.AsByteStringC(), CFX_ByteStringC(ch));
}
inline CFX_ByteString operator+(FX_CHAR ch, const CFX_ByteString& str2) {
- return CFX_ByteString(ch, str2);
+ return CFX_ByteString(ch, str2.AsByteStringC());
}
inline CFX_ByteString operator+(const CFX_ByteString& str1,
const FX_CHAR* str2) {
- return CFX_ByteString(str1, str2);
+ return CFX_ByteString(str1.AsByteStringC(), str2);
}
inline CFX_ByteString operator+(const FX_CHAR* str1,
const CFX_ByteString& str2) {
- return CFX_ByteString(str1, str2);
+ return CFX_ByteString(str1, str2.AsByteStringC());
}
inline CFX_ByteString operator+(const CFX_ByteString& str1,
const CFX_ByteStringC& str2) {
- return CFX_ByteString(str1, str2);
+ return CFX_ByteString(str1.AsByteStringC(), str2);
}
inline CFX_ByteString operator+(const CFX_ByteStringC& str1,
const CFX_ByteString& str2) {
- return CFX_ByteString(str1, str2);
+ return CFX_ByteString(str1, str2.AsByteStringC());
}
class CFX_WideStringC {
@@ -758,7 +760,7 @@ inline CFX_ByteString FX_UTF8Encode(const CFX_WideString& wsStr) {
FX_FLOAT FX_atof(const CFX_ByteStringC& str);
inline FX_FLOAT FX_atof(const CFX_WideStringC& wsStr) {
- return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()));
+ return FX_atof(FX_UTF8Encode(wsStr.GetPtr(), wsStr.GetLength()).c_str());
}
void FX_atonum(const CFX_ByteStringC& str, FX_BOOL& bInteger, void* pData);
FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);