summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_string_c_template.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/cfx_string_c_template.h')
-rw-r--r--core/fxcrt/cfx_string_c_template.h46
1 files changed, 25 insertions, 21 deletions
diff --git a/core/fxcrt/cfx_string_c_template.h b/core/fxcrt/cfx_string_c_template.h
index 75c2be0efc..3a0ad74c08 100644
--- a/core/fxcrt/cfx_string_c_template.h
+++ b/core/fxcrt/cfx_string_c_template.h
@@ -11,6 +11,7 @@
#include <type_traits>
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "third_party/base/stl_util.h"
@@ -75,22 +76,23 @@ class CFX_StringCTemplate {
}
const_iterator begin() const {
- return reinterpret_cast<const CharType*>(m_Ptr);
+ return reinterpret_cast<const CharType*>(m_Ptr.Get());
}
const_iterator end() const {
- return m_Ptr ? reinterpret_cast<const CharType*>(m_Ptr) + m_Length
+ return m_Ptr ? reinterpret_cast<const CharType*>(m_Ptr.Get()) + m_Length
: nullptr;
}
bool operator==(const CharType* ptr) const {
return FXSYS_len(ptr) == m_Length &&
- FXSYS_cmp(ptr, reinterpret_cast<const CharType*>(m_Ptr), m_Length) ==
- 0;
+ FXSYS_cmp(ptr, reinterpret_cast<const CharType*>(m_Ptr.Get()),
+ m_Length) == 0;
}
bool operator==(const CFX_StringCTemplate& other) const {
return other.m_Length == m_Length &&
- FXSYS_cmp(reinterpret_cast<const CharType*>(other.m_Ptr),
- reinterpret_cast<const CharType*>(m_Ptr), m_Length) == 0;
+ FXSYS_cmp(reinterpret_cast<const CharType*>(other.m_Ptr.Get()),
+ reinterpret_cast<const CharType*>(m_Ptr.Get()),
+ m_Length) == 0;
}
bool operator!=(const CharType* ptr) const { return !(*this == ptr); }
bool operator!=(const CFX_StringCTemplate& other) const {
@@ -104,28 +106,28 @@ class CFX_StringCTemplate {
uint32_t strid = 0;
FX_STRSIZE size = std::min(4, m_Length - start_pos);
for (FX_STRSIZE i = 0; i < size; i++)
- strid = strid * 256 + m_Ptr[start_pos + i];
+ strid = strid * 256 + m_Ptr.Get()[start_pos + i];
return strid << ((4 - size) * 8);
}
- const UnsignedType* raw_str() const { return m_Ptr; }
+ const UnsignedType* raw_str() const { return m_Ptr.Get(); }
const CharType* c_str() const {
- return reinterpret_cast<const CharType*>(m_Ptr);
+ return reinterpret_cast<const CharType*>(m_Ptr.Get());
}
FX_STRSIZE GetLength() const { return m_Length; }
bool IsEmpty() const { return m_Length == 0; }
- UnsignedType GetAt(FX_STRSIZE index) const { return m_Ptr[index]; }
+ UnsignedType GetAt(FX_STRSIZE index) const { return m_Ptr.Get()[index]; }
CharType CharAt(FX_STRSIZE index) const {
- return static_cast<CharType>(m_Ptr[index]);
+ return static_cast<CharType>(m_Ptr.Get()[index]);
}
FX_STRSIZE Find(CharType ch) const {
- const UnsignedType* found = reinterpret_cast<const UnsignedType*>(
- FXSYS_chr(reinterpret_cast<const CharType*>(m_Ptr), ch, m_Length));
- return found ? found - m_Ptr : -1;
+ const UnsignedType* found = reinterpret_cast<const UnsignedType*>(FXSYS_chr(
+ reinterpret_cast<const CharType*>(m_Ptr.Get()), ch, m_Length));
+ return found ? found - m_Ptr.Get() : -1;
}
CFX_StringCTemplate Mid(FX_STRSIZE index, FX_STRSIZE count = -1) const {
@@ -136,14 +138,14 @@ class CFX_StringCTemplate {
if (count < 0 || count > m_Length - index)
count = m_Length - index;
- return CFX_StringCTemplate(m_Ptr + index, count);
+ return CFX_StringCTemplate(m_Ptr.Get() + index, count);
}
CFX_StringCTemplate Left(FX_STRSIZE count) const {
if (count <= 0)
return CFX_StringCTemplate();
- return CFX_StringCTemplate(m_Ptr, std::min(count, m_Length));
+ return CFX_StringCTemplate(m_Ptr.Get(), std::min(count, m_Length));
}
CFX_StringCTemplate Right(FX_STRSIZE count) const {
@@ -151,20 +153,22 @@ class CFX_StringCTemplate {
return CFX_StringCTemplate();
count = std::min(count, m_Length);
- return CFX_StringCTemplate(m_Ptr + m_Length - count, count);
+ return CFX_StringCTemplate(m_Ptr.Get() + m_Length - count, count);
}
- const UnsignedType& operator[](size_t index) const { return m_Ptr[index]; }
+ const UnsignedType& operator[](size_t index) const {
+ return m_Ptr.Get()[index];
+ }
bool operator<(const CFX_StringCTemplate& that) const {
- int result = FXSYS_cmp(reinterpret_cast<const CharType*>(m_Ptr),
- reinterpret_cast<const CharType*>(that.m_Ptr),
+ int result = FXSYS_cmp(reinterpret_cast<const CharType*>(m_Ptr.Get()),
+ reinterpret_cast<const CharType*>(that.m_Ptr.Get()),
std::min(m_Length, that.m_Length));
return result < 0 || (result == 0 && m_Length < that.m_Length);
}
protected:
- const UnsignedType* m_Ptr;
+ CFX_UnownedPtr<const UnsignedType> m_Ptr;
FX_STRSIZE m_Length;
private: