Index: trunk/Include/system/string.sbp
===================================================================
--- trunk/Include/system/string.sbp	(revision 386)
+++ trunk/Include/system/string.sbp	(revision 395)
@@ -31,238 +31,332 @@
 _System_AllocForConvertedString = AddressOf (GC_malloc_atomic)
 
-Function GetStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
-	If psz <> 0 Then
-		Return GetStr(psz, lstrlenA(psz) As SIZE_T, wcs)
-	Else
-		Return 0
-	End If
-End Function
-
-Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
-	If psz = 0 Then Return 0
-	Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0)
-	wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
-	GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS)
-	wcs[GetStr] = 0
-End Function
-
-Function GetStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
-	wcs = psz
-	If psz <> 0 Then
-		Return lstrlenW(psz) As SIZE_T
-	Else
-		Return 0
-	End If
-End Function
-
-Function GetStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
-	wcs = psz
-	If psz <> 0 Then
+Namespace Detail
+	Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+		Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, mbsSrc, (len As DWord) As Long, 0, 0)
+		wcsDst = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR
+		GetWCStr = MultiByteToWideChar(CP_THREAD_ACP, 0, mbsSrc, (len As DWord) As Long, wcsDst, lenWCS)
+		wcsDst[GetWCStr] = 0
+	End Function
+
+	Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+		wcsDst = wcsSrc
+		GetWCStr = len
+	End Function
+
+	Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+		Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, wcsSrc, (len As DWord) As Long, 0, 0, 0, 0)
+		mbsDst = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
+		GetMBStr = WideCharToMultiByte(CP_THREAD_ACP, 0, wcsSrc, (wcsSrc As DWord) As Long, mbsDst, lenMBS, 0, 0) As SIZE_T
+		mbsDst[GetMBStr] = 0
+	End Function
+
+	Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+		mbsDst = mbsSrc
+		GetMBStr = len
+	End Function
+End Namespace
+
+/*
+変換の組み合わせは、
+入力引数: wcsz, wcs + len, mbsz, mbs + len, str
+出力関数: wcs(z)出力GetStr, mbs(z)出力GetStr,
+          wcs(z)出力GetStrNT, mbs(z)出力GetStrNT,
+          GetWCStr, GetMBStr, GetTCStr, GetSCStr,
+          ToWCStr, ToMBStr, ToTCStr, ToSCStr
+で、5 * 12 = 60通り。
+*/
+
+Function GetStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
+	If mbszSrc = 0 Then
+		wcsDst = 0
+		Return 0
+	Else
+		Return Detail.GetWCStr(mbszSrc, lstrlenA(mbszSrc) As SIZE_T, wcsDst)
+	End If
+End Function
+
+Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+	If mbsSrc = 0 Then
+		wcsDst = 0
+		Return 0
+	Else
+		Return Detail.GetWCStr(mbsSrc, len, wcsDst)
+	End If
+End Function
+
+Function GetStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
+	If wcszSrc = 0 Then
+		wcsDst = 0
+		Return 0
+	Else
+		wcsDst = wcszSrc
+		Return lstrlenW(wcszSrc) As SIZE_T
+	End If
+End Function
+
+Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+	If wcsSrc = 0 Then
+		wcsDst = 0
+		Return 0
+	Else
+		wcsDst = wcsSrc
 		Return len
