文字列クラス

  オブジェクトの作成と削除



  
LboxDlg *Dlg;
LboxString *Lstrl;

LRESULT CALLBACK About( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message ) {
		case WM_INITDIALOG:
			Dlg = new LboxDlg( hDlg );
			Lstr = new LboxString( );
			return TRUE;

		case WM_COMMAND:
			if( LOWORD(wParam) == IDCANCEL ) {
				Dlg->End( LOWORD(wParam) );
				delete Lstr;
				delete Dlg;
			}
			break;
	}
	return FALSE;
}
  



  コンストラクタ



  
// *********************************************************
// デフォルトコンストラクタ
// *********************************************************
LboxString::LboxString()
{
	LboxString::szLboxString = (NULL);

	LboxString::nLboxString = 32;

	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);
}

// *********************************************************
// バッファ作成コンストラクタ
// *********************************************************
LboxString::LboxString( DWORD nSize )
{
	LboxString::szLboxString = (NULL);

	LboxString::nLboxString = nSize;

	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

}
LboxString::LboxString( LPTSTR lpString )
{
	LboxString::szLboxString = (NULL);

	LboxString::nLboxString = lstrlen(lpString)+1;

	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	if ( LboxString::szLboxString != NULL ) {
		lstrcpy( LboxString::szLboxString, lpString );
	}
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxString::~LboxString()
{
	if ( LboxString::szLboxString != NULL ) {
		GlobalFree(
			(HGLOBAL)LboxString::szLboxString
		);
	}
}
  



  Atoi

  
// *********************************************************
// 文字列を整数値に変換
// 戻り値 : 変換された数値
// *********************************************************
int LboxString::Atoi( LPCTSTR pszBuffer )
{
	return StrToInt( pszBuffer );
}
int LboxString::Atoi( void )
{
	return StrToInt( LboxString::szLboxString );
}
  



  Ahextoi

  
// *********************************************************
// 16進数文字列を整数値に変換
// 戻り値 : 変換された数値
// *********************************************************
int LboxString::Ahextoi( LPCTSTR pszBuffer )
{
	BOOL bRet;
	int nRet;

	bRet = StrToIntEx( pszBuffer, STIF_SUPPORT_HEX, &nRet );
	if ( !bRet ) {
		return 0;
	}

	return nRet;
}
int LboxString::Ahextoi( void )
{
	BOOL bRet;
	int nRet;

	bRet = StrToIntEx( LboxString::szLboxString, STIF_SUPPORT_HEX, &nRet );
	if ( !bRet ) {
		return 0;
	}

	return nRet;
}
  



  Upper

  
// *********************************************************
// バッファ内の小文字を大文字に変換
// 戻り値 : 処理されたバイト数
// *********************************************************
int LboxString::Upper( LPTSTR pszBuffer, int nSize )
{
	return (int)CharUpperBuff(
		pszBuffer,
		(DWORD)nSize
	);
}
int LboxString::Upper( LPTSTR pszBuffer )
{
	return (int)CharUpperBuff(
		pszBuffer,
		lstrlen(pszBuffer)
	);
}
int LboxString::Upper( int nSize )
{
	return (int)CharUpperBuff( 
		LboxString::szLboxString,
		(DWORD)nSize
	);
}
int LboxString::Upper( void )
{
	return (int)CharUpperBuff(
		LboxString::szLboxString,
		lstrlen(LboxString::szLboxString)
	);
}
  



  Lower

  
// *********************************************************
// バッファ内の大文字を小文字に変換
// 戻り値 : 処理されたバイト数
// *********************************************************
int LboxString::Lower( LPTSTR pszBuffer, int nSize )
{
	return (int)CharLowerBuff(
		pszBuffer,
		(DWORD)nSize
	);
}
int LboxString::Lower( LPTSTR pszBuffer )
{
	return (int)CharLowerBuff(
		pszBuffer,
		lstrlen(pszBuffer)
	);
}
int LboxString::Lower( int nSize )
{
	return (int)CharLowerBuff( 
		LboxString::szLboxString,
		(DWORD)nSize
	);
}
int LboxString::Lower( void )
{
	return (int)CharLowerBuff(
		LboxString::szLboxString,
		lstrlen(LboxString::szLboxString)
	);
}
  



  Trim

  
// *********************************************************
// バッファ内の両側から指定された文字を取り除く
// 戻り値 : 無し
// *********************************************************
void LboxString::Trim( LPTSTR pszBuffer, LPTSTR pszTrimChars )
{
	StrTrim( pszBuffer, pszTrimChars );
}
void LboxString::Trim( LPTSTR pszTrimChars )
{
	StrTrim( LboxString::szLboxString, pszTrimChars );
}
  

通常、以下のように使用します

  
Dlg->EditGetText( IDC_EDIT1, Buff );
Buff->Trim( "  " );
if ( Buff->operator == ("") ) {
	Dlg->MsgOk("データを入力してください   ");
	Dlg->EditFocus( IDC_EDIT1 );
}
  

Buff->Trim( "  " ) の "  " は半角と全角のスペースです



  Search

  
// *********************************************************
// バッファ内から文字列を検索する
// 戻り値 : 文字列の位置( ポインタ )
// 戻り値 : 見付からない時は NULL
// *********************************************************
LPTSTR LboxString::Search( LboxString *LString )
{
	return LboxString::Search( LString->szLboxString );
}
LPTSTR LboxString::Search( LPTSTR pszBuffer, LPTSTR pszTarget )
{
	return StrStr( pszBuffer, pszTarget );
}
LPTSTR LboxString::Search( LPTSTR pszTarget )
{
	return StrStr( LboxString::szLboxString, pszTarget );
}
  



  SearchX

  
// *********************************************************
// 大文字小文字を区別せずにバッファ内から文字列を検索する
// 戻り値 : 文字列の位置( ポインタ )
// 戻り値 : 見付からない時は NULL
// *********************************************************
LPTSTR LboxString::SearchX( LboxString *LString )
{
	return LboxString::SearchX( LString->szLboxString );
}
LPTSTR LboxString::SearchX( LPTSTR pszBuffer, LPTSTR pszTarget )
{
	return StrStrI( pszBuffer, pszTarget );
}
LPTSTR LboxString::SearchX( LPTSTR pszTarget )
{
	return StrStrI( LboxString::szLboxString, pszTarget );
}
  



  Case

  
// *********************************************************
// カンマ区切りの文字列リストに指定した文字列があるかどうか
// 戻り値 : リストにある場合は true, 無ければ false
// *********************************************************
BOOL LboxString::Case( LPTSTR pszBuffer, LPCTSTR pszList )
{
	return LboxStringCase( pszBuffer, pszList );
}
BOOL LboxString::Case( LPCTSTR pszList )
{
	return LboxStringCase( LboxString::szLboxString, pszList );
}
  

LboxStringCase



  CaseX

  
// *********************************************************
// 大文字小文字区別無し Case
// 戻り値 : リストにある場合は true, 無ければ false
// *********************************************************
BOOL LboxString::CaseX( LPTSTR pszBuffer, LPCTSTR pszList )
{
	return LboxStringCaseX( pszBuffer, pszList );
}
BOOL LboxString::CaseX( LPCTSTR pszList )
{
	return LboxStringCaseX( LboxString::szLboxString, pszList );
}
  

LboxStringCaseX



  LPTSTR 用 operator +=

  
// *********************************************************
// 追加オペレータ ( LPTSTR 用 )
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::operator += ( LPTSTR szBuffer )
{
	LboxString::nLboxString =
		lstrlen(LboxString::szLboxString) +
		lstrlen(szBuffer) + 1;
	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	if ( LboxString::szLboxString != NULL ) {
		lstrcat(
			LboxString::szLboxString,
			szBuffer
		);
	}

	return LboxString::szLboxString;
}
  

LboxReAlloc



  LboxString 用 operator +=

  
// *********************************************************
// 追加オペレータ ( LboxString 用 )
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::operator += ( LboxString *obj )
{
	if ( obj->szLboxString == NULL ) {
		return LboxString::szLboxString;
	}

	LboxString::nLboxString =
		lstrlen(LboxString::szLboxString) +
		lstrlen(obj->szLboxString) + 1;
	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	if ( LboxString::szLboxString != NULL ) {
		lstrcat(
			LboxString::szLboxString,
			obj->szLboxString
		);
	}

	return LboxString::szLboxString;
}
  

LboxReAlloc



  LPTSTR 用 operator =

  
// *********************************************************
// 代入オペレータ ( LPTSTR 用 )
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::operator = ( LPTSTR szBuffer )
{
	LboxString::nLboxString = lstrlen(szBuffer) + 1;
	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	if ( LboxString::szLboxString != NULL ) {
		lstrcpy(
			LboxString::szLboxString,
			szBuffer
		);
	}

	return LboxString::szLboxString;
}
  

LboxReAlloc



  LboxString 用 operator =

  
// *********************************************************
// 代入オペレータ ( LboxString 用 )
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::operator = ( LboxString *obj )
{
	if ( obj->szLboxString == NULL ) {
		return LboxString::szLboxString;
	}

	LboxString::nLboxString = lstrlen(obj->szLboxString) + 1;
	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	if ( LboxString::szLboxString != NULL ) {
		lstrcpy(
			LboxString::szLboxString,
			obj->szLboxString
		);
	}

	return LboxString::szLboxString;
  

LboxReAlloc



  Enclose

  
// *********************************************************
// 文字列を指定した文字で囲む
// 既にその文字で囲まれている場合はなにもしない
// 戻り値 : 無し
// *********************************************************
void LboxStringEnclose( LPTSTR pszBuffer, int c )
{
	if ( pszBuffer[0] == (char)c &&
		pszBuffer[lstrlen(pszBuffer)-1] == (char)c ) {
		return;
	}
	pszBuffer[lstrlen(pszBuffer)+1] = 0x00;
	pszBuffer[lstrlen(pszBuffer)+2] = 0x00;
	MoveMemory( pszBuffer + 1, pszBuffer, lstrlen( pszBuffer ) );
	pszBuffer[0] = (char)c;
	pszBuffer[lstrlen(pszBuffer)] = (char)c;
}
void LboxString::Enclose( LPTSTR pszBuffer, int c )
{
	LboxStringEnclose( pszBuffer, c );
}
void LboxString::Enclose( int c )
{
	LboxStringEnclose( LboxString::szLboxString, c );
}
void LboxStringEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
	if ( pszBuffer[0] == (char)c1 &&
		pszBuffer[lstrlen(pszBuffer)-1] == (char)c2 ) {
		return;
	}
	pszBuffer[lstrlen(pszBuffer)+1] = 0x00;
	pszBuffer[lstrlen(pszBuffer)+2] = 0x00;
	MoveMemory( pszBuffer + 1, pszBuffer, lstrlen( pszBuffer ) );
	pszBuffer[0] = (char)c1;
	pszBuffer[lstrlen(pszBuffer)] = (char)c2;
}
void LboxString::Enclose( LPTSTR pszBuffer, int c1, int c2 )
{
	LboxStringEnclose( pszBuffer, c1, c2 );
}
void LboxString::Enclose( int c1, int c2 )
{
	LboxStringEnclose( LboxString::szLboxString, c1, c2 );
}
  



  RemoveEnclose

  
// *********************************************************
// 文字列が指定した文字で囲まれていたらその文字を取り去る
// 戻り値 : 無し
// *********************************************************
void LboxStringRemoveEnclose( LPTSTR pszBuffer, int c )
{
	if ( pszBuffer[0] == (char)c &&
		pszBuffer[lstrlen(pszBuffer)-1] == (char)c ) {
		MoveMemory( pszBuffer, pszBuffer + 1, lstrlen( pszBuffer ) );
		pszBuffer[lstrlen(pszBuffer)-1] = 0x00;
	}
}
void LboxString::RemoveEnclose( LPTSTR pszBuffer, int c )
{
	LboxStringRemoveEnclose( pszBuffer, c );
}
void LboxString::RemoveEnclose( int c )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, c );
}
void LboxStringRemoveEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
	if ( pszBuffer[0] == (char)c1 &&
		pszBuffer[lstrlen(pszBuffer)-1] == (char)c2 ) {
		MoveMemory( pszBuffer, pszBuffer + 1, lstrlen( pszBuffer ) );
		pszBuffer[lstrlen(pszBuffer)-1] = 0x00;
	}
}
void LboxString::RemoveEnclose( LPTSTR pszBuffer, int c1, int c2 )
{
	LboxStringRemoveEnclose( pszBuffer, c1, c2 );
}
void LboxString::RemoveEnclose( int c1, int c2 )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, c1, c2 );
}
  

