Index: trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
===================================================================
--- trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 400)
+++ trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab	(revision 457)
@@ -205,5 +205,5 @@
 */
 Function FormatFloatF_Core(s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder
-	FormatFloatF_Core = New System.Text.StringBuilder
+	FormatFloatF_Core = New System.Text.StringBuilder(128)
 	With FormatFloatF_Core
 		AppendSign(FormatFloatF_Core, negative, flags)
@@ -818,10 +818,8 @@
 
 	Dim sb = New System.Text.StringBuilder
-	If sb.Length = &hfeeefeee Then Debug
 	With sb
 		Dim prefixFunc = tr.Prefix
 		Dim prefix = prefixFunc(x, flags)
 		sb.Append(prefix)
-		If sb.Length = &hfeeefeee Then Debug
 
 		Dim prefixLen = 0 As DWord
@@ -830,9 +828,9 @@
 		End If
 
-		Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar
+'		Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar
+		Dim buf[MaxSizeLO] As StrChar
 		Dim convertFunc = tr.Convert
 		Dim bufStartPos = convertFunc(buf, x, flags)
 
-		If sb.Length = &hfeeefeee Then Debug
 		Dim len = (tr.MaxSize - bufStartPos) As Long
 		If len < 0 Then
@@ -844,8 +842,6 @@
 
 		.Append(buf, bufStartPos + 1, len)
-		If sb.Length = &hfeeefeee Then Debug
 
 		AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen)
-		If sb.Length = &hfeeefeee Then Debug
 	End With
 	FormatIntegerEx = sb.ToString()
@@ -855,4 +851,53 @@
 	End If
 End Function
+Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags)
+
+	If d = DWORD_MAX Then
+		d = 1
+	Else
+		'精度が指定されているとき、ゼロフラグは無視される。
+		'仕様上、左揃えのときも無視されるが、それはAdjustFieldWidthが行ってくれる。
+		flags And= Not Zero
+	End If
+
+	Dim lastLength = sb.Length
+
+	With sb
+		Dim prefixFunc = tr.Prefix
+		Dim prefix = prefixFunc(x, flags)
+		sb.Append(prefix)
+
+		Dim prefixLen = 0 As DWord
+		If String.IsNullOrEmpty(prefix) = False Then
+			prefixLen = prefix.Length As DWord
+		End If
+
+'		Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar
+		Dim buf[MaxSizeLO] As StrChar
+		Dim convertFunc = tr.Convert
+		Dim bufStartPos = convertFunc(buf, x, flags)
+
+		Dim len = (tr.MaxSize - bufStartPos) As Long
+		If len < 0 Then
+			Debug
+		End If
+		If len < d Then
+			.Append(&h30 As StrChar, d - len)
+		End If
+
+		.Append(buf, bufStartPos + 1, len)
+
+		AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength)
+	End With
+	Dim t = sb.ToString()
+	
+	If (flags And Cap) = 0 Then
+		Dim len = sb.Length
+		Dim i As Long
+		For i = lastLength To ELM(len)
+			sb[i] = CType.ToLower(sb[i])
+		Next
+	End If
+End Sub
 
 /*!
@@ -864,5 +909,5 @@
 
 /*!
-@brief	文字列をフィールド幅まで満たされるように空白などを挿入する。
+@brief	書式化の仕上げとして、変換部分がフィールド幅まで満たされるように空白などを挿入する。
 @author	Egtra
 @date	2007/10/13
@@ -872,22 +917,23 @@
 @param[in] flags	フラグ
 @param[in] prefixLen	（あれば）接頭辞の文字数。ゼロ埋めする際、この数だけ挿入位置を後ろにする。
+@param[in] offset	変換した部分へのオフセット。AppendではなくInsertを行う際に用いられる。
 sbが"-1"のように負符号を持っている場合は、呼出元でSignフラグ（またはBlank）を立てること。
 */
-Sub AdjustFieldWidth(sb As System.Text.StringBuilder, field As DWord, flags As FormatFlags, prefixLen = 0 As DWord)
+Sub AdjustFieldWidth(sb As System.Text.StringBuilder, field As DWord, flags As FormatFlags, prefixLen = 0 As DWord, offset = 0 As Long)
 	With sb
-		If .Length < field Then
-			Dim embeddedSize = field - .Length
+		Dim len = .Length - offset
+		If len < field Then
+			Dim embeddedSize = field - len
 			If flags And LeftSide Then
 				.Append(&h20, embeddedSize)
 			Else
-				Dim insPos As Long
 				If (flags And Zero) <> 0 Then
+					offset += prefixLen
 					If (flags And Blank) Or (flags And Sign) Then
-						insPos++
+						offset++
 					End If
-					insPos += prefixLen
-					.Insert(insPos, String$(embeddedSize, "0"))
+					.Insert(offset, String$(embeddedSize, "0"))
 				Else
-					.Insert(insPos, String$(embeddedSize, " "))
+					.Insert(offset, String$(embeddedSize, " "))
 				End If
 			End If
@@ -1005,5 +1051,6 @@
 	End If
 
-	s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags))
+'	s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags))
+	FormatIntegerEx(s, ByVal traits, x, precision, field, flags)
 End Sub
 
@@ -1028,5 +1075,5 @@
 	Do
 		Dim c = s[i]
-		If Not IsDigit(c) Then Exit Do
+		If Not CType.IsDigit(c) Then Exit Do
 		StrToLong *= 10
 		StrToLong += ((c As DWord) And &h0f) As Long
@@ -1037,17 +1084,4 @@
 	End If
 	p = VarPtr(s[i])
-End Function
-
-/*!
-@brief	文字が十進数字かどうか調べる。
-@author	Egtra
-@date	2007/11/11
-@param[in] c	調べる文字
-@retval True	0から9の文字である
-@retval False	そうでない
-*/
-Function IsDigit(c As StrChar) As Boolean
-	Dim dw = (c As DWord)
-	IsDigit = (dw - &h30) < 10
 End Function
 