-	Else
-		Return 0
-	End If
-End Function
-
-Function GetStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
-	If psz = 0 Then
-		Return 0
-	Else
-		Return GetStr(psz, lstrlenW(psz) As SIZE_T, mbs)
-	End If
-End Function
-
-Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
-	If psz = 0 Then Return 0
-	Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0)
-	mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR
-	GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T
-	mbs[GetStr] = 0
-End Function
-
-Function GetStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
-	mbs = psz
-	If psz <> 0 Then
-		Return lstrlenA(psz) As SIZE_T
-	Else
-		Return 0
-	End If
-End Function
-
-Function GetStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
-	mbs = psz
-	If psz <> 0 Then
+	End If
+End Function
+
+Function GetStr(wcszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
+	If wcszSrc = 0 Then
+		mbsDst = 0
+		Return 0
+	Else
+		Return Detail.GetMBStr(wcszSrc, lstrlenW(wcszSrc) As SIZE_T, mbsDst)
+	End If
+End Function
+
+Function GetStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+	If wcsSrc = 0 Then
+		mbsDst = 0
+		Return 0
+	Else
+		Return Detail.GetMBStr(wcsSrc, len As SIZE_T, mbsDst)
+	End If
+End Function
+
+Function GetStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
+	If mbszSrc = 0 Then
+		mbsDst = 0
+		Return 0
+	Else
+		mbsDst = mbszSrc
+		Return lstrlenA(mbszSrc) As SIZE_T
+	End If
+End Function
+
+Function GetStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+	If mbsSrc = 0 Then
+		mbsDst = 0
 		Return len
 	Else
-		Return 0
-	End If
-End Function
-
-Function GetStr(s As String, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
-End Function
-
-Function GetStr(s As String, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
-End Function
-
-Function GetWCStr(psz As PSTR, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(psz, wcs)
-End Function
-
-Function GetWCStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(psz, len, wcs)
-End Function
-
-Function GetWCStr(psz As PWSTR, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(psz, wcs)
-End Function
-
-Function GetWCStr(psz As PWSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(psz, len, wcs)
-End Function
-
-Function GetWCStr(s As String, ByRef wcs As PWSTR) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, wcs)
-End Function
-
-Function GetMBStr(psz As PWSTR, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(psz, mbs)
-End Function
-
-Function GetMBStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(psz, len, mbs)
-End Function
-
-Function GetMBStr(psz As PSTR, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(psz, mbs)
-End Function
-
-Function GetMBStr(psz As PSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(psz, len, mbs)
-End Function
-
-Function GetMBStr(s As String, ByRef mbs As PSTR) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, mbs)
-End Function
-
-Function GetTCStr(psz As PSTR, ByRef tcs As PCTSTR) As SIZE_T
-	Return GetStr(psz, tcs)
-End Function
-
-Function GetTCStr(psz As PSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
-	Return GetStr(psz, len, tcs)
-End Function
-
-Function GetTCStr(psz As PWSTR, ByRef tcs As PCTSTR) As SIZE_T
-	Return GetStr(psz, tcs)
-End Function
-
-Function GetTCStr(psz As PWSTR, len As SIZE_T, ByRef tcs As PCTSTR) As SIZE_T
-	Return GetStr(psz, len, tcs)
-End Function
-
-Function GetTCStr(s As String, ByRef tcs As PCTSTR) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, tcs)
-End Function
-
-Function GetSCStr(psz As PSTR, ByRef ss As *StrChar) As SIZE_T
-	Return GetStr(psz, ss)
-End Function
-
-Function GetSCStr(psz As PSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
-	Return GetStr(psz, len, ss)
-End Function
-
-Function GetSCStr(psz As PWSTR, ByRef ss As *StrChar) As SIZE_T
-	Return GetStr(psz, ss)
-End Function
-
-Function GetSCStr(psz As PWSTR, len As SIZE_T, ByRef ss As *StrChar) As SIZE_T
-	Return GetStr(psz, len, ss)
-End Function
-
-Function GetSCStr(s As String, ByRef ss As *StrChar) As SIZE_T
-	Return GetStr(s.StrPtr, s.Length As SIZE_T, ss)
-End Function
-
-Function ToWCStr(psz As PSTR) As PWSTR
-	GetStr(psz, ToWCStr)
-End Function
-
-Function ToWCStr(psz As PSTR, len As SIZE_T) As PWSTR
-	GetStr(psz, len, ToWCStr)
-End Function
-
-Function ToWCStr(psz As PWSTR) As PWSTR
-	GetStr(psz, ToWCStr)
-End Function
-
-Function ToWCStr(psz As PWSTR, len As SIZE_T) As PWSTR
-	GetStr(psz, len, ToWCStr)
+		mbsDst = mbsSrc
+		Return 0
+	End If
+End Function
+
+Function GetStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
+	If ActiveBasic.IsNothing(strSrc) Then
+		wcsDst = 0
+		Return 0
+	Else
+		Return Detail.GetWCStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
+	End If
+End Function
+
+Function GetStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
+	If ActiveBasic.IsNothing(strSrc) Then
+		mbsDst = 0
+		Return 0
+	Else
+		Return Detail.GetMBStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
+	End If
+End Function
+
+Sub GetStrNT(mbszSrc As PSTR, ByRef mbszDst As PSTR)
+	mbszDst = mbszSrc
+End Sub
+
+Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef mbszDst As PSTR)
+	mbszDst = mbsSrc
+End Sub
+
+Sub GetStrNT(mbszSrc As PSTR, ByRef wcszDst As PWSTR)
+	GetStr(mbszSrc, wcszDst)
+End Sub
+
+Sub GetStrNT(mbsSrc As PSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
+	GetStr(mbsSrc, len, wcszDst)
+End Sub
+
+Sub GetStrNT(wcszSrc As PWSTR, ByRef mbszDst As PSTR)
+	GetStr(wcszSrc, mbszDst)
+End Sub
+
+Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef mbszDst As PSTR)
+	GetStr(wcsSrc, len, mbszDst)
+End Sub
+
+Sub GetStrNT(wcszSrc As PWSTR, ByRef wcszDst As PWSTR)
+	wcszDst = wcszSrc
+End Sub
+
+Sub GetStrNT(wcsSrc As PWSTR, len As SIZE_T, ByRef wcszDst As PWSTR)
+	wcszDst = wcsSrc
+End Sub
+
+Sub GetStrNT(strSrc As String, ByRef mbszDst As PSTR)
+	GetStr(strSrc, mbszDst)
+End Sub
+
+Sub GetStrNT(strSrc As String, ByRef wcszDst As PWSTR)
+	GetStr(strSrc, wcszDst)
+End Sub
+
+Function GetWCStr(mbszSrc As PSTR, ByRef wcsDst As PWSTR) As SIZE_T
+	Return GetStr(mbszSrc, wcsDst)
+End Function
+
+Function GetWCStr(mbsSrc As PSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+	Return GetStr(mbsSrc, len, wcsDst)
+End Function
+
+Function GetWCStr(wcszSrc As PWSTR, ByRef wcsDst As PWSTR) As SIZE_T
+	Return GetStr(wcszSrc, wcsDst)
+End Function
+
+Function GetWCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef wcsDst As PWSTR) As SIZE_T
+	Return GetStr(wcsSrc, len, wcsDst)
+End Function
+
+Function GetWCStr(strSrc As String, ByRef wcsDst As PWSTR) As SIZE_T
+	Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, wcsDst)
+End Function
+
+Function GetMBStr(mbszSrc As PWSTR, ByRef mbsDst As PSTR) As SIZE_T
+	Return GetStr(mbszSrc, mbsDst)
+End Function
+
+Function GetMBStr(wcsSrc As PWSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+	Return GetStr(wcsSrc, len, mbsDst)
+End Function
+
+Function GetMBStr(mbszSrc As PSTR, ByRef mbsDst As PSTR) As SIZE_T
+	Return GetStr(mbszSrc, mbsDst)
+End Function
+
+Function GetMBStr(mbsSrc As PSTR, len As SIZE_T, ByRef mbsDst As PSTR) As SIZE_T
+	Return GetStr(mbsSrc, len, mbsDst)
+End Function
+
+Function GetMBStr(strSrc As String, ByRef mbsDst As PSTR) As SIZE_T
+	Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, mbsDst)
+End Function
+
+Function GetTCStr(mbszSrc As PSTR, ByRef tcsDst As PCTSTR) As SIZE_T
+	Return GetStr(mbszSrc, tcsDst)
+End Function
+
+Function GetTCStr(mbsSrc As PSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
+	Return GetStr(mbsSrc, len, tcsDst)
+End Function
+
+Function GetTCStr(wcszSrc As PWSTR, ByRef tcsDst As PCTSTR) As SIZE_T
+	Return GetStr(wcszSrc, tcsDst)
+End Function
+
+Function GetTCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef tcsDst As PCTSTR) As SIZE_T
+	Return GetStr(wcsSrc, len, tcsDst)
+End Function
+
+Function GetTCStr(strSrc As String, ByRef tcsDst As PCTSTR) As SIZE_T
+	Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, tcsDst)
+End Function
+
+Function GetSCStr(mbszSrc As PSTR, ByRef ssDst As *StrChar) As SIZE_T
+	Return GetStr(mbszSrc, ssDst)
+End Function
+
+Function GetSCStr(mbsSrc As PSTR, len As SIZE_T, ByRef ssDst As *StrChar) As SIZE_T
+	Return GetStr(mbsSrc, len, ssDst)
+End Function
+
+Function GetSCStr(wcszSrc As PWSTR, ByRef ssDst As *StrChar) As SIZE_T
+	Return GetStr(wcszSrc, ssDst)
+End Function
+
+Function GetSCStr(wcsSrc As PWSTR, len As SIZE_T, ByRef ssDst As *StrChar) As SIZE_T
+	Return GetStr(wcsSrc, len, ssDst)
+End Function
+
+Function GetSCStr(strSrc As String, ByRef ssDst As *StrChar) As SIZE_T
+	Return GetStr(strSrc.StrPtr, strSrc.Length As SIZE_T, ssDst)
+End Function
+
+Function ToWCStr(mbsz As PSTR) As PWSTR
+	GetStrNT(mbsz, ToWCStr)
+End Function
+
+Function ToWCStr(mbs As PSTR, len As SIZE_T) As PWSTR
+	GetStrNT(mbs, len, ToWCStr)
+End Function
+
+Function ToWCStr(wcsz As PWSTR) As PWSTR
+	ToWCStr = wcsz
+End Function
+
+Function ToWCStr(wcs As PWSTR, len As SIZE_T) As PWSTR
+	ToWCStr = wcs
 End Function
 
 Function ToWCStr(s As String) As PWSTR
-	GetStr(s.StrPtr, s.Length As SIZE_T, ToWCStr)
-End Function
-
-Function ToMBStr(psz As PSTR) As PSTR
-	GetStr(psz, ToMBStr)
-End Function
-
-Function ToMBStr(psz As PSTR, len As SIZE_T) As PSTR
-	GetStr(psz, len, ToMBStr)
-End Function
-
-Function ToMBStr(psz As PWSTR) As PSTR
-	GetStr(psz, ToMBStr)
-End Function
-
-Function ToMBStr(psz As PWSTR, len As SIZE_T) As PSTR
-	GetStr(psz, len, ToMBStr)
+	GetStrNT(s, ToWCStr)
+End Function
+
+Function ToMBStr(mbsz As PSTR) As PSTR
+	ToMBStr = mbsz
+End Function
+
+Function ToMBStr(mbs As PSTR, len As SIZE_T) As PSTR
+	ToMBStr = mbs
+End Function
+
+Function ToMBStr(wcsz As PWSTR) As PSTR
+	GetStrNT(wcsz, ToMBStr)
+End Function
+
+Function ToMBStr(wcs As PWSTR, len As SIZE_T) As PSTR
+	GetStrNT(wcs, len, ToMBStr)
 End Function
 
 Function ToMBStr(s As String) As PSTR
-	GetStr(s.StrPtr, s.Length As SIZE_T, ToMBStr)
-End Function
-
-Function ToTCStr(psz As PSTR) As PCTSTR
-	GetStr(psz, ToTCStr)
-End Function
-
-Function ToTCStr(psz As PSTR, len As SIZE_T) As PCTSTR
-	GetStr(psz, len, ToTCStr)
-End Function
-
-Function ToTCStr(psz As PWSTR) As PCTSTR
-	GetStr(psz, ToTCStr)
-End Function
-
-Function ToTCStr(psz As PWSTR, len As SIZE_T) As PCTSTR
-	GetStr(psz, len, ToTCStr)
+	GetStrNT(s, ToMBStr)
+End Function
+
+Function ToTCStr(mbsz As PSTR) As PCTSTR
+	GetStrNT(mbsz, ToTCStr)
+End Function
+
+Function ToTCStr(mbs As PSTR, len As SIZE_T) As PCTSTR
+	GetStrNT(mbs, len, ToTCStr)
+End Function
+
+Function ToTCStr(wcsz As PWSTR) As PCTSTR
+	GetStrNT(wcsz, ToTCStr)
+End Function
+
+Function ToTCStr(wcs As PWSTR, len As SIZE_T) As PCTSTR
+	GetStrNT(wcs, len, ToTCStr)
 End Function
 
 Function ToTCStr(s As String) As PCTSTR
-	GetStr(s.StrPtr, s.Length As SIZE_T, ToTCStr)
-End Function
-
-Function ToSCStr(psz As PSTR) As *StrChar
-	GetStr(psz, ToSCStr)
-End Function
-
-Function ToSCStr(psz As PSTR, len As SIZE_T) As *StrChar
-	GetStr(psz, len, ToSCStr)
-End Function
-
-Function ToSCStr(psz As PWSTR) As *StrChar
-	GetStr(psz, ToSCStr)
-End Function
-
-Function ToSCStr(psz As PWSTR, len As SIZE_T) As *StrChar
-	GetStr(psz, len, ToSCStr)
+	GetStrNT(s, ToTCStr)
+End Function
+
+Function ToSCStr(mbsz As PSTR) As *StrChar
+	GetStrNT(mbsz, ToSCStr)
+End Function
+
+Function ToSCStr(mbs As PSTR, len As SIZE_T) As *StrChar
+	GetStrNT(mbs, len, ToSCStr)
+End Function
+
+Function ToSCStr(wcsz As PWSTR) As *StrChar
+	GetStrNT(wcsz, ToSCStr)
+End Function
+
+Function ToSCStr(wcs As PWSTR, len As SIZE_T) As *StrChar
+	GetStrNT(wcs, len, ToSCStr)
 End Function
 
 Function ToSCStr(s As String) As *StrChar
-	GetStr(s.StrPtr, s.Length As SIZE_T, ToSCStr)
+	ToSCStr = StrPtr(s)
 End Function
 
