本文整理汇总了C++中StringData::Unique方法的典型用法代码示例。如果您正苦于以下问题:C++ StringData::Unique方法的具体用法?C++ StringData::Unique怎么用?C++ StringData::Unique使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringData
的用法示例。
在下文中一共展示了StringData::Unique方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Append
StringBase& Append(const wchar_t* lpData, size_t nLength, int nCodePage = CP_OEMCP)
{
if ( !lpData || !nLength ) //*lpData??
return *this;
size_t nNewLength = Traits::GetUnicodeDataLength(lpData, nLength, nCodePage);
size_t nSize = nNewLength+m_pData->GetLength();
if ( m_pData->Unique() && (nSize < m_pData->GetSize()) ) //check!!!
{
Traits::CopyUnicodeData(m_pData->GetData()+m_pData->GetLength(), nSize, lpData, nLength, nCodePage);
m_pData->SetLength(nSize);
}
else
{
StringData<T>* pNewData = new StringData<T>(nSize+1);
memcpy(pNewData->GetData(), m_pData->GetData(), m_pData->GetLength()*sizeof(T));
Traits::CopyUnicodeData(pNewData->GetData()+m_pData->GetLength(), nNewLength, lpData, nLength, nCodePage);
pNewData->SetLength(nSize);
FreeData();
m_pData = pNewData;
}
return *this;
}
示例2: SetData
StringBase& SetData(const char* lpData, size_t nLength, int nCodePage = CP_OEMCP)
{
m_nEncoding = nCodePage;
if ( !lpData || !nLength )
{
FreeData();
SetEmpty();
}
else
{
size_t nSize = Traits::GetAnsiDataLength(lpData, nLength, m_nEncoding);
if ( m_pData && m_pData->Unique() && (nSize < m_pData->GetSize()) )
{
Traits::CopyAnsiData(m_pData->GetData(), nSize, lpData, nLength, m_nEncoding);
m_pData->SetLength(nLength);
}
else
{
StringData<T>* pNewData = new StringData<T>(nSize+1);
Traits::CopyAnsiData(pNewData->GetData(), nSize, lpData, nLength, m_nEncoding);
pNewData->SetLength(nLength);
FreeData();
m_pData = pNewData;
}
}
return *this;
}
示例3: SetData
AsciiStringBase& SetData(const wchar_t* lpData, size_t nLength)
{
if ( !lpData || !nLength )
{
FreeData();
SetEmpty();
}
else
{
size_t nSize = WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, 0, 0, 0, 0);
if ( m_pData && m_pData->Unique() && (nSize < m_pData->GetSize()) )
{
WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, m_pData->GetData(), nSize, 0, 0);
m_pData->SetLength(nSize);
}
else
{
StringData<char>* pNewData = new StringData<char>(nSize+1);
WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, pNewData->GetData(), nSize, 0, 0);
pNewData->SetLength(nSize);
FreeData();
m_pData = pNewData;
}
}
return *this;
}
示例4: Append
AsciiStringBase& Append(const wchar_t* lpData, size_t nLength)
{
if ( !lpData || !nLength ) //*lpData??
return *this;
size_t nNewLength = WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, 0, 0, 0, 0);
size_t nSize = nNewLength+m_pData->GetLength();
if ( m_pData->Unique() && (nSize < m_pData->GetSize()) ) //check!!!
{
WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, m_pData->GetData()+m_pData->GetLength(), nNewLength, 0, 0);
m_pData->SetLength(nSize);
}
else
{
StringData<char>* pNewData = new StringData<char>(nSize+1);
memcpy(pNewData->GetData(), m_pData->GetData(), m_pData->GetLength());
WideCharToMultiByte(m_nEncoding, 0, lpData, nLength, pNewData->GetData()+m_pData->GetLength(), nNewLength, 0, 0);
pNewData->SetLength(nSize);
FreeData();
m_pData = pNewData;
}
return *this;
}
示例5: GetBuffer
T* GetBuffer(size_t nLength = (size_t)-1)
{
size_t nNewLength = (nLength == (size_t)-1)?m_pData->GetLength():nLength;
if ( !m_pData->Unique() || (nNewLength > m_pData->GetSize()) )
{
StringData<T>* pNewData = new StringData<T>(nNewLength+1);
memcpy(pNewData->GetData(), m_pData->GetData(), m_pData->GetLength()*sizeof(T));
pNewData->SetLength(m_pData->GetLength());
FreeData();
m_pData = pNewData;
}
return m_pData->GetData();
}