LboxStringRemoveEnclose



  StripPath

  
// *********************************************************
// パスを取り去ってファイル名を得る
// " で囲まれていたら事前に取り去る
// 戻り値 : 無し
// *********************************************************
void LboxString::StripPath( LPTSTR pszBuffer )
{
	LboxStringRemoveEnclose( pszBuffer, '"' );
	PathStripPath( pszBuffer );
}
void LboxString::StripPath( void )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, '"' );
	PathStripPath( LboxString::szLboxString );
}
  



  RemoveFileSpec

  
// *********************************************************
// ファイル名を取り去ってパス(ディレクトリ)を得る
// " で囲まれていたら事前に取り去る
// 文字列最後尾の \ は取り去られます
// 戻り値 : 無し
// *********************************************************
void LboxString::RemoveFileSpec( LPTSTR pszBuffer )
{
	LboxStringRemoveEnclose( pszBuffer, '"' );
	PathRemoveFileSpec( pszBuffer );
}
void LboxString::RemoveFileSpec( void )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, '"' );
	PathRemoveFileSpec( LboxString::szLboxString );
}
  



  RemoveBackslash

  
// *********************************************************
// 文字列最後尾の \ 削除
// " で囲まれていたら事前に取り去る
// 戻り値 : 無し
// *********************************************************
void LboxString::RemoveBackslash( LPTSTR pszBuffer )
{
	LboxStringRemoveEnclose( pszBuffer, '"' );
	PathRemoveBackslash( pszBuffer );
}
void LboxString::RemoveBackslash( void )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, '"' );
	PathRemoveBackslash( LboxString::szLboxString );
}
  



  AddBackslash

  
// *********************************************************
// 文字列最後尾に \ 追加
// " で囲まれていたら事前に取り去る
// 戻り値 : 無し
// *********************************************************
void LboxString::AddBackslash( LPTSTR pszBuffer )
{
	LboxStringRemoveEnclose( pszBuffer, '"' );
	PathAddBackslash( pszBuffer );
}
void LboxString::AddBackslash( void )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, '"' );
	PathAddBackslash( LboxString::szLboxString );
}
  



  RemoveExtension

  
// *********************************************************
// ファイル名文字列の拡張子を取り去る
// " で囲まれていたら事前に取り去る
// 戻り値 : 無し
// *********************************************************
void LboxString::RemoveExtension( LPTSTR pszBuffer )
{
	LboxStringRemoveEnclose( pszBuffer, '"' );
	PathRemoveExtension( pszBuffer );
}
void LboxString::RemoveExtension( void )
{
	LboxStringRemoveEnclose( LboxString::szLboxString, '"' );
	PathRemoveExtension( LboxString::szLboxString );
}
  



  BuildPath

  
// *********************************************************
// pszBuffer に lpDir と lpFile から作成したパスをセット
// 戻り値 : 無し
// *********************************************************
void LboxString::BuildPath( LPTSTR pszBuffer, LPTSTR lpDir, LPTSTR lpFile )
{
	PathCombine( pszBuffer, lpDir, lpFile );
}
// *********************************************************
// szLboxString に lpDir と lpFile から作成したパスをセット
// 戻り値 : 無し
// *********************************************************
void LboxString::BuildPath( LPTSTR lpDir, LPTSTR lpFile )
{
	LboxString::operator = (lpDir);
	LboxString::operator += ( "\\" );
	LboxString::operator += ( lpFile );
	PathCombine( LboxString::szLboxString, lpDir, lpFile );
}
  



  Resize

  
