Click here to Skip to main content
15,896,726 members
Articles / Containers / Virtual Machine

TOOL

Rate me:
Please Sign up or sign in to vote.
4.98/5 (52 votes)
23 Oct 200676 min read 231.4K   5.4K   147  
TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language interpreter. The purpose of this article is to introduce the TOOL interpreter and language from the perspective of a person who has a desire to include a scripting solution as part of his project.
/*****************************************************************************/
/*                              SOURCE FILE                                  */
/*****************************************************************************/
/*
       $Archive:   $

      $Revision:   $
          $Date:   $
        $Author:   $

    Description:   Implementation of a string class that does not require MFC

                      TOOL And XML FORMS License
                      ==========================

                      Except where otherwise noted, all of the documentation 
                      and software included in the TOOL package is 
                      copyrighted by Michael Swartzendruber.

                      Copyright (C) 2005 Michael John Swartzendruber. 
                      All rights reserved.

                      Access to this code, whether intentional or accidental,
                      does NOT IMPLY any transfer of rights.

                      This software is provided "as-is," without any express 
                      or implied warranty. In no event shall the author be held
                      liable for any damages arising from the use of this software.

                      Permission is granted to anyone to use this software for 
                      any purpose, including commercial applications, and to 
                      alter and redistribute it, provided that the following 
                      conditions are met:

                      1. All redistributions of source code files must retain 
                         all copyright notices that are currently in place, 
                         and this list of conditions without modification.

                      2. The origin of this software must not be misrepresented;
                         you must not claim that you wrote the original software.

                      3. If you use this software in another product, an acknowledgment
                         in the product documentation would be appreciated but is
                         not required.

                      4. Modified versions in source or binary form must be plainly 
                         marked as such, and must not be misrepresented as being 
                         the original software.
*/
static char OBJECT_ID[] = "$Revision:   $ : $Date:   $";
/*****************************************************************************/

#pragma warning( disable : 4297 )

#include <stdio.h>
#include <new>            // for std::bad_alloc
#include <crtdbg.h>       // for _ASSERT
#include "FastString.h"

std::bad_alloc CFastStringBadAlloc;

// CFastString allocation extra size; if no extra allocation is wanted
// then set CFastStringA_EXTRA_SIZE to 0
//
int CFastString::BUFFER_EXTRA_SIZE = 16;

// do not modify the following constants
//
int CFastString::FORMAT_EXTRA_SIZE = 32;
int CFastString::INT_SIZE          = 16;
int CFastString::LONG_SIZE         = 16;
int CFastString::ULONG_SIZE        = 20;



