本文整理汇总了C++中CopyBeforeWrite函数的典型用法代码示例。如果您正苦于以下问题:C++ CopyBeforeWrite函数的具体用法?C++ CopyBeforeWrite怎么用?C++ CopyBeforeWrite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CopyBeforeWrite函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw
/*
* @implemented
*/
void CHString::TrimLeft() throw (CHeap_Exception)
{
int NewBegin;
int NewLength;
WCHAR *CurrentChar;
// We'll modify, so copy first
CopyBeforeWrite();
// Start at the begin of the string
CurrentChar = m_pchData;
while (*CurrentChar != 0)
{
// Browse string till we find something which is not a space
if (!iswspace(*CurrentChar))
{
break;
}
CurrentChar++;
}
// Then, calculate new begin (easy) and new length
// And move memory
NewBegin = (CurrentChar - m_pchData);
NewLength = GetData()->nDataLength - NewBegin;
memmove(m_pchData, CurrentChar, NewLength * sizeof(WCHAR));
GetData()->nDataLength = NewLength;
}
示例2: SafeStrlen
int CString::Insert(int nIndex, LPCTSTR pstr)
{
if (nIndex < 0)
nIndex = 0;
int nInsertLength = SafeStrlen(pstr);
int nNewLength = GetData()->nDataLength;
if (nInsertLength > 0)
{
CopyBeforeWrite();
if (nIndex > nNewLength)
nIndex = nNewLength;
nNewLength += nInsertLength;
if (GetData()->nAllocLength < nNewLength)
{
CStringData* pOldData = GetData();
LPTSTR pstr = m_pchData;
AllocBuffer(nNewLength);
memcpy(m_pchData, pstr, (pOldData->nDataLength+1)*sizeof(TCHAR));
CString::Release(pOldData);
}
// move existing bytes down
memcpy(m_pchData + nIndex + nInsertLength,
m_pchData + nIndex,
(nNewLength-nIndex-nInsertLength+1)*sizeof(TCHAR));
memcpy(m_pchData + nIndex,
pstr, nInsertLength*sizeof(TCHAR));
GetData()->nDataLength = nNewLength;
}
return nNewLength;
}
示例3: CopyBeforeWrite
FX_STRSIZE CFX_WideString::Insert(FX_STRSIZE nIndex, FX_WCHAR ch)
{
CopyBeforeWrite();
if (nIndex < 0) {
nIndex = 0;
}
FX_STRSIZE nNewLength = GetLength();
if (nIndex > nNewLength) {
nIndex = nNewLength;
}
nNewLength++;
if (m_pData == NULL || m_pData->m_nAllocLength < nNewLength) {
StringData* pOldData = m_pData;
const FX_WCHAR* pstr = m_pData->m_String;
m_pData = StringData::Create(nNewLength);
if (!m_pData) {
return 0;
}
if(pOldData != NULL) {
FXSYS_memmove(m_pData->m_String, pstr, (pOldData->m_nDataLength + 1)*sizeof(FX_WCHAR));
pOldData->Release();
} else {
m_pData->m_String[0] = 0;
}
}
FXSYS_memmove(m_pData->m_String + nIndex + 1,
m_pData->m_String + nIndex, (nNewLength - nIndex)*sizeof(FX_WCHAR));
m_pData->m_String[nIndex] = ch;
m_pData->m_nDataLength = nNewLength;
return nNewLength;
}
示例4: CopyBeforeWrite
int CString::Insert(int nIndex, TCHAR ch)
{
CopyBeforeWrite();
if (nIndex < 0)
nIndex = 0;
int nNewLength = GetData()->nDataLength;
if (nIndex > nNewLength)
nIndex = nNewLength;
nNewLength++;
if (GetData()->nAllocLength < nNewLength)
{
CStringData* pOldData = GetData();
LPTSTR pstr = m_pchData;
AllocBuffer(nNewLength);
memcpy(m_pchData, pstr, (pOldData->nDataLength+1)*sizeof(TCHAR));
CString::Release(pOldData);
}
// move existing bytes down
memcpy(m_pchData + nIndex + 1,
m_pchData + nIndex, (nNewLength-nIndex)*sizeof(TCHAR));
m_pchData[nIndex] = ch;
GetData()->nDataLength = nNewLength;
return nNewLength;
}
示例5: ASSERT
void CString::SetAt(int nIndex, TCHAR ch)
{
ASSERT(nIndex >= 0);
ASSERT(nIndex < GetData()->nDataLength);
CopyBeforeWrite();
m_pchData[nIndex] = ch;
}
示例6: ASSERT
void CFX_WideString::SetAt(FX_STRSIZE nIndex, FX_WCHAR ch) {
if (m_pData == NULL) {
return;
}
ASSERT(nIndex >= 0);
ASSERT(nIndex < m_pData->m_nDataLength);
CopyBeforeWrite();
m_pData->m_String[nIndex] = ch;
}
示例7: CopyBeforeWrite
void CFX_WideString::MakeUpper() {
if (m_pData == NULL) {
return;
}
CopyBeforeWrite();
if (GetLength() < 1) {
return;
}
FXSYS_wcsupr(m_pData->m_String);
}
示例8: CopyBeforeWrite
void CString::ReleaseBuffer(int nNewLength)
{
CopyBeforeWrite(); // just in case GetBuffer was not called
if (nNewLength == -1)
nNewLength = lstrlen(m_pchData); // zero terminated
ASSERT(nNewLength <= GetData()->nAllocLength);
GetData()->nDataLength = nNewLength;
m_pchData[nNewLength] = '\0';
}
示例9: FXSYS_wcslen
FX_STRSIZE CFX_WideString::Replace(const FX_WCHAR* lpszOld, const FX_WCHAR* lpszNew)
{
if (GetLength() < 1) {
return 0;
}
if (lpszOld == NULL) {
return 0;
}
FX_STRSIZE nSourceLen = FXSYS_wcslen(lpszOld);
if (nSourceLen == 0) {
return 0;
}
FX_STRSIZE nReplacementLen = lpszNew ? FXSYS_wcslen(lpszNew) : 0;
FX_STRSIZE nCount = 0;
FX_WCHAR* lpszStart = m_pData->m_String;
FX_WCHAR* lpszEnd = m_pData->m_String + m_pData->m_nDataLength;
FX_WCHAR* lpszTarget;
{
while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
nCount++;
lpszStart = lpszTarget + nSourceLen;
}
}
if (nCount > 0) {
CopyBeforeWrite();
FX_STRSIZE nOldLength = m_pData->m_nDataLength;
FX_STRSIZE nNewLength = nOldLength + (nReplacementLen - nSourceLen) * nCount;
if (m_pData->m_nAllocLength < nNewLength || m_pData->m_nRefs > 1) {
StringData* pOldData = m_pData;
const FX_WCHAR* pstr = m_pData->m_String;
m_pData = StringData::Create(nNewLength);
if (!m_pData) {
return 0;
}
FXSYS_memcpy(m_pData->m_String, pstr, pOldData->m_nDataLength * sizeof(FX_WCHAR));
pOldData->Release();
}
lpszStart = m_pData->m_String;
lpszEnd = m_pData->m_String + FX_MAX(m_pData->m_nDataLength, nNewLength);
{
while ((lpszTarget = (FX_WCHAR*)FXSYS_wcsstr(lpszStart, lpszOld)) != NULL && lpszStart < lpszEnd) {
FX_STRSIZE nBalance = nOldLength - (FX_STRSIZE)(lpszTarget - m_pData->m_String + nSourceLen);
FXSYS_memmove(lpszTarget + nReplacementLen, lpszTarget + nSourceLen, nBalance * sizeof(FX_WCHAR));
FXSYS_memcpy(lpszTarget, lpszNew, nReplacementLen * sizeof(FX_WCHAR));
lpszStart = lpszTarget + nReplacementLen;
lpszStart[nBalance] = 0;
nOldLength += (nReplacementLen - nSourceLen);
}
}
ASSERT(m_pData->m_String[nNewLength] == 0);
m_pData->m_nDataLength = nNewLength;
}
return nCount;
}
示例10: length
wxStringImpl& wxStringImpl::append(size_t n, wxStringCharType ch)
{
size_type len = length();
if ( !Alloc(len + n) || !CopyBeforeWrite() ) {
wxFAIL_MSG( wxT("out of memory in wxStringImpl::append") );
return *this;
}
GetStringData()->nDataLength = len + n;
m_pchData[len + n] = '\0';
for ( size_t i = 0; i < n; ++i )
m_pchData[len + i] = ch;
return *this;
}
示例11: GetData
int CString::Delete(int nIndex, int nCount /* = 1 */)
{
if (nIndex < 0)
nIndex = 0;
int nNewLength = GetData()->nDataLength;
if (nCount > 0 && nIndex < nNewLength)
{
CopyBeforeWrite();
int nBytesToCopy = nNewLength - (nIndex + nCount) + 1;
memcpy(m_pchData + nIndex,
m_pchData + nIndex + nCount, nBytesToCopy * sizeof(TCHAR));
GetData()->nDataLength = nNewLength - nCount;
}
return nNewLength;
}
示例12: wxASSERT
wxStringImpl& wxStringImpl::insert(size_t nPos,
const wxStringCharType *sz, size_t n)
{
wxASSERT( nPos <= length() );
if ( n == npos ) n = wxStrlen(sz);
if ( n == 0 ) return *this;
if ( !Alloc(length() + n) || !CopyBeforeWrite() ) {
wxFAIL_MSG( wxT("out of memory in wxStringImpl::insert") );
return *this;
}
memmove(m_pchData + nPos + n, m_pchData + nPos,
(length() - nPos) * sizeof(wxStringCharType));
memcpy(m_pchData + nPos, sz, n * sizeof(wxStringCharType));
GetStringData()->nDataLength = length() + n;
m_pchData[length()] = '\0';
return *this;
}
示例13: FXSYS_assert
void CFX_WideString::TrimRight(const FX_WCHAR* lpszTargetList) {
FXSYS_assert(lpszTargetList != NULL);
if (m_pData == NULL || *lpszTargetList == 0) {
return;
}
CopyBeforeWrite();
FX_STRSIZE len = GetLength();
if (len < 1) {
return;
}
FX_STRSIZE pos = len;
while (pos) {
if (FXSYS_wcschr(lpszTargetList, m_pData->m_String[pos - 1]) == NULL) {
break;
}
pos--;
}
if (pos < len) {
m_pData->m_String[pos] = 0;
m_pData->m_nDataLength = pos;
}
}
示例14: FXSYS_assert
void CFX_WideString::TrimLeft(const FX_WCHAR* lpszTargets)
{
FXSYS_assert(lpszTargets != NULL);
if (m_pData == NULL || *lpszTargets == 0) {
return;
}
CopyBeforeWrite();
if (GetLength() < 1) {
return;
}
const FX_WCHAR* lpsz = m_pData->m_String;
while (*lpsz != 0) {
if (FXSYS_wcschr(lpszTargets, *lpsz) == NULL) {
break;
}
lpsz ++;
}
if (lpsz != m_pData->m_String) {
int nDataLength = m_pData->m_nDataLength - (FX_STRSIZE)(lpsz - m_pData->m_String);
FXSYS_memmove(m_pData->m_String, lpsz, (nDataLength + 1)*sizeof(FX_WCHAR));
m_pData->m_nDataLength = nDataLength;
}
}
示例15: CopyBeforeWrite
wxStringImpl::iterator wxStringImpl::begin()
{
if ( !empty() )
CopyBeforeWrite();
return m_pchData;
}