// *********************************************************
// バッファのリサイズ
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::Resize( DWORD nSize )
{
	LboxString::nLboxString = nSize;

	return LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);
}
  



  FindExtension

  
// *********************************************************
// ファイル名文字列の拡張子の位置を取得
// 戻り値 : ポインタ
// *********************************************************
LPTSTR LboxString::FindExtension( LPTSTR pszBuffer )
{
	return PathFindExtension( pszBuffer );
}
LPTSTR LboxString::FindExtension( void )
{
	return PathFindExtension( LboxString::szLboxString );
}
  



  Printf

  
// *********************************************************
// フォーマットした文字列を設定
// 戻り値 : 無し
// *********************************************************
void LboxString::Printf( LPTSTR FormatString, ...)
{
	LboxString::nLboxString = 1024;
	LboxReAlloc(
		&(LboxString::szLboxString),
		LboxString::nLboxString
	);

	va_list marker;

	va_start(marker, FormatString);
	wvsprintf(LboxString::szLboxString, FormatString, marker);
	va_end(marker);              
}
  



  Printfcat

  
// *********************************************************
// フォーマットした文字列を追加
// 戻り値 : 無し
// *********************************************************
void LboxString::Printfcat( LPTSTR FormatString, ...)
{
	char *szBuffer = new char[1024];

	va_list marker;
	DWORD nSize;

	va_start(marker, FormatString);
	wvsprintf(szBuffer, FormatString, marker);
	va_end(marker);

	nSize = 
		lstrlen( LboxString::szLboxString ) +
		lstrlen( szBuffer ) + 2;

	delete [] szBuffer;

	if ( nSize > LboxString::nLboxString ) {
		LboxString::nLboxString = nSize;
		LboxReAlloc(
			&(LboxString::szLboxString),
			LboxString::nLboxString
		);
	}

	va_start(marker, FormatString);
	wvsprintf(
		(LboxString::szLboxString)+
		lstrlen(LboxString::szLboxString),
		FormatString,
		marker
	);
	va_end(marker);              

}
  



  LPTSTR 用 operator ==

  
// *********************************************************
// 比較オペレータ ( LPTSTR 用 )
// 戻り値 : 完全一致 1, 不一致 0, 大文字小文字無視一致 -1;
// *********************************************************
int LboxString::operator == ( LPTSTR szBuffer )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		szBuffer) == 0 ) {
		return 1;
	}

	if( lstrcmpi( 
		LboxString::szLboxString,
		szBuffer) == 0 ) {
		return -1;
	}

	return 0;
}
  



  LboxString 用 operator ==

  
// *********************************************************
// 比較オペレータ ( LboxString 用 )
// 戻り値 : 完全一致 1, 不一致 0, 大文字小文字無視一致 -1;
// *********************************************************
int LboxString::operator == ( LboxString *obj )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		obj->szLboxString) == 0 ) {
		return 1;
	}

	if( lstrcmpi( 
		LboxString::szLboxString,
		obj->szLboxString) == 0 ) {
		return -1;
	}

	return 0;
}
  



  LPTSTR 用 operator <

  
// *********************************************************
// 比較オペレータ ( LPTSTR 用 )
// 戻り値 : 小さい場合 true
// *********************************************************
BOOL LboxString::operator < ( LPTSTR szBuffer )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		szBuffer) < 0 ) {
		return true;
	}

	return false;
}
  



  LboxString 用 operator <

  
// *********************************************************
// 比較オペレータ ( LboxString 用 )
// 戻り値 : 小さい場合 true
// *********************************************************
BOOL LboxString::operator < ( LboxString *obj )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		obj->szLboxString) < 0 ) {
		return true;
	}

	return false;
  



  LPTSTR 用 operator >

  
// *********************************************************
// 比較オペレータ ( LPTSTR 用 )
// 戻り値 : 大きい場合 true
// *********************************************************
BOOL LboxString::operator > ( LPTSTR szBuffer )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		szBuffer) > 0 ) {
		return true;
	}

	return false;
}
  



  LboxString 用 operator >

  
// *********************************************************
// 比較オペレータ ( LboxString 用 )
// 戻り値 : 大きい場合 true
// *********************************************************
BOOL LboxString::operator > ( LboxString *obj )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		obj->szLboxString) > 0 ) {
		return true;
	}

	return false;
}
  



  Insert

  
// *********************************************************
// 文字列の挿入
// 戻り値 : 文字列へのポインタ
// *********************************************************
LPTSTR LboxString::Insert( LboxString *LString )
{
	return LboxString::Insert( LString->szLboxString );
}
LPTSTR LboxString::Insert( LPTSTR lpBuffer )
{
	DWORD nSize;

	nSize = 
		lstrlen(LboxString::szLboxString) +
		lstrlen( lpBuffer ) + 1;

	if ( nSize > LboxString::nLboxString ) {
		LboxString::nLboxString = nSize;
		LboxReAlloc(
			&(LboxString::szLboxString),
			LboxString::nLboxString
		);
	}

	MoveMemory( 
		(LboxString::szLboxString) + lstrlen( lpBuffer ),
		LboxString::szLboxString,
		lstrlen(LboxString::szLboxString)+1
	);
	MoveMemory( 
		(LboxString::szLboxString),
		lpBuffer,
		lstrlen(lpBuffer)
	);

	return (LboxString::szLboxString);
}
LPTSTR LboxString::Insert( LboxString *LString, int nPos )
{
	return LboxString::Insert( LString->szLboxString, nPos );
}
LPTSTR LboxString::Insert( LPTSTR lpBuffer, int nPos )
{
	DWORD nSize;

	nSize = 
		lstrlen(LboxString::szLboxString) +
		lstrlen( lpBuffer ) + 1;

	if ( nSize > LboxString::nLboxString ) {
		LboxString::nLboxString = nSize;
		LboxReAlloc(
			&(LboxString::szLboxString),
			LboxString::nLboxString
		);
	}

	MoveMemory( 
		(LboxString::szLboxString) + nPos + lstrlen( lpBuffer ),
		LboxString::szLboxString + nPos,
		lstrlen(LboxString::szLboxString)+1-nPos
	);
	MoveMemory( 
		(LboxString::szLboxString)+nPos,
		lpBuffer,
		lstrlen(lpBuffer)
	);

	return (LboxString::szLboxString);
}
  



  Display

  
// *********************************************************
// テスト表示
// 戻り値 : 無し
// *********************************************************
void LboxString::Display( void )
{
	MessageBox(
		NULL,
		LboxString::szLboxString,
		"LboxString::Display",
		MB_OK
	);
}
  



  Replace

  