/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::AllocBuffer

       DESCRIPTION:  allocates a buffer of the given size

             INPUT:  dwSize - size to reserve
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::AllocBuffer( int dwSize )
{
  _ASSERT( dwSize > 0 );
  m_iSize     = dwSize;
  m_pchBuffer = (TCHAR*) malloc( CFastString::TLEN( m_iSize ) );
  memset( m_pchBuffer, 0, m_iSize );
  _ASSERT( m_pchBuffer );
  if ( !m_pchBuffer )
  {
    throw CFastStringBadAlloc;
  }
}
/* End of function "CFastString::AllocBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::FreeBuffer

       DESCRIPTION:  free the internal buffer

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  void 
*/
inline void CFastString::FreeBuffer( void )
{
  _ASSERT( m_pchBuffer );

  if ( m_pchBuffer )
  {
    free( m_pchBuffer );
    m_pchBuffer = NULL;
    m_iSize     = 0;
    m_iLength   = 0;
  }
}
/* End of function "CFastString::FreeBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::Initialize

       DESCRIPTION:  initialize this to the defined size

             INPUT:  dwAllocSize - size to pre-allocate
            OUTPUT:  none

           RETURNS:  void   
*/
void CFastString::Initialize( int dwAllocSize )
{
  _ASSERT( dwAllocSize > 0 );

  m_pchBuffer = NULL;
  m_iSize     = 0;
  m_iLength   = 0;

  AllocBuffer( GetPaddedSize( dwAllocSize ) );

  m_pchBuffer[0] = '\0';
}
/* End of function "CFastString::Initialize"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::GetPaddedSize

       DESCRIPTION:  Adds the internal buffer pad value to the requested size

             INPUT:  dwSize - requested size
            OUTPUT:  none

           RETURNS:  padded size 
*/
inline int CFastString::GetPaddedSize( int dwSize )
{
  _ASSERT( BUFFER_EXTRA_SIZE >= 0 );

  return( dwSize + BUFFER_EXTRA_SIZE );
}
/* End of function "CFastString::GetPaddedSize"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::UpdateBufferSize

       DESCRIPTION:  re-allocates the internal buffer to the requested size

             INPUT:  dwSize - new size to pre-reserve
            OUTPUT:  none

           RETURNS:  void 
*/
void CFastString::UpdateBufferSize( const int dwSize )
{
  _ASSERT( dwSize >= 0 );

  if ( m_iSize < dwSize )
  {
    FreeBuffer();
    AllocBuffer( GetPaddedSize( dwSize ) );
  }
}
/* End of function "CFastString::UpdateBufferSize"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::CopyToBuffer

       DESCRIPTION:  copies the string passed to this to the internal buffer

             INPUT:  chSource -  pointer to the string to copy
                     dwSize - size of the string to copy
            OUTPUT:  

           RETURNS:  void
*/
void CFastString::CopyToBuffer( const char* pchSource, int dwSize )
{
  _ASSERT( pchSource && dwSize >= 0 );

  memcpy( m_pchBuffer, pchSource, CFastString::TLEN( dwSize ) ); 
  m_pchBuffer[ dwSize ] = '\0';
  m_iLength             = dwSize;
}
/* End of function "CFastString::CopyToBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::TLEN

       DESCRIPTION:  returns the number of bytes scaled up the size of each
                     buffer cell size

             INPUT:  iLength - length to multiply
            OUTPUT:  none

           RETURNS:  byte count of length x size of each cell
*/
inline int CFastString::TLEN( int iLength )
{
  return( iLength * sizeof( TCHAR ) );
}
/* End of function "CFastString::TLEN"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::CFastString

       DESCRIPTION:  ctor. inits this

             INPUT:  void
            OUTPUT:  none

           RETURNS:  none
*/
CFastString::CFastString( void ) 
{
  Initialize();
}
/* End of function "CFastString::CFastString"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::~CFastString

       DESCRIPTION:  dtor. clean up allocations

             INPUT:  void
            OUTPUT:  none

           RETURNS:  none
*/
CFastString::~CFastString( void )
{
  FreeBuffer();
}
/* End of function "CFastString::~CFastString"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::CFastString

       DESCRIPTION:  copy constructor

             INPUT:  roOther - other instance
            OUTPUT:  none

           RETURNS:  none
*/
CFastString::CFastString( const CFastString& roOther )
{
  Initialize( roOther.Length() + 1 );
  *this = roOther;
}
/* End of function "CFastString::CFastString"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::CFastString

       DESCRIPTION:  construct with string

             INPUT:  pchValue - pointer to string to assign to this
            OUTPUT:  none

           RETURNS:  none
*/
CFastString::CFastString( const char* pchValue )
{
  _ASSERT( pchValue );

  Initialize( _tcslen( pchValue ) + 1 );
  *this = pchValue;
}
/* End of function "CFastString::CFastString"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::CFastString

       DESCRIPTION:  construct and pre-allocate a number of bytes in the buffer

             INPUT:  dwAllocSize - initial size to reserve for this
            OUTPUT:  none

           RETURNS:  none
*/
CFastString::CFastString( int dwAllocSize )
{
  Initialize( dwAllocSize > 0 ? dwAllocSize : 1 );
}
/* End of function "CFastString::CFastString"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  roOther - the other instance of this class to construct
                               from
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( const CFastString& roOther )
{
  if ( this == &roOther )
  {
    return( *this );
  }
  
  UpdateBufferSize( roOther.Length() + 1 );
  CopyToBuffer( roOther.Buffer(), roOther.Length() );

  return( *this );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  pchValue - pointer to initial value
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( const char* pchValue )
{
  _ASSERT( pchValue );

  int dwLen = _tcslen( pchValue );
  UpdateBufferSize( dwLen + 1 );
  CopyToBuffer( pchValue,  dwLen );
  
  return( *this );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  iValue - initial value
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( int iValue )
{
  return( SetInt( iValue ) );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  lValue - initial value
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( long lValue )
{
  return( SetLong( lValue ) );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  ulValue - initial value
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( unsigned long ulValue )
{
  return( SetULong( ulValue ) );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator = 

       DESCRIPTION:  assignment construction

             INPUT:  dblValue - initial value
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::operator = ( double dblValue )
{
  return( SetDouble( dblValue ) );
}
/* End of function "CFastString::operator = "
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME: CFastString::operator const char* 

       DESCRIPTION:  internal buffer access

             INPUT:  void 
            OUTPUT:  none

           RETURNS:  const pointer to internal buffer
*/
CFastString::operator const char* ( void ) const
{
  return( m_pchBuffer );
}
/* End of function "CFastString::operator const char*"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Buffer

       DESCRIPTION:  buffer access

             INPUT:  void - 
            OUTPUT:  none

           RETURNS:  const pointer to internal buffer
*/
TCHAR* CFastString::Buffer( void ) const
{
  return( m_pchBuffer );
}
/* End of function "CFastString::Buffer"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Buffer

       DESCRIPTION:  buffer access

             INPUT:  void - 
            OUTPUT:  none

           RETURNS:  pointer to internal buffer
*/
TCHAR* CFastString::Buffer( void )
{
  return( m_pchBuffer );
}
/* End of function "CFastString::Buffer"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::BufferSize

       DESCRIPTION:  query the internal size of this

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  size 
*/
int CFastString::BufferSize( void ) const
{
  return( m_iSize );
}
/* End of function "CFastString::BufferSize"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Realloc

       DESCRIPTION:  re-allocate the internal buffer

             INPUT:  dwSize - the new size
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::Realloc( int dwSize )
{
  _ASSERT( dwSize >= 0 );

  FreeBuffer();
  AllocBuffer( dwSize );
}
/* End of function "CFastString::Realloc"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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* CFastString::GetBuffer( int iSize ) 
{
  if ( iSize > GetLength() )
  {
    Realloc( iSize + 1 );
  }
  return( m_pchBuffer );
}
/* End of function "CFastString::GetBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  CFastString::GetBufferSetLength

       DESCRIPTION:  Gets a buffer of the requested size

             INPUT:  iSize - requested size
            OUTPUT:  none

           RETURNS:  pointer to the internal buffer
*/
TCHAR* CFastString::GetBufferSetLength( int iSize ) 
{
  return( GetBuffer( iSize ) );
}
/* End of function "CFastString::GetBufferSetLength"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::ReleaseBuffer

       DESCRIPTION:  to make this compat. with MFC CString...no op here

             INPUT:  void 
            OUTPUT:  none

           RETURNS:  void 
*/
void CFastString::ReleaseBuffer( void )
{
 m_iLength = strlen( Buffer() );
}
/* End of function "CFastString::ReleaseBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::ReleaseBuffer

       DESCRIPTION:  release bytes from the reserved buffer

             INPUT:  iSize - the size to set for the internal buffer
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::ReleaseBuffer( int iSize )
{
  if ( -1 != iSize )
  {
    if ( iSize < GetLength() )
    {
      Compact( iSize );
    }
  }
}
/* End of function "CFastString::ReleaseBuffer"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Compact

       DESCRIPTION:  shrink the internal buffer

             INPUT:  iNewSize - the new size the buffer should be
            OUTPUT:  none

           RETURNS:  void 
*/
void CFastString::Compact( int iNewSize )
{
  m_iLength = iNewSize;
  Compact();
}
/* End of function "CFastString::Compact"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Compact

       DESCRIPTION:  compact this to the size needed by the current buffer 
                     contents

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  void 
*/
void CFastString::Compact( void )
{
  if ( m_iLength + 1 < (int) m_iSize )
  {
    CFastString oTemp = *this;
    FreeBuffer();
    AllocBuffer( oTemp.Length() + 1 );
    CopyToBuffer( oTemp.Buffer(), oTemp.Length() );
  }
}
/* End of function "CFastString::Compact"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Length

       DESCRIPTION:  return the internal length of this

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  the internal length
*/
int CFastString::Length( void ) const
{
  return( m_iLength );
}
/* End of function "CFastString::Length"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::IsEmpty

       DESCRIPTION:  query this for empty buffer

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  TRUE if buffer is empty, false if not
*/
BOOL CFastString::IsEmpty( void ) const
{
  return( ( 0 == m_iLength ) ? TRUE : FALSE );
}
/* End of function "CFastString::IsEmpty"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::operator == ( const char* pchToCompare ) const
{
  return( 0 == Compare( pchToCompare ) );
}
/* End of function "CFastString::operator =="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::operator != ( const char*& pchToCompare ) const
{
  return( 0 != Compare( pchToCompare ) );
}
/* End of function "CFastString::operator !="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::Compare( const char* pchToCompare ) const
{
  _ASSERT( pchToCompare );

  return( _tcscmp( m_pchBuffer, pchToCompare ) );
}
/* End of function "CFastString::Compare"
/*****************************************************************************/


