示例#1
0
void CString::ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData)
{
	//  -- the main routine for += operators

	// concatenating an empty string is a no-op!
	if (nSrcLen == 0)
		return;

	// if the buffer is too small, or we have a width mis-match, just
	//   allocate a new buffer (slow but sure)
	if (GetData()->nRefs > 1 || GetData()->nDataLength + nSrcLen > GetData()->nAllocLength)
	{
		// we have to grow the buffer, use the ConcatCopy routine
		CStringData* pOldData = GetData();
		ConcatCopy(GetData()->nDataLength, m_pchData, nSrcLen, lpszSrcData);
		ASSERT(pOldData != NULL);
		CString::Release(pOldData);
	}
	else
	{
		// fast concatenation when buffer big enough
		memcpy(m_pchData+GetData()->nDataLength, lpszSrcData, nSrcLen*sizeof(TCHAR));
		GetData()->nDataLength += nSrcLen;
		ASSERT(GetData()->nDataLength <= GetData()->nAllocLength);
		m_pchData[GetData()->nDataLength] = '\0';
	}
}
示例#2
0
/*
 * @implemented
 */
void CHString::ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData)
{
    // With null length, there's not that much to concat...
    if (nSrcLen == 0)
    {
        return;
    }

    // Still no negative length
    if (nSrcLen < 0)
    {
        RaiseException(ERROR_INVALID_PARAMETER, EXCEPTION_NONCONTINUABLE, 0, 0);
    }

    // Ensure we wouldn't overflow with the concat
    if (GetData()->nDataLength + nSrcLen > INT_MAX)
    {
        RaiseException(STATUS_INTEGER_OVERFLOW, EXCEPTION_NONCONTINUABLE, 0, 0);
    }

    // In case we have to modify a shared string OR if it can't fit into current buffer...
    if (GetData()->nRefs > 1 || GetData()->nDataLength + nSrcLen > GetData()->nAllocLength)
    {
        // Allocate a new buffer! (without forgetting to release old one)
        CHStringData* OldData = GetData();

        // You remember about "InPlace" in the function's name?
        // The cake is a lie
        ConcatCopy(GetData()->nDataLength, m_pchData, nSrcLen, lpszSrcData);
        Release(OldData);
    }
    else
    {
        // Ensure we don't overflow
        if (nSrcLen > INT_MAX)
        {
            RaiseException(STATUS_INTEGER_OVERFLOW, EXCEPTION_NONCONTINUABLE, 0, 0);
        }

        // Then, just copy and null terminate
        wcsncpy(m_pchData + GetData()->nDataLength, lpszSrcData, nSrcLen);
        GetData()->nDataLength += nSrcLen;
        m_pchData[GetData()->nDataLength] = 0;
    }
}
void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, const FX_WCHAR* lpszSrcData)
{
    if (nSrcLen == 0 || lpszSrcData == NULL) {
        return;
    }
    if (m_pData == NULL) {
        m_pData = StringData::Create(nSrcLen);
        if (m_pData) {
            FXSYS_memcpy(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
        }
        return;
    }
    if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) {
        ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData);
    } else {
        FXSYS_memcpy(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
        m_pData->m_nDataLength += nSrcLen;
        m_pData->m_String[m_pData->m_nDataLength] = 0;
    }
}
示例#4
0
void CStrClass::ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData)
{
	//	-- the main routine for += operators

	// if the buffer is too small, or we have a width mis-match, just
	//	 allocate a new buffer (slow but sure)
	if (m_nDataLength + nSrcLen > m_nAllocLength)
	{
		// we have to grow the buffer, use the Concat in place routine
		LPTSTR lpszOldData = m_pchData;
		ConcatCopy(m_nDataLength, lpszOldData, nSrcLen, lpszSrcData);
		SafeDelete(lpszOldData);
	}
	else
	{
		// fast concatenation when buffer big enough
		memcpy(&m_pchData[m_nDataLength], lpszSrcData, nSrcLen*sizeof(TCHAR));
		m_nDataLength += nSrcLen;
	}
	m_pchData[m_nDataLength] = '\0';
}
示例#5
0
void CFX_WideString::ConcatInPlace(FX_STRSIZE nSrcLen, FX_LPCWSTR lpszSrcData)
{
    if (nSrcLen == 0 || lpszSrcData == NULL) {
        return;
    }
    if (m_pData == NULL) {
        m_pData = FX_AllocStringW(nSrcLen);
        if (m_pData) {
            FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
        }
        return;
    }
    if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nAllocLength) {
        CFX_StringDataW* pOldData = m_pData;
        ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcData);
        FX_ReleaseStringW(pOldData);
    } else {
        FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData, nSrcLen * sizeof(FX_WCHAR));
        m_pData->m_nDataLength += nSrcLen;
        m_pData->m_String[m_pData->m_nDataLength] = 0;
    }
}
const CCOMStringW& CCOMStringW::operator+=(WCHAR ch)
{
	USES_CONVERSION;
	ConcatCopy(ch);
	return *this;
}
const CCOMStringW& CCOMStringW::operator+=(const WCHAR*  lpsz)
{
	ConcatCopy(lpsz);
	return *this;
}
const CCOMStringW& CCOMStringW::operator+=(CCOMStringW& strSrc)
{
	ConcatCopy((const WCHAR* ) strSrc);
	return *this;
}
const CCOMString& CCOMString::operator+=(BSTR bstrStr)
{
	USES_CONVERSION;
	ConcatCopy(OLE2T(bstrStr));
	return *this;
}
const CCOMString& CCOMString::operator+=(LPCTSTR lpsz)
{
	ConcatCopy(lpsz);
	return *this;
}
const CCOMString& CCOMString::operator+=(CCOMString& strSrc)
{
	ConcatCopy((LPCTSTR) strSrc);
	return *this;
}