// *********************************************************
// 指定文字列置き換え
// 戻り値 : 無し
// *********************************************************
LPTSTR LboxString::Replace( LPTSTR lpTarget, LPTSTR lpReplace )
{
	DWORD nTarget,nReplace,nUpsize;

	nTarget = lstrlen( lpTarget );
	nReplace = lstrlen( lpReplace );
	nUpsize = 0;

	LboxString *LString;
	if ( nTarget < nReplace ) {
		LString = new LboxString( LboxString::nLboxString + MAX_PATH );
	}
	else {
		LString = new LboxString( LboxString::nLboxString );
	}

	unsigned char *base;
	base = (unsigned char *)LboxString::szLboxString;
	unsigned char *ptr;
	ptr = _mbsstr(
		base,
		(const unsigned char *)lpTarget
	);
	if ( ptr != NULL ) {
		DWORD dwNew;
		dwNew = 0;
		while( ptr != NULL ) {
			if ( nTarget < nReplace ) {
				nUpsize += nReplace - nTarget;
				if ( nUpsize > MAX_PATH ) {
					LString->Resize(
						LString->nLboxString + MAX_PATH
					);
					nUpsize = 0;
					nUpsize += nReplace - nTarget;
				}
			}
			CopyMemory(
				LString->szLboxString+dwNew,
				(LPTSTR)base,
				(DWORD)ptr - (DWORD)base
			);
			dwNew = dwNew + (DWORD)ptr - (DWORD)base;
			CopyMemory(
				LString->szLboxString+dwNew,
				lpReplace,
				nReplace
			);
			dwNew = dwNew + nReplace;
			LString->szLboxString[dwNew] = 0x00;
			base = ptr + nTarget;
			ptr = _mbsstr(
				base,
				(const unsigned char *)lpTarget
			);
		}
		lstrcat( LString->szLboxString, (LPTSTR)base );
		LboxString::operator = ( LString );
	}

	delete LString;
	return LboxString::szLboxString;
}
  



  SetChar

  
// *********************************************************
// 指定位置キャラクタセット
// 戻り値 : 無し
// *********************************************************
LPTSTR LboxString::SetChar( DWORD nPos, DWORD nChar )
{
	LboxString::szLboxString[nPos] = (unsigned char)nChar;
	return LboxString::szLboxString;
}
  



  LboxString 用 operator !=

  
// *********************************************************
// 比較オペレータ ( LPTSTR 用 )
// 戻り値 : 完全一致 1, 不一致 0, 大文字小文字無視一致 -1;
// *********************************************************
BOOL LboxString::operator != ( LPTSTR szBuffer )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		szBuffer) != 0 ) {
		return true;
	}

	return false;
}

// *********************************************************
// 比較オペレータ ( LboxString 用 )
// 戻り値 : 完全一致 1, 不一致 0, 大文字小文字無視一致 -1;
// *********************************************************
BOOL LboxString::operator != ( LboxString *obj )
{
	if( lstrcmp( 
		LboxString::szLboxString,
		obj->szLboxString) != 0 ) {
		return true;
	}

	return false;
}
  



  RemoveTopchar

  
// *********************************************************
// 文字列の先頭文字を削除する
// 戻り値 : 無し
// *********************************************************
void LboxString::RemoveTopchar( void )
{
	LboxString::RemoveTopchar( LboxString::szLboxString );
}
void LboxString::RemoveTopchar( LPTSTR pszBuffer )
{
	MoveMemory( pszBuffer, pszBuffer + 1, lstrlen( pszBuffer ) );
}
  



  RemoveLastchar

  
// *********************************************************
// 文字列の最終文字を削除する
// 戻り値 : 無し
// *********************************************************
void LboxString::RemoveLastchar( void )
{
	LboxString::RemoveLastchar( LboxString::szLboxString );
}
void LboxString::RemoveLastchar( LPTSTR pszBuffer )
{
	pszBuffer[lstrlen(pszBuffer)-1] = 0x00;
}
  



  Fzero

  
// *********************************************************
// 先行ゼロ文字列の作成
// 戻り値 : 無し
// *********************************************************
void LboxString::Fzero( int nData, int nLen )
{
	char szFormat[20];
	szFormat[0] = '%';
	wsprintf( szFormat+1, "0%dd", nLen );
	LboxString::Printf( szFormat, nData );
}
void LboxString::Fzero( LboxString *LString, int nLen )
{
	LboxString::Fzero( LString->szLboxString, nLen );
}
void LboxString::Fzero( LPTSTR lpData, int nLen )
{
	char szFormat[20];
	szFormat[0] = '%';
	wsprintf( szFormat+1, "0%ds", nLen );
	LboxString::Printf( szFormat, lpData );
}
  



  Repeat

  
// *********************************************************
// 繰り返し文字列の作成
// 戻り値 : 無し
// *********************************************************
void LboxString::Repeat( LboxString *LString, int nCount )
{
	LboxString::Repeat( LString->szLboxString, nCount );
}
void LboxString::Repeat( LPTSTR lpData, int nCount )
{
	int i,nLen;
	nLen = lstrlen( lpData ) * nCount;
	if ( LboxString::nLboxString < nLen ) {
		LboxString::Resize( nLen );
	}

	LboxString::SetChar( 0, 0 );
	for( i = 0; i < nCount; i++ ) {
		LboxString::operator += (lpData);
	}
}
  



  Left,Right,Substr

  