/*****************************************************************************/
/*
     FUNCTION NAME:  <, <=, >, >=, ==, != 

       DESCRIPTION:  various logical operators for this class

             INPUT:  roTest - another instance of this class to compare against
            OUTPUT:  none

           RETURNS:  returns the results of the comparison of the data contained
                     in this instance and the other instance of this class type
*/
bool CFastString::operator < ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( false );
  }

  if ( -1 == Compare( roTest.Buffer() ) )
  {
    return( true );
  }

  return( false );
}
       
bool CFastString::operator <= ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( true );
  }

  int iLess = Compare( roTest.Buffer() );
  if ( -1 == iLess || iLess == 0 ) 
  {
    return( true );
  }

  return( false );
}
       
bool CFastString::operator > ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( false );
  }

  if ( 1 == Compare( roTest.Buffer() ) )
  {
    return( true );
  }

  return( false );
}
       
bool CFastString::operator >= ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( true );
  }

  int iLess = Compare( roTest.Buffer() ); 
  if ( 1 == iLess || iLess == 0 )
  {
    return( true );
  }

  return( false );
}
       
bool CFastString::operator == ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( true );
  }

  if ( 0 == Compare( roTest.Buffer() ) )
  {
    return( true );
  }

  return( false );
}
       
bool CFastString::operator != ( const CFastString& roTest )
{ 
  if ( &roTest == this )
  {
    return( false );
  }

  int iLess = Compare( roTest.Buffer() ); 
  if ( -11 == iLess || iLess == 1 )
  {
    return( true );
  }

  return( false );
}
/* End of function "= <, <=, >, >=, ==, !="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::CompareNoCase( const char* pchToCompare ) const
{
  _ASSERT( pchToCompare );
  return( _tcsicmp( m_pchBuffer, pchToCompare ) );
}
/* End of function "CFastString::CompareNoCase"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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& CFastString::operator [] ( int iIndex )
{
  return( m_pchBuffer[ iIndex ] );
}
/* End of function "CFastString::operator []"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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& CFastString::operator [] ( int iIndex ) const
{
  return( m_pchBuffer[ iIndex ] );
}
/* End of function "CFastString::operator []"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Left

       DESCRIPTION:  return the left portion of this

             INPUT:  dwSize - number of characters from the left to return
            OUTPUT:  none

           RETURNS:  CFastString
*/
CFastString CFastString::Left( int dwSize ) const
{
  _ASSERT( dwSize >= 0 );

  int  iCopySize;
  
  if ( dwSize > m_iLength )
  {
    iCopySize = m_iLength;
  }
  else
  {
    iCopySize = dwSize;
  }
  
  CFastString  oResult( iCopySize + 1 );
  oResult.CopyToBuffer( m_pchBuffer, iCopySize );

  return( oResult );
}
/* End of function "CFastString::Left"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::Right( int iCount, CFastString& roResult )
{
  if ( iCount >= GetLength() ) 
  {
    roResult = *this;
    return;
  }
  Mid( GetLength() - iCount, iCount, roResult );
}
/* End of function "CFastString::Right"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Right

       DESCRIPTION:  return the right side of this

             INPUT:  dwSize - number of characters to return
            OUTPUT:  none

           RETURNS:  CFastString  
*/
CFastString CFastString::Right( int dwSize ) const
{
  _ASSERT( dwSize >= 0 );

  int  iCopySize;
  
  if ( dwSize > m_iLength )
  {
    iCopySize = m_iLength;
  }
  else
  {
    iCopySize = dwSize;
  }
  
  CFastString  oResult( iCopySize + 1 );
  oResult.CopyToBuffer( m_pchBuffer + m_iLength - iCopySize, iCopySize );

  return( oResult );
}
/* End of function "CFastString::Right"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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 CFastString::Mid( int iStartAt, int iCount, CFastString& roResult )
{
  roResult = Mid( iStartAt, iCount );
}
/* End of function "CFastString::Mid"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Mid

       DESCRIPTION:  return the characters from the "middle" of this.

             INPUT:  dwStart - the index to start from
            OUTPUT:  

           RETURNS:  CFastString   
*/
CFastString CFastString::Mid( int dwStart ) const
{
  CFastString  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 "CFastString::Mid"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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:  CFastString   
*/
CFastString CFastString::Mid( int dwStart, int dwSize ) const
{
  _ASSERT( dwStart >= 0 && dwSize >= 0 );

  CFastString  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 "CFastString::Mid"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::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
*/
int CFastString::FindCount( const char* pchToFind ) const
{
  _ASSERT( pchToFind );
  return FindCount( 0, pchToFind );
}
/* End of function "CFastString::FindCount"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::FindCount

       DESCRIPTION:  counts the number of times that pchToFind occurs in this
                     after the starting position (inclusive)

             INPUT:  iStartAt - index from which to start the search
                     pchToFind - pointer to string to search for in this
            OUTPUT:  

           RETURNS:  count
*/
int  CFastString::FindCount( int iStartAt, const char* pchToFind ) const
{
  _ASSERT( iStartAt >= 0 && pchToFind );

  LPTSTR  pchHead = m_pchBuffer + iStartAt;
  LPTSTR  pchNext;
  int     iCount = 0;
  int     iSubSize = _tcslen( pchToFind );
  
  if ( 0 == iSubSize )
  {
    return( 0 );
  }

  pchNext = _tcsstr( pchHead, pchToFind );

  while ( pchNext )
  {
    iCount++;
    pchHead = pchNext + iSubSize;
    pchNext = _tcsstr( pchHead, pchToFind );
  }

  return( iCount );
}
/* End of function "CFastString::FindCount"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Find

       DESCRIPTION:  find the first occurance of pchToFind in this and return
                     the index of that occurance

             INPUT:  pchToFind - pointer to the string to search for
            OUTPUT:  none

           RETURNS:  the index if found, -1 if not found
*/
int CFastString::Find( const char* pchToFind, int iStartAt ) const
{
  _ASSERT( pchToFind );
  LPTSTR  pchNext;

  if ( iStartAt > m_iLength )
  {
    return( -1 );
  }

  pchNext = _tcsstr( m_pchBuffer + iStartAt, pchToFind );
  if ( pchNext )
  {
    return( pchNext - m_pchBuffer );
  }  
  return( -1 );
}
/* End of function "CFastString::Find"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Find

       DESCRIPTION:  find the first occurance of pchToFind in this and return
                     the index of that occurance

             INPUT:  pchToFind - pointer to the string to search for
            OUTPUT:  none

           RETURNS:  the index if found, -1 if not found
*/
int CFastString::Find( const char* pchToFind ) const
{
  _ASSERT( pchToFind );
  LPTSTR  pchNext;
  
  pchNext = _tcsstr( m_pchBuffer, pchToFind );
  if ( pchNext )
  {
    return( pchNext - m_pchBuffer );
  }  
  return( -1 );
}
/* End of function "CFastString::Find"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Find

       DESCRIPTION:  find the first occurance of pchToFind in this and return
                     the index of that occurance

             INPUT:  chToFind - pointer to the string to search for
            OUTPUT:  none

           RETURNS:  the index if found, -1 if not found
*/
int CFastString::Find( const char chToFind ) const
{
  LPTSTR  pchNext;
  
  pchNext = _tcschr( m_pchBuffer, chToFind );
  if ( pchNext )
  {
    return( pchNext - m_pchBuffer );
  }  
  return( -1 );
}
/* End of function "CFastString::Find"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::FindNthOf

       DESCRIPTION:  locates the 'nth' occurance of pchToFind in this

             INPUT:  iOccurance - the occurance to locate
                     pchToFind - the string to locate
            OUTPUT:  

           RETURNS:  index of the given occurance, -1 if not found
*/
int CFastString::FindNthOf( int iOccurance, const char* pchToFind ) const
{
  _ASSERT( iOccurance > 0 && pchToFind );

  LPTSTR pchNext;
  LPTSTR pchHead  = m_pchBuffer;
  int    iSubSize = _tcslen( pchToFind );

  pchNext = _tcsstr( pchHead, pchToFind );
  if ( pchNext )
  {
    iOccurance--;
  }
  while ( pchNext && iOccurance > 0 )
  {
    pchHead = pchNext + iSubSize;
    pchNext = _tcsstr( pchHead, pchToFind );
    if ( pchNext ) 
    { 
      iOccurance--; 
    };
  }
  if ( 0 == iOccurance )
  {
    return( pchNext - m_pchBuffer );
  }
  return( -1 );
}
/* End of function "CFastString::FindNthOf"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::ReverseFind

       DESCRIPTION:  finds the first occurance of pchToFind in this, from the
                     "right edge" of the buffer

             INPUT:  pchToFind - pointer to the string to find.
            OUTPUT:  none

           RETURNS:  index of the occurance, -1 if not found
*/
int CFastString::ReverseFind( const char* pchToFind ) const
{
  _ASSERT( pchToFind );

  LPTSTR  pchHead = m_pchBuffer;
  LPTSTR  pchNext;
  int     iSubSize = _tcslen( pchToFind );
  int     iIndex = -1;

  pchNext = _tcsstr( pchHead, pchToFind );
  while ( pchNext )
  {
    iIndex  = pchNext - m_pchBuffer;
    pchHead = pchNext + iSubSize;
    pchNext = _tcsstr( pchHead, pchToFind );
  }
  return( iIndex );
}
/* End of function "CFastString::ReverseFind"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::ReverseFindNthOf

       DESCRIPTION:  locates the nth occurance of pchToFind from the "right end"
                     of the buffer

             INPUT:  iOccurance - the occurance to find
                     pchToFind - the string to search for
            OUTPUT:  

           RETURNS:  index of location , -1 if not found
*/
int CFastString::ReverseFindNthOf( int iOccurance, const char* pchToFind ) const
{
  _ASSERT( iOccurance > 0 && pchToFind );

  int iCount = FindCount( pchToFind );
  if ( iCount >= iOccurance )
  {
    return( FindNthOf( iCount + 1 - iOccurance,  pchToFind ) );
  }
  return( -1 );
}
/* End of function "CFastString::ReverseFindNthOf"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Empty

       DESCRIPTION:  empties the buffer in this

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Empty( void )
{
  m_pchBuffer[0] = '\0';
  m_iLength      = 0;
  return( *this );
}
/* End of function "CFastString::Empty"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Fill

       DESCRIPTION:  fills this with the specified character

             INPUT:  chFillChar - the fill character 
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Fill( const TCHAR chFillChar )
{
  _tcsnset( m_pchBuffer, chFillChar, m_iLength );
  return( *this );
}
/* End of function "CFastString::Fill"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Trim

       DESCRIPTION:  trim both

             INPUT:  void
            OUTPUT:  none

           RETURNS:  trimmed version of this
*/
CFastString& CFastString::Trim( void )
{
  return( TrimLeft().TrimRight() );
}
/* End of function "CFastString::Trim"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::TrimQuotes

       DESCRIPTION:  

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  reference to this
*/
CFastString& CFastString::TrimQuotes( void )
{
  TCHAR* pchHead = m_pchBuffer;
  
  if ( m_pchBuffer[ 0 ]  == '"' )
  {
    m_pchBuffer[ 0 ] = ' ';
  }
  if ( m_pchBuffer[ m_iLength - 1 ] == '"' )
  {
    m_pchBuffer[ m_iLength - 1 ] = ' ';
  } 
  return( TrimLeft().TrimRight() );
}
/* End of function "CFastString::TrimQuotes"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::TrimLeft

       DESCRIPTION:  trim leading spaces in this

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::TrimLeft( void )
{
  TCHAR* pchHead = m_pchBuffer;
  
  while ( _istspace( *pchHead ) )
  {
    pchHead = _tcsinc( pchHead );
  }
  if ( pchHead != m_pchBuffer )
  {
    int iMoveBy = m_iLength - ( pchHead - m_pchBuffer );
    memmove( m_pchBuffer, pchHead, CFastString::TLEN( iMoveBy + 1 ) );
    m_iLength -= m_iLength - iMoveBy;
  }
  return( *this );
}
/* End of function "CFastString::TrimLeft"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::TrimRight

       DESCRIPTION:  trim trailing spaces from this

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::TrimRight( void )
{
  int    iTailIndex    = ( m_iLength > 0 ) ? m_iLength - 1 : 0;
  TCHAR* pchTail       = m_pchBuffer + iTailIndex;
  int    iTrimSize     = 0;

  while ( NULL != pchTail && _istspace( *pchTail ) )
  {
    pchTail = _tcsdec( m_pchBuffer, pchTail );
    iTrimSize++;
  }
  if ( iTrimSize > 0 )
  {
    m_pchBuffer[ iTailIndex + 1 - iTrimSize ] = '\0';
    m_iLength -= iTrimSize;
  }
  return( *this );
}
/* End of function "CFastString::TrimRight"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Truncate

       DESCRIPTION:  shorten this to the size indicated

             INPUT:  dwSize - the new size for this
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Truncate( int dwSize )
{
  if ( dwSize + 1 > m_iLength )
  {
    return( *this );
  }
  m_pchBuffer[ dwSize ] = '\0';
  m_iLength = dwSize;

  return( *this );
}
/* End of function "CFastString::Truncate"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Lower

       DESCRIPTION:  shift all chars to lower case

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Lower( void )
{
  _tcslwr( m_pchBuffer );
  return( *this );
}
/* End of function "CFastString::Lower"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Upper

       DESCRIPTION:  shift all chars to upper case

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Upper( void )
{
  _tcsupr( m_pchBuffer );
  return( *this );
}
/* End of function "CFastString::Upper"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Insert

       DESCRIPTION:  insert a string of characters at the given index

             INPUT:  iAtIndex - the insert location
                     pchToInsert - pointer to string to insert
            OUTPUT:  

           RETURNS:  self
*/
CFastString& CFastString::Insert( int iAtIndex, const char* pchToInsert )
{
  _ASSERT( iAtIndex >= 0 && pchToInsert );
  if ( iAtIndex > m_iLength )
  {
    return( *this );
  }

  int iParamLength = _tcslen( pchToInsert );
  int iNewLength   = m_iLength + iParamLength;
  
  CFastString oTemp( *this );
  UpdateBufferSize( iNewLength + 1 );
  memcpy( m_pchBuffer, 
          oTemp.Buffer(), 
          CFastString::TLEN( iAtIndex ) );
  memcpy( m_pchBuffer + iAtIndex, 
          pchToInsert, 
          CFastString::TLEN( iParamLength ) );
  memcpy( m_pchBuffer + iAtIndex + iParamLength,  
          oTemp.Buffer() + iAtIndex, 
          CFastString::TLEN( oTemp.Length() - iAtIndex ) );

  m_pchBuffer[ iNewLength ] = '\0';
  m_iLength = iNewLength;
      
  return( *this );
}
/* End of function "CFastString::Insert"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Prepend

       DESCRIPTION:  insert a given string at the beginning of this

             INPUT:  pchToInsert - pointer to string to insert
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::Prepend( const char* pchToInsert )
{
  _ASSERT( pchToInsert );

  int iParamLength = _tcslen( pchToInsert );
  int iNewLength   = m_iLength + iParamLength; 

  CFastString oTemp( *this );
  UpdateBufferSize( iNewLength + 1 );
  memmove( m_pchBuffer + iParamLength, 
           oTemp.Buffer(), 
           CFastString::TLEN( oTemp.Length() ) );
  memcpy( m_pchBuffer, 
          pchToInsert, 
          CFastString::TLEN( iParamLength ) );

  m_pchBuffer[ iNewLength ] = '\0';
  m_iLength = iNewLength;
  
  return( *this );
}
/* End of function "CFastString::Prepend"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Append

       DESCRIPTION:  append a string at the end of this

             INPUT:  pchToInsert - pointer to string to add to the end
            OUTPUT:  none

           RETURNS:  self 
*/
CFastString& CFastString::Append( const char* pchToInsert )
{
  _ASSERT( pchToInsert );
  int iParamLength = _tcslen( pchToInsert );
  int iNewLength   = m_iLength + iParamLength; 

  CFastString oTemp( *this );
  UpdateBufferSize( iNewLength + 1 );
  memcpy( m_pchBuffer, 
          oTemp.Buffer(), 
          CFastString::TLEN( oTemp.Length() ));
  memcpy( m_pchBuffer + iNewLength - iParamLength, 
          pchToInsert, CFastString::TLEN( iParamLength ));

  m_pchBuffer[ iNewLength ] = '\0';
  m_iLength = iNewLength;

  return( *this );
}
/* End of function "CFastString::Append"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Remove

       DESCRIPTION:  slices out a section of this

             INPUT:  iStartAt - start slicing here
                     iLength - size to slice out
            OUTPUT:  

           RETURNS:  self 
*/
CFastString& CFastString::Remove( int iStartAt, int iLength )
{
  _ASSERT( iStartAt >= 0 && iLength >= 0 );

  if ( iStartAt > m_iLength || 0 == iLength )
  {
    return( *this );
  }
  
  int iRemoveLength = ( iStartAt + iLength <= m_iLength ) ? iLength : ( m_iLength - iStartAt );
  int iNewLength    = m_iLength - iRemoveLength;
  
  CFastString oTemp( *this );
  UpdateBufferSize( iNewLength + 1 );

  memcpy( m_pchBuffer + iStartAt, 
        oTemp.Buffer() + iStartAt + iRemoveLength, 
        CFastString::TLEN( iNewLength - iStartAt ));

  m_pchBuffer[ iNewLength ] = '\0';
  m_iLength = iNewLength;

  return( *this );
}
/* End of function "CFastString::Remove"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Replace

       DESCRIPTION:  replace each occurance of pchToFind with pchReplaceWith

             INPUT:  iStartAt - the index to start the replace from
                     pchToFind - replace this text
                     pchReplaceWith - with this text
            OUTPUT:  

           RETURNS:  self
*/
CFastString& CFastString::Replace( int iStartAt, const char* pchToFind, const char* pchReplaceWith )
{
  _ASSERT( iStartAt >= 0 && pchToFind && pchReplaceWith );

  if ( iStartAt >= m_iLength )
  {
    return( *this );
  }
  
  int iToReplaceLength   = _tcslen( pchToFind );
  int iReplaceWithLength = _tcslen( pchReplaceWith );
  int iLengthDifference  = iReplaceWithLength - iToReplaceLength;
  int iReplaceCount      = FindCount( iStartAt, pchToFind );
  int iNewBufferLength   = m_iLength + iLengthDifference * iReplaceCount;
  
  CFastString oTemp( m_pchBuffer );
  UpdateBufferSize( iNewBufferLength + 1 );
  
  TCHAR* pchHead = oTemp.Buffer() + iStartAt;
  TCHAR* pchNext = _tcsstr( pchHead, pchToFind );
  int    iCurrentIndex = 0;  
  
  if ( iStartAt > 0 )
  {
    memcpy( m_pchBuffer + iCurrentIndex, 
            oTemp.Buffer(), 
            CFastString::TLEN( iStartAt ) );

    iCurrentIndex += iStartAt;
  }

  while ( pchNext )
  {
    memcpy( m_pchBuffer + iCurrentIndex, 
            pchHead, 
            CFastString::TLEN( pchNext - pchHead ) );
    iCurrentIndex += pchNext - pchHead;

    memcpy( m_pchBuffer + iCurrentIndex, 
            pchReplaceWith, 
            CFastString::TLEN( iReplaceWithLength ) );
    iCurrentIndex += iReplaceWithLength;
    
    pchHead = pchNext + iToReplaceLength;
    pchNext = _tcsstr( pchHead, pchToFind );
  }
  
  iLengthDifference = oTemp.Length() - ( pchHead - oTemp.Buffer() );
  if (  iLengthDifference > 0 )
  {
    memcpy( m_pchBuffer + iCurrentIndex, 
            pchHead, 
            CFastString::TLEN( iLengthDifference ) );
  }
  
  m_pchBuffer[ iNewBufferLength ] = '\0';
  m_iLength = iNewBufferLength;

  return( *this );
}
/* End of function "CFastString::Replace"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Replace

       DESCRIPTION:  replace each occurance of pchToFind with pchReplaceWith

             INPUT:  pchToFind - replace this text
                     pchReplaceWith - with this text
            OUTPUT:  

           RETURNS:  self
*/
CFastString& CFastString::Replace( const char* pchToFind, const char* pchReplaceWith )
{
  _ASSERT( pchToFind && pchReplaceWith );

  return( Replace( 0, pchToFind, pchReplaceWith ) );
}
/* End of function "CFastString::Replace"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::Format

       DESCRIPTION:  formatted assignment function

             INPUT:  pchFormat - pointer to the format string
                     ... - arguments
            OUTPUT:  

           RETURNS:  self
*/
CFastString& CFastString::Format( const char* pchFormat, ... )
{
  _ASSERT( pchFormat );

  va_list args;
  va_start( args, pchFormat );
  FormatV( pchFormat, args );
  va_end( args );
  return( *this );
}
/* End of function "CFastString::Format"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::FormatV

       DESCRIPTION:  formatted assignment function

             INPUT:  pchFormat - pointer to format string
                     pvArgs - arguments
            OUTPUT:  

           RETURNS:  self
*/
CFastString& CFastString::FormatV( const char* pchFormat, va_list pvArgs )
{
  _ASSERT( pchFormat );

  int  iNewSize      = m_iLength + 1;
  int  iWrittenCount = -1;
  
  iNewSize += _tcslen( pchFormat) + FORMAT_EXTRA_SIZE;
  while ( iWrittenCount < 0 )
  {
    UpdateBufferSize( iNewSize + 1 );
    iWrittenCount = _vsntprintf( m_pchBuffer, iNewSize, pchFormat, pvArgs );
    iNewSize <<= 1;
  }
  m_pchBuffer[ iWrittenCount ] = '\0';
  m_iLength = iWrittenCount;
  
  return( *this );
}
/* End of function "CFastString::FormatV"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::SetInt

       DESCRIPTION:  integer assignment

             INPUT:  iValue - the value to assign to this
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::SetInt( const int iValue )
{
  UpdateBufferSize( INT_SIZE ); 

  _itot( iValue, m_pchBuffer, 10 );
  m_iLength = _tcslen( m_pchBuffer );
  
  return( *this );
}
/* End of function "CFastString::SetInt"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::SetLong

       DESCRIPTION:  long assignment

             INPUT:  lValue - the value to assign to this
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::SetLong( const long lValue )
{
  UpdateBufferSize( LONG_SIZE ); 

  _ltot( lValue, m_pchBuffer, 10 );
  m_iLength = _tcslen( m_pchBuffer );
  
  return( *this );
}
/* End of function "CFastString::SetLong"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::SetULong

       DESCRIPTION:  unsigned long assignment

             INPUT:  ulValue - the value to assign to this
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::SetULong( const unsigned long ulValue )
{
  UpdateBufferSize( ULONG_SIZE ); 

  _ultot( ulValue, m_pchBuffer, 10 );
  m_iLength = _tcslen( m_pchBuffer );
  
  return( *this );
}
/* End of function "CFastString::SetULong"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::SetDouble

       DESCRIPTION:  double assignment

             INPUT:  dblValue - the value to assign to this
            OUTPUT:  none

           RETURNS:  self
*/
CFastString& CFastString::SetDouble( const double dblValue )
{
  return( Format( "%g", dblValue ) );
}
/* End of function "CFastString::SetDouble"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::GetInt

       DESCRIPTION:  return the value of this as an integer

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  value of this
*/
int CFastString::GetInt( void ) const
{
  return( _ttoi( m_pchBuffer ) );
}
CFastString::operator int ( void ) const
{
  return( _ttoi( m_pchBuffer ) );
}
/* End of function "CFastString::GetInt"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::GetLong

       DESCRIPTION:  return the value of this as a long

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  value of this
*/
long CFastString::GetLong( void ) const
{
  return( _ttol( m_pchBuffer ) );
}
CFastString::operator long () const
{
  return( _ttol( m_pchBuffer ) );
}
/* End of function "CFastString::GetLong"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::GetULong

       DESCRIPTION:  return the value of this as an unsigned long

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  value of this
*/
unsigned long CFastString::GetULong( void ) const
{
  return( _tcstoul( m_pchBuffer, NULL, 10 ) );
}
CFastString::operator unsigned long () const
{
  return( _tcstoul( m_pchBuffer, NULL, 10 ) );
}
/* End of function "CFastString::GetULong"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::GetDouble

       DESCRIPTION:  return the value of this as a double

             INPUT:  void  
            OUTPUT:  none

           RETURNS:  value of this
*/
double CFastString::GetDouble( void ) const
{
  return( _tcstod( m_pchBuffer, NULL ) );
}
CFastString::operator double () const
{
  return( _tcstod( m_pchBuffer, NULL ) );
}
/* End of function "CFastString::GetDouble"
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator += 

       DESCRIPTION:  append a character to this

             INPUT:  chToAppend - character to append to this
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::operator += ( const char chToAppend )
{
  char achTwo[ 2 ];
  achTwo[ 0 ] = chToAppend;
  achTwo[ 1 ] = 0;
  Append( achTwo );
}
/* End of function "CFastString::operator +="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator += 

       DESCRIPTION:  append another string on to this

             INPUT:  roOther - character to append to this
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::operator += ( const CFastString& roOther )
{
  Append( roOther.Buffer() );
}
/* End of function "CFastString::operator +="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  CFastString::operator += 

       DESCRIPTION:  append another string on to this

             INPUT:  pchToAppend - string to append to this
            OUTPUT:  none

           RETURNS:  void
*/
void CFastString::operator += ( const char* pchToAppend )
{
  Append( pchToAppend );
}
/* End of function "CFastString::operator +="
/*****************************************************************************/


/*****************************************************************************/
/*

     FUNCTION NAME:  operator << 

       DESCRIPTION:  various concatenation operators

             INPUT:  roTarget - target of the operation
                     varies   - to concat on to the target
                     
            OUTPUT:  

           RETURNS:  self
*/
CFastString& operator << ( CFastString& roTarget, const char* pchToAppend )
{
  _ASSERT( pchToAppend );
  return( roTarget.Append( pchToAppend ) );
}

CFastString& operator << ( CFastString& roTarget, int iValue )
{
  return( roTarget.Append( CFastString( CFastString::INT_SIZE ).SetInt( iValue ) ) );
}

CFastString& operator << ( CFastString& roTarget, long lValue )
{
  return( roTarget.Append( CFastString( CFastString::LONG_SIZE ).SetLong( lValue ) ) );
}

CFastString& operator << ( CFastString& roTarget, unsigned long ulValue )
{
  return( roTarget.Append( CFastString( CFastString::ULONG_SIZE ).SetULong( ulValue ) ) );
}

CFastString& operator << ( CFastString& roTarget, double dblValue )
{
  return( roTarget.Append( CFastString( CFastString::FORMAT_EXTRA_SIZE + 4 ).SetDouble( dblValue ) ) );
}
/* End of function "CFastString::operator <<"
/*****************************************************************************/



/*****************************************************************************/
/* Check-in history */
/*
 *$Log:  $
*/
/*****************************************************************************/



CFastString& CFastString::Fill(const TCHAR chFillChar, int iStart, int iSize)
{
  
  if (iStart + iSize > m_iSize)
  {
    CFastString sTemp(*this);
    UpdateBufferSize(iStart + iSize);
    memcpy( m_pchBuffer, 
          sTemp.Buffer(), 
          CFastString::TLEN( sTemp.Length() ));
  }
  memset( (m_pchBuffer + iStart), chFillChar, iSize );
  m_iLength = iStart + iSize;
  return( *this );
}


CFastString& CFastString::AppendChar(const TCHAR chFillChar, int iStart, int iSize)
{
  
  if (iStart + iSize > m_iSize)
  {
    CFastString sTemp(*this);
    UpdateBufferSize(iStart + iSize);
    memcpy( m_pchBuffer, 
          sTemp.Buffer(), 
          CFastString::TLEN( sTemp.Length() ));
  }
  memset( (m_pchBuffer + iStart), chFillChar, iSize );
  m_iLength += iSize;
  return( *this );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions