📄 vmstring.h
字号:
#ifndef VM_STRING_H_INCLUDED
#define VM_STRING_H_INCLUDED
/*****************************************************************************/
/* HEADER FILE */
/*****************************************************************************/
/*
$Archive: $
$Revision: $
$Date: $
$Author: $
Description: Declaration of a string class that does not require MFC
included
All methods marked with throw() will throw std::bad_alloc
if memory allocation is needed and it fails
every allocation (including the first one) adds an amount
of extra TCHARs to internal buffer so the buffer will not
be resized every time a small operation is performed;
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.
*/
/*****************************************************************************/
#include <windows.h>
#include <tchar.h>
class VMString
{
public:
static int BUFFER_EXTRA_SIZE;
VMString( void ) throw();
VMString( const VMString& roOther ) throw();
VMString( const char* pchValue ) throw();
VMString( int iAllocationSize ) throw();
VMString( const char* pchValue, int iLength ) throw();
~VMString( void );
VMString& operator = ( const VMString& roOther ) throw();
VMString& operator = ( const char* pchValue ) throw();
VMString& operator = ( int iValue ) throw();
VMString& operator = ( long lValue ) throw();
VMString& operator = ( unsigned long ulValue ) throw();
VMString& operator = ( double dblValue ) throw();
TCHAR* GetString( void ) const { return( Buffer() ); };
TCHAR* Buffer( void ) const;
TCHAR* Buffer( void );
TCHAR* GetBuffer( int idx );
TCHAR* GetBufferSetLength( int idx );
void ReleaseBuffer( int idx );
void ReleaseBuffer( void );
int BufferSize() const;
void Realloc( int size ) throw();
void Compact( void ) throw();
void Compact( int iNewSize ) throw();
int GetLength( void ) const { return( Length() ); };
int Length( void ) const;
BOOL IsEmpty( void ) const;
BOOL operator == ( const char* pchCompare ) const;
BOOL operator != ( const char*& pchCompare ) const;
int Compare( const char* pchCompare ) const;
int CompareNoCase( const char* pchCompare ) const;
operator const char* ( void ) const;
operator int ( void ) const;
operator long ( void ) const;
operator unsigned long ( void ) const;
operator double ( void ) const;
TCHAR& operator [] ( int iIndex );
const TCHAR& operator [] ( int iIndex ) const;
VMString Left( int iSize ) const throw();
VMString Right( int iSize ) const throw();
VMString Mid( int iStart ) const throw();
VMString Mid( int iStart, int iSize ) const throw();
void Right( int iCount, VMString& roOutput );
void Mid( int iOffset, int iCount, VMString& roOutput );
int FindCount( const char* pchToFind ) const;
int FindCount( int iStartAt, const char* pchToFind ) const;
int Find( const char* pchToFind ) const;
int Find( const char* pchToFind, int iStartAt ) const;
int Find( const char chToFind, int iStartAt ) const;
int Find( const char chToFind ) const;
int FindNthOf( int iOccurance, const char* pchToFind ) const;
int ReverseFind( const char* pchToFind ) const;
int ReverseFindNthOf( int iOccrance, const char* pchToFind ) const;
VMString& Empty( void );
VMString& Fill( const TCHAR chr );
VMString& Trim( void );
VMString& TrimLeft( void );
VMString& TrimRight( void );
VMString& Lower( void );
VMString& Upper( void );
VMString& Insert( int iAtIndex, const char* pchToInsert ) throw();
VMString& Prepend( const char* pchToPrepend ) throw();
VMString& Append( const char* pchToAppend ) throw();
VMString& Remove( int iAtIndex, int iLength ) throw();
VMString& Truncate( int iPosition ) ;
VMString& Replace( const char* pchToReplace, const char* pchNew ) throw();
VMString& Replace( const char chToReplace, const char chNew ) throw();
VMString& Replace( int iStartAt, const char* pchToReplace, const char* pchNew ) throw();
VMString& Format( const char* pchFormat, ... ) throw();
VMString& FormatV( const char* pchFormat, va_list args ) throw();
int GetInt( void ) const;
long GetLong( void ) const;
unsigned long GetULong( void ) const;
double GetDouble( void ) const;
VMString& SetInt( const int iValue ) throw();
VMString& SetLong( const long lValue ) throw();
VMString& SetULong( const unsigned long ulValue ) throw();
VMString& SetDouble( const double dblValue ) throw();
friend VMString& operator << ( VMString& roOther, const char* pszStr ) throw();
friend VMString& operator << ( VMString& roOther, int iValue ) throw();
friend VMString& operator << ( VMString& roOther, long lValue ) throw();
friend VMString& operator << ( VMString& roOther, unsigned long ulValue ) throw();
friend VMString& operator << ( VMString& roOther, double dblValue ) throw();
void operator +=( const VMString& roToAdd );
void operator +=( const char* pchToAdd );
void operator +=( const char chToAdd );
private:
static int FORMAT_EXTRA_SIZE;
static int INT_SIZE;
static int LONG_SIZE;
static int ULONG_SIZE;
#ifdef VC_60_BUILD
void AllocBuffer( int iSize ) throw();
#else
void AllocBuffer( int iSize ) throw(...); // 2b|!2b==?
#endif
void FreeBuffer( void );
void Initialize( int iAllocSize = 1 ) throw();
int GetPaddedSize( int iSize );
void UpdateBufferSize( const int iSize ) throw();
void CopyToBuffer( const char* source, int iSize );
int TLEN( int iLength );
TCHAR* m_pchBuffer;
int m_iSize;
int m_iLength;
};
#endif
/*****************************************************************************//* Check-in history */
/*
*$Log: $
*/
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -