7#include "core/fxcrt/string_data_template.h"
13#include "core/fxcrt/fx_memcpy_wrappers.h"
14#include "core/fxcrt/fx_memory.h"
15#include "core/fxcrt/fx_safe_types.h"
16#include "third_party/base/check.h"
17#include "third_party/base/check_op.h"
22template <
typename CharType>
29 int overhead = offsetof(StringDataTemplate, m_String) +
sizeof(CharType);
30 FX_SAFE_SIZE_T nSize = nLen;
31 nSize *=
sizeof(CharType);
40 size_t totalSize = nSize.ValueOrDie();
41 size_t usableLen = (totalSize - overhead) /
sizeof(CharType);
42 DCHECK(usableLen >= nLen);
44 void* pData = FX_StringAlloc(
char, totalSize);
49template <
typename CharType>
54 result->CopyContents(pStr, nLen);
58template <
typename CharType>
64template <
typename CharType>
67 DCHECK(other.m_nDataLength <= m_nAllocLength);
69 (other.m_nDataLength + 1) *
sizeof(CharType));
72template <
typename CharType>
76 DCHECK_LE(nLen, m_nAllocLength);
77 FXSYS_memcpy(
m_String, pStr, nLen *
sizeof(CharType));
81template <
typename CharType>
85 DCHECK_GE(offset, 0u);
87 DCHECK_LE(offset + nLen, m_nAllocLength);
88 FXSYS_memcpy(
m_String + offset, pStr, nLen *
sizeof(CharType));
92template <
typename CharType>
95 : m_nDataLength(dataLen), m_nAllocLength(allocLen) {
96 DCHECK_GE(dataLen, 0u);
97 DCHECK_LE(dataLen, allocLen);
void CopyContents(const CharType *pStr, size_t nLen)
void CopyContents(const StringDataTemplate &other)
void CopyContentsAt(size_t offset, const CharType *pStr, size_t nLen)
void StringDealloc(void *ptr)