// *********************************************************
// 部分文字列取得
// 戻り値 : 無し
// *********************************************************
void LboxString::Left( int nLen, LboxString *LString )
{
	if ( nLen >= lstrlen(LboxString::szLboxString) ) {
		return;
	}
	LString->operator = (LboxString::szLboxString);
	LString->SetChar( nLen, 0x00 );
}
void LboxString::Right( int nLen, LboxString *LString )
{
	if ( nLen >= lstrlen(LboxString::szLboxString) ) {
		return;
	}
	LString->operator = (
		LboxString::szLboxString
		+ lstrlen(LboxString::szLboxString)
		- nLen
	);
}
void LboxString::Substr( int nPos, int nLen, LboxString *LString )
{
	LString->operator = (
		LboxString::szLboxString
		+ nPos
	);
	LString->SetChar( nLen, 0x00 );
}
  



  NumberFormat

  
// *********************************************************
// カンマ編集
// 戻り値 : 無し
// *********************************************************
void LboxString::NumberFormat( LboxString *LString )
{
	int nLen;
	nLen = lstrlen(LboxString::szLboxString);
	nLen = nLen + nLen/3 + 1;
	if ( LString->nLboxString < (DWORD)nLen ) {
		LString->Resize( nLen );
	}
	LString->SetChar( nLen, 0x00 );

	int i,nPos,nCount;
	nPos = nLen-1;
	nLen = lstrlen(LboxString::szLboxString);
	nCount = 0;
	for( i = nLen-1; i >= 0; i-- ) {
		nCount++;
		if ( nCount % 3  == 1 && nCount != 1 ) {
			*(LString->szLboxString + nPos) = ',';
			nPos--;
			*(LString->szLboxString + nPos) =
				*(LboxString::szLboxString + i);
		}
		else {
			*(LString->szLboxString + nPos) =
				*(LboxString::szLboxString + i);
		}
		nPos--;
	}
	if ( nPos != -1 ) {
		MoveMemory(
			LString->szLboxString,
			LString->szLboxString+nPos+1,
			nLen + nLen/3 + 1
		);
	}
}
  



  Length

  
// *********************************************************
// 文字列の長さ
// 戻り値 : 無し
// *********************************************************
int LboxString::Length( void )
{
	return lstrlen( LboxString::szLboxString );
}
  



  IsDate

  
// *********************************************************
// 日付として正しいかどうか
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxString::IsDate( void )
{
	WORD wDate;
	WORD wTime;

	return LboxString::ToDosDate( &wDate, &wTime );
}
  



  ToDosDate

  
// *********************************************************
// 文字列日付を Dos 形式の日付に変換する
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxString::ToDosDate( LPWORD lpFatDate, LPWORD lpFatTime )
{
	LboxToken Ltoken;
	LboxString LString;
	int nWork;

	Ltoken.CreateToken( this->szLboxString, "/" );
	if ( Ltoken.nCount < 3 ) {
		return false;
	}

	LString.operator = (Ltoken.Token[0]);
	nWork = LString.Atoi();
	if ( ( nWork - 1980 ) < 0 ) {
		nWork = nWork + 2000;
	}
	nWork = nWork - 1980;

	WORD wYear;
	WORD wMonth;
	WORD wDay;

	wYear = (WORD)nWork;
	wYear = wYear << 9;

	LString.operator = (Ltoken.Token[1]);
	nWork = LString.Atoi();

	wMonth = (WORD)nWork;
	wMonth = wMonth << 5;

	LString.operator = (Ltoken.Token[2]);
	nWork = LString.Atoi();

	wDay = (WORD)nWork;

	WORD wDate;
	WORD wTime;

	wDate = wYear | wMonth | wDay;
	wTime = 0;

	FILETIME ft;

	BOOL bRet;

	bRet = DosDateTimeToFileTime(
		wDate,
		wTime,
		&ft
	);

	if ( !bRet ) {
		return false;
	}

	(*lpFatDate) = wDate;
	(*lpFatTime) = wTime;

	return true;
}
  



  ToFileTime

  
// *********************************************************
// 文字列日付を FILETIME 形式に変換する
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxString::ToFileTime( LPFILETIME lpFileTime )
{
	WORD wDate;
	WORD wTime;
	BOOL bRet;

	bRet = this->ToDosDate( &wDate, &wTime );
	if ( !bRet ) {
		return false;
	}

	bRet = DosDateTimeToFileTime(
		wDate,
		wTime,
		lpFileTime
	);

	if ( !bRet ) {
		return false;
	}

	return true;

}
  



  ToSystemTime

  
// *********************************************************
// 文字列日付を SYSTEMTME 形式に変換する
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxString::ToSystemTime( LPSYSTEMTIME lpSystemTime )
{
	BOOL bRet;
	FILETIME ft;

	bRet = this->ToFileTime( &ft );
	if ( !bRet ) {
		return false;
	}

	bRet = FileTimeToSystemTime(
		&ft,
		lpSystemTime
	);

	if ( !bRet ) {
		return false;
	}

	return true;

}
  



  DateDiff

  
