/*!
@file	Classes/ActiveBasic/CType/CType.ab
@brief	ASCII文字分類関数群
@author	Egtra
@date	2007/11/25
*/

Namespace ActiveBasic
Namespace CType

Namespace Detail

Function Widen(c As CHAR) As WCHAR
	Return c As Byte As WCHAR
End Function

Function Narrow(c As WCHAR) As CHAR
	Return c As Byte As CHAR
End Function

End Namespace 'Detail

/*!
@brief	ASCIIのアルファベットまたは数字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsAlnum(c As WCHAR) As Boolean
	Return IsUpper(c) Or IsLower(c) Or IsDigit(c)
End Function

/*!
@brief	ASCIIのアルファベットかどうか
@author	Egtra
@date	2007/11/25
*/
Function IsAlpha(c As WCHAR) As Boolean
	Return IsUpper(c) Or IsLower(c)
End Function

/*!
@brief	ASCIIの行内に置ける空白文字かどうか
@author	Egtra
@date	2007/11/25
ようするにASCIIでは空白とタブ
*/
Function IsBlank(c As WCHAR) As Boolean
	Return c = &h20 Or c = &h09 'space or tab
End Function

/*!
@brief	ASCIIの制御文字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsCntrl(c As WCHAR) As Boolean
	Return c < &h20 Or c = &h7f
End Function

/*!
@brief	ASCIIの数字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsDigit(c As WCHAR) As Boolean
	Return (c As DWord Xor &h30) < 10
End Function

/*!
@brief	ASCIIの図形文字かどうか
@author	Egtra
@date	2007/11/25
図形文字とは、空白以外の表示文字
*/
Function IsGraph(c As WCHAR) As Boolean
	Return (c As DWord - &h21) < (&h7e - &h21)
End Function

/*!
@brief	ASCIIのアルファベッの小文字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsLower(c As WCHAR) As Boolean
	Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
End Function

/*!
@brief	ASCIIの表示文字かどうか
@author	Egtra
@date	2007/11/25
制御文字でないもの、空白も表示文字に含む
*/
Function IsPrint(c As WCHAR) As Boolean
	Return (c As DWord - &h20) < (&h7e - &h20)
End Function

/*!
@brief	ASCIIの区切り数字かどうか
@author	Egtra
@date	2007/11/25
アルファベットでも数字でもない図形文字のこと
*/
Function IsPunct(c As WCHAR) As Boolean
	Return c < &h7f And IsGraph(c) And (Not IsAlnum(c))
End Function

/*!
@brief	ASCIIの空白文字かどうか
@author	Egtra
@date	2008/01/22
*/
Function IsSpace(c As WCHAR) As Boolean
	Return c As DWord - 9 < 4 Or c = &h20 ' &h41 = Asc("A")
End Function

/*!
@brief	ASCIIのアルファベットの大文字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsUpper(c As WCHAR) As Boolean
	Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
End Function

/*!
@brief	ASCIIの十六進法で記す際に用いられる文字かどうか
@author	Egtra
@date	2007/11/25
*/
Function IsXDigit(c As WCHAR) As Boolean
	Return IsDigit(c) Or ((c As DWord And (Not &h20)) - &h41 < 5)
End Function

/*!
@brief	ASCIIのアルファベット大文字を小文字にする
@author	Egtra
@date	2007/11/25
*/
Function ToLower(c As WCHAR) As WCHAR
	If IsUpper(c) Then
		Return c Or &h20
	Else
		Return c
	End If
End Function

/*!
@brief	ASCIIのアルファベット小文字を大文字にする
@author	Egtra
@date	2007/11/25
*/
Function ToUpper(c As WCHAR) As WCHAR
	If IsLower(c) Then
		Return c And (Not &h20)
	Else
		Return c
	End If
End Function

/*!
@overload
*/
Function IsAlnum(c As CHAR) As Boolean
	Return IsAlnum(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsAlpha(c As CHAR) As Boolean
	Return IsAlpha(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsBlank(c As CHAR) As Boolean
	Return IsBlank(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsCntrl(c As CHAR) As Boolean
	Return IsCntrl(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsDigit(c As CHAR) As Boolean
	Return IsDigit(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsGraph(c As CHAR) As Boolean
	Return IsGraph(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsLower(c As CHAR) As Boolean
	Return IsLower(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsPrint(c As CHAR) As Boolean
	Return IsPrint(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsPunct(c As CHAR) As Boolean
	Return IsPunct(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsSpace(c As CHAR) As Boolean
	Return IsSpace(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsUpper(c As CHAR) As Boolean
	Return IsUpper(Detail.Widen(c))
End Function

/*!
@overload
*/
Function IsXDigit(c As CHAR) As Boolean
	Return IsXDigit(Detail.Widen(c))
End Function

/*!
@overload
*/
Function ToLower(c As CHAR) As CHAR
	Return Detail.Narrow(ToLower(Detail.Widen(c)))
End Function

/*!
@overload
*/
Function ToUpper(c As CHAR) As CHAR
	Return Detail.Narrow(ToUpper(Detail.Widen(c)))
End Function

End Namespace 'CType
End Namespace 'ActiveBasic
