📄 vmstring.cpp
字号:
/*****************************************************************************/
/*
FUNCTION NAME: VMString::BufferSize
DESCRIPTION: query the internal size of this
INPUT: void
OUTPUT: none
RETURNS: size
*/
int VMString::BufferSize( void ) const
{
return( m_iSize );
}
/* End of function "VMString::BufferSize"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Realloc
DESCRIPTION: re-allocate the internal buffer
INPUT: dwSize - the new size
OUTPUT: none
RETURNS: void
*/
void VMString::Realloc( int dwSize )
{
_ASSERT( dwSize >= 0 );
FreeBuffer();
AllocBuffer( dwSize );
}
/* End of function "VMString::Realloc"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::GetBuffer
DESCRIPTION: returns a buffer of the requested size to the caller
INPUT: iSize - size of the buffer to get
OUTPUT: none
RETURNS: pointer to internal buffer
*/
TCHAR* VMString::GetBuffer( int iSize )
{
if ( iSize > GetLength() )
{
Realloc( iSize + 1 );
}
return( m_pchBuffer );
}
/* End of function "VMString::GetBuffer"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::GetBufferSetLength
DESCRIPTION: Gets a buffer of the requested size
INPUT: iSize - requested size
OUTPUT: none
RETURNS: pointer to the internal buffer
*/
TCHAR* VMString::GetBufferSetLength( int iSize )
{
return( GetBuffer( iSize ) );
}
/* End of function "VMString::GetBufferSetLength"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::ReleaseBuffer
DESCRIPTION: to make this compat. with MFC CString...no op here
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMString::ReleaseBuffer( void )
{
m_iLength = strlen( Buffer() );
}
/* End of function "VMString::ReleaseBuffer"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::ReleaseBuffer
DESCRIPTION: release bytes from the reserved buffer
INPUT: iSize - the size to set for the internal buffer
OUTPUT: none
RETURNS: void
*/
void VMString::ReleaseBuffer( int iSize )
{
if ( -1 != iSize )
{
if ( iSize < GetLength() )
{
Compact( iSize );
}
}
}
/* End of function "VMString::ReleaseBuffer"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Compact
DESCRIPTION: shrink the internal buffer
INPUT: iNewSize - the new size the buffer should be
OUTPUT: none
RETURNS: void
*/
void VMString::Compact( int iNewSize )
{
m_iLength = iNewSize;
Compact();
}
/* End of function "VMString::Compact"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Compact
DESCRIPTION: compact this to the size needed by the current buffer
contents
INPUT: void
OUTPUT: none
RETURNS: void
*/
void VMString::Compact( void )
{
if ( m_iLength + 1 < (int) m_iSize )
{
VMString oTemp = *this;
FreeBuffer();
AllocBuffer( oTemp.Length() + 1 );
CopyToBuffer( oTemp.Buffer(), oTemp.Length() );
}
}
/* End of function "VMString::Compact"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Length
DESCRIPTION: return the internal length of this
INPUT: void
OUTPUT: none
RETURNS: the internal length
*/
int VMString::Length( void ) const
{
return( m_iLength );
}
/* End of function "VMString::Length"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::IsEmpty
DESCRIPTION: query this for empty buffer
INPUT: void
OUTPUT: none
RETURNS: TRUE if buffer is empty, false if not
*/
BOOL VMString::IsEmpty( void ) const
{
return( ( 0 == m_iLength ) ? TRUE : FALSE );
}
/* End of function "VMString::IsEmpty"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::operator ==
DESCRIPTION: compare given parameter against internal buffer
INPUT: pchToCompare - pointer to string to compare against
OUTPUT: none
RETURNS: TRUE if equal, FALSE if not
*/
BOOL VMString::operator == ( const char* pchToCompare ) const
{
return( 0 == Compare( pchToCompare ) );
}
/* End of function "VMString::operator =="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::operator !=
DESCRIPTION: compare given parameter against internal buffer
INPUT: pchToCompare - pointer to string to compare against
OUTPUT: none
RETURNS: FALSE if equal, TRUE if not
*/
BOOL VMString::operator != ( const char*& pchToCompare ) const // 2b|!2b==?
{
return( 0 != Compare( pchToCompare ) );
}
/* End of function "VMString::operator !="
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Compare
DESCRIPTION: compare the internal buffer in this to value provided
INPUT: pchToCompare - pointer to string to compare against
OUTPUT: none
RETURNS: -1 if this is < pchToCompare
0 if this is = pchToCompare
1 if this is > pchToCompare
*/
int VMString::Compare( const char* pchToCompare ) const
{
_ASSERT( pchToCompare );
return( strcmp( m_pchBuffer, pchToCompare ) );
}
/* End of function "VMString::Compare"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Compare
DESCRIPTION: compare the internal buffer in this to value provided
and ignore case during the compare
INPUT: pchToCompare - pointer to string to compare against
OUTPUT: none
RETURNS: -1 if this is < pchToCompare
0 if this is = pchToCompare
1 if this is > pchToCompare
*/
int VMString::CompareNoCase( const char* pchToCompare ) const
{
_ASSERT( pchToCompare );
return( stricmp( m_pchBuffer, pchToCompare ) );
}
/* End of function "VMString::CompareNoCase"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::operator []
DESCRIPTION: returns a character at a specified index in the buffer
INPUT: iIndex - index of character to return
OUTPUT: none
RETURNS: TCHAR at position
*/
TCHAR& VMString::operator [] ( int iIndex )
{
return( m_pchBuffer[ iIndex ] );
}
/* End of function "VMString::operator []"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::operator []
DESCRIPTION: returns a character at a specified index in the buffer
INPUT: iIndex - index of character to return
OUTPUT: none
RETURNS: const TCHAR at position
*/
const TCHAR& VMString::operator [] ( int iIndex ) const
{
return( m_pchBuffer[ iIndex ] );
}
/* End of function "VMString::operator []"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Left
DESCRIPTION: return the left portion of this
INPUT: dwSize - number of characters from the left to return
OUTPUT: none
RETURNS: VMString
*/
VMString VMString::Left( int dwSize ) const
{
_ASSERT( dwSize >= 0 );
int iCopySize;
if ( dwSize > m_iLength )
{
iCopySize = m_iLength;
}
else
{
iCopySize = dwSize;
}
VMString oResult( iCopySize + 1 );
oResult.CopyToBuffer( m_pchBuffer, iCopySize );
return( oResult );
}
/* End of function "VMString::Left"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Right
DESCRIPTION: return the right side of this. results returned through
roResult. Included for compatibility with previous string
class
INPUT: iCount - number of characters to return
roResult - output will go here
OUTPUT:
RETURNS: void
*/
void VMString::Right( int iCount, VMString& roResult )
{
if ( iCount >= GetLength() )
{
roResult = *this;
return;
}
Mid( GetLength() - iCount, iCount, roResult );
}
/* End of function "VMString::Right"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Right
DESCRIPTION: return the right side of this
INPUT: dwSize - number of characters to return
OUTPUT: none
RETURNS: VMString
*/
VMString VMString::Right( int dwSize ) const
{
_ASSERT( dwSize >= 0 );
int iCopySize;
if ( dwSize > m_iLength )
{
iCopySize = m_iLength;
}
else
{
iCopySize = dwSize;
}
VMString oResult( iCopySize + 1 );
oResult.CopyToBuffer( m_pchBuffer + m_iLength - iCopySize, iCopySize );
return( oResult );
}
/* End of function "VMString::Right"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Mid
DESCRIPTION: return the characters from the "middle" of this. results
returned through roResult. Included for compatibility with
previous string class
INPUT: iStartAt - the index to start from
iCount - the number of characters from iStartAt to include
roResult - results placed here
OUTPUT:
RETURNS: void
*/
void VMString::Mid( int iStartAt, int iCount, VMString& roResult )
{
roResult = Mid( iStartAt, iCount );
}
/* End of function "VMString::Mid"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Mid
DESCRIPTION: return the characters from the "middle" of this.
INPUT: dwStart - the index to start from
OUTPUT:
RETURNS: VMString
*/
VMString VMString::Mid( int dwStart ) const
{
VMString oResult;
if ( dwStart + 1 > m_iLength )
{
return( oResult );
}
int iCopySize = m_iLength - dwStart;
oResult.UpdateBufferSize( iCopySize + 1 );
oResult.CopyToBuffer( m_pchBuffer + dwStart, iCopySize );
return( oResult );
}
/* End of function "VMString::Mid"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::Mid
DESCRIPTION: return the characters from the "middle" of this.
INPUT: dwStart - the index to start from
dwSize - the number of characters from iStartAt to include
OUTPUT:
RETURNS: VMString
*/
VMString VMString::Mid( int dwStart, int dwSize ) const
{
_ASSERT( dwStart >= 0 && dwSize >= 0 );
VMString oResult;
if ( dwStart + 1 > m_iLength )
{
return( oResult );
}
int iCopySize = m_iLength - dwStart;
if ( iCopySize > dwSize )
{
iCopySize = dwSize;
}
oResult.UpdateBufferSize( iCopySize + 1 );
oResult.CopyToBuffer( m_pchBuffer + dwStart, iCopySize );
return( oResult );
}
/* End of function "VMString::Mid"
/*****************************************************************************/
/*****************************************************************************/
/*
FUNCTION NAME: VMString::FindCount
DESCRIPTION: counts the number of times that pchToFind occurs in this
INPUT: pchToFind - pointer to string to search for in this
OUTPUT: none
RETURNS: count
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -