/* * @implemented */ CHString CHString::Mid(int nFirst, int nCount) const throw (CHeap_Exception) { CHString NewString; // Validate sizes first if (nFirst < 0) { nFirst = 0; } if (nCount < 0) { nCount = 0; } // Ensure we don't go beyond the string if (nFirst + nCount > GetData()->nDataLength) { nCount = GetData()->nDataLength - nFirst; } // Also ensure we don't read beyond // Yes, this should have been done before previous check // MS does it that way if (nFirst > GetData()->nDataLength) { nCount = 0; } AllocCopy(NewString, nCount, nFirst, 0); return NewString; }
CStrClass CStrClass::Left(int nCount) const { if (nCount > m_nDataLength) nCount = m_nDataLength; CStrClass dest; AllocCopy(dest, nCount, 0, 0); return dest; }
CString CString::Left(int nCount) const { if (nCount < 0) nCount = 0; if (nCount >= GetData()->nDataLength) return *this; CString dest; AllocCopy(dest, nCount, 0, 0); return dest; }
CStrClass CStrClass::Mid(int nFirst, int nCount) const { // out-of-bounds requests return sensible things if (nFirst + nCount > m_nDataLength) nCount = m_nDataLength - nFirst; if (nFirst > m_nDataLength) nCount = 0; CStrClass dest; AllocCopy(dest, nCount, nFirst, 0); return dest; }
CFX_WideString CFX_WideString::Right(FX_STRSIZE nCount) const { if (m_pData == NULL) { return CFX_WideString(); } if (nCount < 0) { nCount = 0; } if (nCount >= m_pData->m_nDataLength) { return *this; } CFX_WideString dest; AllocCopy(dest, nCount, m_pData->m_nDataLength - nCount); return dest; }
CFX_ByteString CFX_ByteString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { if (!m_pData) return CFX_ByteString(); nFirst = std::min(std::max(nFirst, 0), m_pData->m_nDataLength); nCount = std::min(std::max(nCount, 0), m_pData->m_nDataLength - nFirst); if (nCount == 0) return CFX_ByteString(); if (nFirst == 0 && nCount == m_pData->m_nDataLength) return *this; CFX_ByteString dest; AllocCopy(dest, nCount, nFirst); return dest; }
/* * @implemented */ CHString CHString::Left(int nCount) const throw (CHeap_Exception) { CHString NewString; // Validate input (we can't get more than what we have ;-)) if (nCount) { if (nCount > GetData()->nDataLength) { nCount = GetData()->nDataLength; } } AllocCopy(NewString, nCount, 0, 0); return NewString; }
CFX_WideString CFX_WideString::Mid(FX_STRSIZE nFirst, FX_STRSIZE nCount) const { if (m_pData == NULL) { return CFX_WideString(); } if (nFirst < 0) { nFirst = 0; } if (nCount < 0) { nCount = 0; } if (nFirst + nCount > m_pData->m_nDataLength) { nCount = m_pData->m_nDataLength - nFirst; } if (nFirst > m_pData->m_nDataLength) { nCount = 0; } if (nFirst == 0 && nFirst + nCount == m_pData->m_nDataLength) { return *this; } CFX_WideString dest; AllocCopy(dest, nCount, nFirst); return dest; }
CString CString::Mid(int nFirst, int nCount) const { // out-of-bounds requests return sensible things if (nFirst < 0) nFirst = 0; if (nCount < 0) nCount = 0; if (nFirst + nCount > GetData()->nDataLength) nCount = GetData()->nDataLength - nFirst; if (nFirst > GetData()->nDataLength) nCount = 0; ASSERT(nFirst >= 0); ASSERT(nFirst + nCount <= GetData()->nDataLength); // optimize case of returning entire string if (nFirst == 0 && nFirst + nCount == GetData()->nDataLength) return *this; CString dest; AllocCopy(dest, nCount, nFirst, 0); return dest; }