// *********************************************************
// 文字列日付の経過日数
// 戻り値 : 経過日数( 失敗時は -1 )
// *********************************************************
int LboxString::DateDiff( LboxString *LDate )
{
	return LboxString::DateDiff( LDate->szLboxString );
}
int LboxString::DateDiff( LPTSTR lpDate )
{
	LboxString LString;
	LboxInfo Info;

	LString.operator = (lpDate);

	BOOL bRet;
	SYSTEMTIME st1;
	SYSTEMTIME st2;

	bRet = this->ToSystemTime( &st1 );
	if ( !bRet ) {
		return -1;
	}
	bRet = LString.ToSystemTime( &st2 );
	if ( !bRet ) {
		return -1;
	}

	return Info.DateDiff( &st1, &st2 );

}
  



  Dayofweek

  
// *********************************************************
// 文字列日付から 曜日文字列に変換する
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxString::Dayofweek( void )
{
	BOOL bRet;
	SYSTEMTIME st;

	bRet = this->ToSystemTime( &st );
	if ( !bRet ) {
		return false;
	}

	switch( st.wDayOfWeek ) {
		case 0:
			this->operator = ("日");
			break;
		case 1:
			this->operator = ("月");
			break;
		case 2:
			this->operator = ("火");
			break;
		case 3:
			this->operator = ("水");
			break;
		case 4:
			this->operator = ("木");
			break;
		case 5:
			this->operator = ("金");
			break;
		case 6:
			this->operator = ("土");
			break;
	}

	return true;

}
  



  IsGroup

  
// *********************************************************
// 文字列中に存在している文字のみで構成されているかどうか
// 戻り値 : true 構成されている, false されていない
// *********************************************************
BOOL LboxString::IsGroup( LboxString *LGroup )
{
	return LboxString::IsGroup( LGroup->szLboxString );
}
BOOL LboxString::IsGroup( LPTSTR lpGroup )
{
	int i,nLen;
	char buff[10];

	nLen = lstrlen( this->szLboxString );
	for( i = 0; i < nLen; i++ ) {
		if ( IsDBCSLeadByte( (BYTE)(*((this->szLboxString)+i)) ) ) {
			buff[0] = (*((this->szLboxString)+i));
			buff[1] = (*((this->szLboxString)+i+1));
			buff[2] = 0x00;
			i++;
		}
		else {
			buff[0] = (*((this->szLboxString)+i));
			buff[1] = 0x00;
		}
		if ( StrStr( lpGroup, buff ) == NULL ) {
			return false;
		}
	}

	return true;

}
  



  IsNum

  
// *********************************************************
// "0123456789" で構成されているか
// 戻り値 : true 構成されている, false されていない
// *********************************************************
BOOL LboxString::IsNum( void )
{
	return LboxString::IsGroup( "0123456789" );
}
  



  IsDBCS

  
// *********************************************************
// 漢字のみで構成されているか
// 戻り値 : true 構成されている, false されていない
// *********************************************************
BOOL LboxString::IsDBCS( void )
{
	int i,nLen;

	nLen = lstrlen( this->szLboxString );
	for( i = 0; i < nLen; i++ ) {
		if ( IsDBCSLeadByte( (BYTE)(*((this->szLboxString)+i)) ) ) {
			i++;
		}
		else {
			return false;
		}
	}

	return true;
}
  



  IsNotDBCS

  
// *********************************************************
// 漢字以外だけで構成されているか
// 戻り値 : true 構成されている, false されていない
// *********************************************************
BOOL LboxString::IsNotDBCS( void )
{
	int i,nLen;

	nLen = lstrlen( this->szLboxString );
	for( i = 0; i < nLen; i++ ) {
		if ( IsDBCSLeadByte( (BYTE)(*((this->szLboxString)+i)) ) ) {
			return false;
		}
	}

	return true;
}
  



  IsNumeric

  
// *********************************************************
// 数値として正しいかどうか
// 戻り値 : true 正しい, false 正しく無い
// *********************************************************
BOOL LboxString::IsNumeric( void )
{

	if ( !(this->IsNotDBCS()) ) {
		return false;
	}
	if ( !(this->IsGroup( "01234567890.-" )) ) {
		return false;
	}

	int i,nLen;
	int nPeriod,nMinus;

	nPeriod = nMinus = 0;
	nLen = lstrlen( this->szLboxString );
	for( i = 0; i < nLen; i++ ) {
		if ( (*((this->szLboxString)+i)) == '.' ) {
			nPeriod++;
		}
		if ( (*((this->szLboxString)+i)) == '-' ) {
			nMinus++;
		}
	}
	if ( nPeriod > 1 ) {
		return false;
	}
	if ( nMinus > 1 ) {
		return false;
	}
	if ( nMinus == 1 ) {
		if ( (*(this->szLboxString)) != '-' ) {
			return false;
		}
	}

	return true;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