Esempio n. 1
0
UnicodeString& UnicodeString::Replace(size_t Pos, size_t Len, const wchar_t* Data, size_t DataLen)
{
	// Pos & Len must be valid
	assert(Pos <= m_pData->GetLength());
	assert(Len <= m_pData->GetLength());
	assert(Pos + Len <= m_pData->GetLength());
	// Data and *this must not intersect (but Data can be located entirely within *this)
	assert(!(Data < m_pData->GetData() && Data + DataLen > m_pData->GetData()));
	assert(!(Data < m_pData->GetData() + m_pData->GetLength() && Data + DataLen > m_pData->GetData() + m_pData->GetLength()));

	if (!Len && !DataLen)
		return *this;

	size_t NewLength = m_pData->GetLength() + DataLen - Len;

	if (m_pData->GetRef() == 1 && NewLength + 1 <= m_pData->GetSize())
	{
		if (NewLength)
		{
			if (Data >= m_pData->GetData() && Data + DataLen <= m_pData->GetData() + m_pData->GetLength())
			{
				// copy data from self
				UnicodeString TmpStr(Data, DataLen);
				wmemmove(m_pData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
				wmemcpy(m_pData->GetData() + Pos, TmpStr.CPtr(), TmpStr.GetLength());
			}
			else
			{
				wmemmove(m_pData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
				wmemcpy(m_pData->GetData() + Pos, Data, DataLen);
			}
		}

		m_pData->SetLength(NewLength);
	}
	else
	{
		if (!NewLength)
		{
			m_pData->DecRef();
			SetEUS();
			return *this;
		}

		UnicodeStringData *NewData = new UnicodeStringData(NewLength + 1);
		wmemcpy(NewData->GetData(), m_pData->GetData(), Pos);
		wmemcpy(NewData->GetData() + Pos, Data, DataLen);
		wmemcpy(NewData->GetData() + Pos + DataLen, m_pData->GetData() + Pos + Len, m_pData->GetLength() - Pos - Len);
		NewData->SetLength(NewLength);
		m_pData->DecRef();
		m_pData = NewData;
	}

	return *this;
}
Esempio n. 2
0
void UnicodeString::Inflate(size_t nSize)
{
	if (m_pData->GetRef() == 1)
	{
		m_pData->Inflate(nSize);
	}
	else
	{
		UnicodeStringData *pNewData = new UnicodeStringData(nSize);
		size_t nNewLength = Min(m_pData->GetLength(),nSize-1);
		wmemcpy(pNewData->GetData(),m_pData->GetData(),nNewLength);
		pNewData->SetLength(nNewLength);
		m_pData->DecRef();
		m_pData = pNewData;
	}
}
Esempio n. 3
0
		bool ContainsAny(const wchar_t *Chars, size_t nStartPos=0) const { return wcspbrk(m_pData->GetData()+nStartPos,Chars) != nullptr; }
Esempio n. 4
0
		operator const wchar_t *() const { return m_pData->GetData(); }
Esempio n. 5
0
		bool Contains(wchar_t Ch, size_t nStartPos=0) const { return wcschr(m_pData->GetData()+nStartPos,Ch) != nullptr; }
Esempio n. 6
0
		UnicodeString& Unlink() {Inflate(m_pData->GetLength()+1); return *this;}
Esempio n. 7
0
		const wchar_t *CPtr() const { return m_pData->GetData(); }
Esempio n. 8
0
		wchar_t Last() const { return m_pData->GetData()[m_pData->GetLength()?m_pData->GetLength()-1:0]; }
Esempio n. 9
0
		bool IsEmpty() const { return !(m_pData->GetLength() && *m_pData->GetData()); }
Esempio n. 10
0
		wchar_t First() const { return m_pData->GetData()[0]; }
Esempio n. 11
0
		wchar_t At(size_t nIndex) const { return m_pData->GetData()[nIndex]; }
Esempio n. 12
0
		size_t GetSize() const { return m_pData->GetSize(); }
Esempio n. 13
0
		size_t GetLength() const { return m_pData->GetLength(); }
Esempio n. 14
0
		~UnicodeString() { /*if (m_pData) он не должен быть nullptr*/ m_pData->DecRef(); }