本文整理汇总了C++中StringData::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::Release方法的具体用法?C++ StringData::Release怎么用?C++ StringData::Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::Release方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Insert
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;
}
示例2: GetBuffer
FX_WCHAR* CFX_WideString::GetBuffer(FX_STRSIZE nMinBufLength)
{
if (m_pData == NULL && nMinBufLength == 0) {
return NULL;
}
if (m_pData && m_pData->m_nRefs <= 1 && m_pData->m_nAllocLength >= nMinBufLength) {
return m_pData->m_String;
}
if (m_pData == NULL) {
m_pData = StringData::Create(nMinBufLength);
if (!m_pData) {
return NULL;
}
m_pData->m_nDataLength = 0;
m_pData->m_String[0] = 0;
return m_pData->m_String;
}
StringData* pOldData = m_pData;
FX_STRSIZE nOldLen = pOldData->m_nDataLength;
if (nMinBufLength < nOldLen) {
nMinBufLength = nOldLen;
}
m_pData = StringData::Create(nMinBufLength);
if (!m_pData) {
return NULL;
}
FXSYS_memcpy(m_pData->m_String, pOldData->m_String, (nOldLen + 1)*sizeof(FX_WCHAR));
m_pData->m_nDataLength = nOldLen;
pOldData->Release();
return m_pData->m_String;
}
示例3: Replace
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;
}
示例4: ConcatCopy
void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, const FX_WCHAR* lpszSrc1Data,
FX_STRSIZE nSrc2Len, const FX_WCHAR* lpszSrc2Data)
{
FX_STRSIZE nNewLen = nSrc1Len + nSrc2Len;
if (nNewLen <= 0) {
return;
}
// Don't release until done copying, might be one of the arguments.
StringData* pOldData = m_pData;
m_pData = StringData::Create(nNewLen);
if (m_pData) {
wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len);
wmemcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len);
}
pOldData->Release();
}