Changeset 468 for trunk


Ignore:
Timestamp:
Mar 9, 2008, 12:00:01 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

TextWriter, StreamWriterの追加。
SPrintfの浮動小数点数変換で、NaN, Infiniteの出力に対応。
PathとDirectoryInfoのCreateDirectoryで、対象が既に存在するときには例外を投げないように修正。
SimpleTestCase内で使用する一時フォルダの場所にGetTempPathで取得する版を追加(コメントアウト)。

Location:
trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab

    r457 r468  
    1 'Classes/ActiveBasic/Strings/SPrintF.ab
     1/*!
     2@file Include/Classes/ActiveBasic/Strings/SPrintF.ab
     3@brief SPrintfとその補助ルーチンが含まれるファイル。
     4
     5SPrintfで数値変換が行われるとき、呼出の階層は、
     6SPrintf→FormatInteger, FormatFloat→FormatIntegerEx, FormatFloatExとなる。
     7
     8また、次のような変換ルーチンが存在する。
     9@li FormatFloatE
     10@li FormatFloatF
     11@li FormatFloatG
     12@li FormatFloatA
     13@li FormatIntegerD
     14@li FormatIntegerU
     15@li FormatIntegerO
     16@li FormatIntegerX
     17@li FormatCharacter
     18@li FormatString
     19*/
    220
    321Namespace ActiveBasic
     
    92110    LeftSide = &h8
    93111    /*! 代替表記、#。
    94     <ul>
    95         <li>[OoXx]では、値が0でない場合、先頭に0、0xを付ける。</ul>
    96         <li>[AaEeFfGg]では、精度0でも小数点を付ける。</ul>
    97         <li>[Gg]では、それに加え、小数部末尾の0の省略を行わないようにする。</ul>
    98     </ul>
     112    @li [OoXx]では、値が0でない場合、先頭に0、0xを付ける。</ul>
     113    @li [AaEeFfGg]では、精度0でも小数点を付ける。</ul>
     114    @li [Gg]では、それに加え、小数部末尾の0の省略を行わないようにする。</ul>
    99115    */
    100116    Alt = &h10
     
    121137@param[in] flags    書式フラグ。
    122138@return xの文字列表現
    123 
     139*/
     140Function FormatFloatE(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     141    FormatFloatE = FormatFloatEx(AddressOf(FormatFloatE_Convert), x, precision, field, flags)
     142End Function
     143
     144/*
     145@brief  浮動小数点数をprintfの%e, %E(指数形式、十進法)相当の変換で文字列化する関数。
     146@author Egtra
     147@date   2008/03/08
     148@param[in,out] sb 書式化した文字列を追加するバッファ。
     149@param[in] x    文字列化する浮動小数点数値。
     150@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。
     151@param[in] field    フィールド幅。
     152@param[in] flags    書式フラグ。
     153*/
     154Sub FormatFloatE(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
     155    FormatFloatEx(sb, AddressOf(FormatFloatE_Convert), x, precision, field, flags)
     156End Sub
     157
     158/*!
     159@brief  浮動小数点数をprintfの%e, %E(指数形式、十進法)相当の変換で文字列化する関数。
     160@author Egtra
     161@date   2008/03/07
     162@param[in,out] sb 書式化した文字列を追加するバッファ。
     163@param[in] x    文字列化する浮動小数点数値。
     164@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして15となる。
     165@param[in] field    フィールド幅。
     166@param[in,out] flags    書式フラグ。
    124167@todo   他の実装での末尾桁の扱いを調べる(このコードでは何もしていないので切捨となっている)。
    125168*/
    126 Function FormatFloatE(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     169Sub FormatFloatE_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
    127170    If precision = DWORD_MAX Then
    128         precision = 6
    129     End If
    130 
     171        precision = 15
     172    End If
    131173    Dim e As Long, negative As Boolean
    132174    Dim s = FloatToChars(x, e, negative)
    133     Dim sb = FormatFloatE_Base(s, negative, precision, flags)
     175    FormatFloatE_Base(sb, s, negative, precision, flags)
    134176    FormatFloatE_Exponent(sb, e, flags)
    135     AdjustFieldWidth(sb, field, flags)
    136     FormatFloatE = sb.ToString()
    137 End Function
     177End Sub
    138178
    139179/**
     
    142182@date   2007/10/27
    143183*/
    144 Function FormatFloatE_Base(s As String, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder
    145     FormatFloatE_Base = New System.Text.StringBuilder
    146     With FormatFloatE_Base
    147         AppendSign(FormatFloatE_Base, negative, flags)
    148 
     184Sub FormatFloatE_Base(sb As System.Text.StringBuilder, s As String, negative As Boolean, precision As DWord, ByRef flags As FormatFlags)
     185    With sb
     186        AppendSign(sb, negative, flags)
    149187        .Append(s[0])
    150 
    151188        If (flags And Alt) Or precision > 0 Then
    152189            .Append(".")
     
    156193            Else 'sで用意された桁が指定された精度より少ないとき
    157194                .Append(s, 1, outputLen)
    158                 .Append(&h30 As StrChar, precision - outputLen) '足りない桁は0埋め
     195                .Append(&h30 As Char, precision - outputLen) '足りない桁は0埋め
    159196            End If
    160197        End If
    161198    End With
    162 End Function
     199End Sub
    163200
    164201/**
     
    167204@date   2007/10/27
    168205*/
    169 Sub FormatFloatE_Exponent(buf As System.Text.StringBuilder, e As Long, flags As FormatFlags)
    170     With buf
     206Sub FormatFloatE_Exponent(sb As System.Text.StringBuilder, e As Long, flags As FormatFlags)
     207    With sb
    171208        If flags And Cap Then
    172209            .Append("E")
     
    174211            .Append("e")
    175212        End If
    176         .Append(FormatIntegerD(e, 2, 0, Sign Or Zero))
     213        FormatIntegerD(sb, e, 2, 0, Sign Or Zero)
    177214    End With
    178215End Sub
     
    183220@date   2007/10/23
    184221@param[in]  x   文字列化する浮動小数点数値。
    185 @param[in]  precision   精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。
     222@param[in]  precision   精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値15となる。
    186223@param[in]  field   フィールド幅。
    187224@param[in]  flags   書式フラグ。
     
    189226*/
    190227Function FormatFloatF(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     228    FormatFloatF = FormatFloatEx(AddressOf(FormatFloatF_Convert), x, precision, field, flags)
     229End Function
     230
     231/*
     232@brief  浮動小数点数をprintfの%f(小数形式、十進法)相当の変換で文字列化する関数。
     233@author Egtra
     234@date   2008/03/08
     235@param[in,out] sb 書式化した文字列を追加するバッファ。
     236@param[in] x    文字列化する浮動小数点数値。
     237@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。
     238@param[in] field    フィールド幅。
     239@param[in] flags    書式フラグ。
     240*/
     241Sub FormatFloatF(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
     242    FormatFloatEx(sb, AddressOf(FormatFloatF_Convert), x, precision, field, flags)
     243End Sub
     244
     245/*!
     246@brief  浮動小数点数をprintfの%f(小数形式、十進法)相当の変換で文字列化する関数。
     247@author Egtra
     248@date   2008/03/07
     249@param[in,out] sb 書式化した文字列を追加するバッファ。
     250@param[in]  x   文字列化する浮動小数点数値。
     251@param[in]  precision   精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値15となる。
     252@param[in]  field   フィールド幅。
     253@param[in,out]  flags   書式フラグ。
     254*/
     255Sub FormatFloatF_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
    191256    If precision = DWORD_MAX Then
    192         precision = 6
    193     End If
    194 
     257        precision = 15
     258    End If
    195259    Dim e As Long, negative As Boolean
    196260    Dim s = FloatToChars(x, e, negative)
    197     Dim sb = FormatFloatF_Core(s, e, negative, precision, flags)
    198     AdjustFieldWidth(sb, field, flags)
    199     FormatFloatF = sb.ToString()
    200 End Function
     261    FormatFloatF_Core(sb, s, e, negative, precision, flags)
     262End Sub
    201263
    202264/**
     
    204266@date   2007/10/27
    205267*/
    206 Function FormatFloatF_Core(s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags) As System.Text.StringBuilder
    207     FormatFloatF_Core = New System.Text.StringBuilder(128)
    208     With FormatFloatF_Core
    209         AppendSign(FormatFloatF_Core, negative, flags)
     268Sub FormatFloatF_Core(sb As System.Text.StringBuilder, s As String, e As Long, negative As Boolean, precision As DWord, ByRef flags As FormatFlags)
     269    With sb
     270        AppendSign(sb, negative, flags)
    210271
    211272        Dim intPartLen = e + 1
     
    214275            '有効桁が全て整数部に収まる場合
    215276            .Append(s)
    216             .Append(&h30 As StrChar, intPartLen - 17)
     277            .Append(&h30 As Char, intPartLen - 17)
    217278            outputDigit = 17
    218279        ElseIf intPartLen > 0 Then
     
    222283        Else
    223284            '有効桁が全く整数部にかからない場合
    224             .Append(&h30 As StrChar)
     285            .Append(&h30 As Char)
    225286        End If
    226287
     
    234295                    '1.23e-4 = 0.000123のように指数が負のため小数点以下に0が続く場合
    235296                    zeroDigit = System.Math.Min(-intPartLen As DWord, precision)
    236                     .Append(&h30 As StrChar, zeroDigit As Long)
     297                    .Append(&h30 As Char, zeroDigit As Long)
    237298                End If
    238299                .Append(s, outputDigit, (precision - zeroDigit) As Long)
    239300            Else
    240301                .Append(s, outputDigit, lastDigit)
    241                 .Append(&h30 As StrChar, (precision - lastDigit) As Long) '残りの桁は0埋め
     302                .Append(&h30 As Char, (precision - lastDigit) As Long) '残りの桁は0埋め
    242303            End If
    243304        End If
    244305    End With
    245 End Function
     306End Sub
    246307
    247308/*!
     
    250311@date   2007/10/23
    251312@param[in]  x   文字列化する浮動小数点数値。
    252 @param[in]  precision   精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値6となる。
     313@param[in]  precision   精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値15となる。
    253314@param[in]  field   フィールド幅。
    254315@param[in]  flags   書式フラグ。
     
    257318*/
    258319Function FormatFloatG(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     320    FormatFloatG = FormatFloatEx(AddressOf(FormatFloatG_Convert), x, precision, field, flags)
     321End Function
     322
     323/*
     324@brief  浮動小数点数をprintfの%g, %G(小数・指数、十進法)相当の変換で文字列化する関数。
     325@author Egtra
     326@date   2008/03/08
     327@param[in,out] sb 書式化した文字列を追加するバッファ。
     328@param[in] x    文字列化する浮動小数点数値。
     329@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。
     330@param[in] field    フィールド幅。
     331@param[in] flags    書式フラグ。
     332*/
     333Sub FormatFloatG(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
     334    FormatFloatEx(sb, AddressOf(FormatFloatG_Convert), x, precision, field, flags)
     335End Sub
     336
     337/*!
     338@brief  浮動小数点数をprintfの%g, %G(小数・指数、十進法)相当の変換で文字列化する関数。
     339@author Egtra
     340@date   2007/10/23
     341@param[in,out] sb 書式化した文字列を追加するバッファ。
     342@param[in]  x   文字列化する浮動小数点数値。
     343@param[in]  precision   精度。小数点以下の桁数。DWORD_MAXまたは0のとき、指定なしとして既定値15となる。
     344@param[in]  field   フィールド幅。
     345@param[in,out]  flags   書式フラグ。
     346@todo   下位桁の扱いの調査。
     347*/
     348Sub FormatFloatG_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
    259349    'GではE/Fと違い整数部も有効桁数に数えるのでその分を引いておく。
    260350    If precision = DWORD_MAX Or precision = 0 Then
    261         precision = 5
     351        precision = 14
    262352    Else
    263353        precision--
    264354    End If
    265 
     355    Dim lastLength = sb.Length
    266356    Dim e As Long, negative As Boolean
    267357    Dim s = FloatToChars(x, e, negative)
    268 
    269     Dim sb = Nothing As System.Text.StringBuilder
    270 
    271358    If -5 < e And e < precision Then
    272         sb = FormatFloatF_Core(s, e, negative, -e + precision, flags)
    273         FormatFloatG_RemoveLowDigit(sb, flags)
     359        FormatFloatF_Core(sb, s, e, negative, -e + precision, flags)
     360        FormatFloatG_RemoveLowDigit(sb, lastLength, flags)
    274361    Else
    275         sb = FormatFloatE_Base(s, negative, precision, flags)
    276         FormatFloatG_RemoveLowDigit(sb, flags)
     362        FormatFloatE_Base(sb, s, negative, precision, flags)
     363        FormatFloatG_RemoveLowDigit(sb, lastLength, flags)
    277364        FormatFloatE_Exponent(sb, e, flags)
    278365    End If
    279 
    280     AdjustFieldWidth(sb, field, flags)
    281     FormatFloatG = sb.ToString()
    282 End Function
     366End Sub
    283367
    284368/*!
     
    290374flagsでAltが立っているとき、この関数は何もしない。
    291375*/
    292 Sub FormatFloatG_RemoveLowDigit(sb As System.Text.StringBuilder, flags As FormatFlags)
     376Sub FormatFloatG_RemoveLowDigit(sb As System.Text.StringBuilder, start As Long, flags As FormatFlags)
    293377    Imports ActiveBasic.Strings
    294378   
    295379    Dim count = sb.Length
    296380    If (flags And Alt) = 0 Then
    297         Dim point = ChrFind(StrPtr(sb), count As SIZE_T, Asc("."))
     381        Dim p = StrPtr(sb)
     382        Dim point = ChrFind(VarPtr(p[start]), (count - start) As SIZE_T, Asc("."))
    298383        If point = -1 Then
    299384            Debug
     
    327412*/
    328413Function FormatFloatA(x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     414    FormatFloatA = FormatFloatEx(AddressOf(FormatFloatA_Convert), x, precision, field, flags)
     415End Function
     416
     417/*
     418@brief  浮動小数点数をprintfの%a, %A(指数形式、十六進法)相当の変換で文字列化する関数。
     419@author Egtra
     420@date   2008/03/08
     421@param[in,out] sb 書式化した文字列を追加するバッファ。
     422@param[in] x    文字列化する浮動小数点数値。
     423@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値6となる。
     424@param[in] field    フィールド幅。
     425@param[in] flags    書式フラグ。
     426*/
     427Sub FormatFloatA(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
     428    FormatFloatEx(sb, AddressOf(FormatFloatA_Convert), x, precision, field, flags)
     429End Sub
     430
     431/*!
     432@brief  浮動小数点数をprintfの%a, %A(指数形式、十六進法)相当の変換で文字列化する関数。
     433@author Egtra
     434@date   2008/03/07
     435@param[in,out] sb 書式化した文字列を追加するバッファ。
     436@param[in] x    文字列化する浮動小数点数値。
     437@param[in] precision    精度。小数点以下の桁数。DWORD_MAXのとき、指定なしとして既定値13となる。
     438@param[in] field    フィールド幅。
     439@param[in,out] flags    書式フラグ。
     440
     441C99では、末尾の0を取り除いても良いとあるので、
     442このルーチンでは取り除くことにしている。
     443*/
     444Sub FormatFloatA_Convert(sb As System.Text.StringBuilder, x As Double, precision As DWord, field As DWord, ByRef flags As FormatFlags)
    329445    If precision = DWORD_MAX Then
    330446        precision = 13
    331447    End If
    332 
     448    Dim lastLength = sb.Length
    333449    Dim pqw = VarPtr(x) As *QWord
    334450
    335     Dim sb = New System.Text.StringBuilder
    336451    With sb
    337452        Dim sign = (GetQWord(pqw) And &H8000000000000000) As Boolean
     
    362477        If precision > 0 Or (flags And Alt) Then
    363478            .Append(".")
    364             Dim base = FormatIntegerLX(GetQWord(pqw) And &h000fffffffffffff, 13, 0, flags And Cap)
    365             Dim diff = precision - 13 As Long
    366             If diff <= 0 Then
    367                 .Append(Left$(base, precision))
     479            Dim fraction = GetQWord(pqw) And &h000fffffffffffff
     480            If precision < 13 Then
     481                Dim dropped = 13 - precision
     482                fraction >>= dropped * 4
     483                FormatIntegerLX(sb, fraction, precision, 0, flags And Cap)
    368484            Else
    369                 .Append(base).Append(&h30, diff)
     485                FormatIntegerLX(sb, fraction, 13, 0, flags And Cap)
     486                .Append(&h30, precision - 13)
    370487            End If
    371488        End If
    372 
    373         FormatFloatG_RemoveLowDigit(sb, flags)
    374 
     489        FormatFloatG_RemoveLowDigit(sb, lastLength, flags)
    375490        .Append("P")
    376         .Append(FormatIntegerD(exp, 1, 0, Sign))
    377        
    378         FormatFloatA = .ToString()
     491        FormatIntegerD(sb, exp, 1, 0, Sign)
     492        AdjustAlphabet(sb, flags, lastLength)
    379493    End With
    380 
    381     If (flags And Cap) = 0 Then
    382         FormatFloatA = FormatFloatA.ToLower()
    383     End If
    384 End Function
     494End Sub
    385495
    386496/*!
     
    408518
    409519/*!
    410 @brief  DWordの最大値4294967295の文字数 - 1。FormatIntegerU内で使用。
    411 @author Egtra
    412 @date   2007/09/18
    413 */
    414 Const MaxSizeU = 9
    415 
    416 /*!
    417520@brief  符号無し整数をprintfの%u(十進法表現)相当の変換で文字列化する関数。
    418521@author Egtra
     
    429532
    430533/*!
     534@brief  符号無し整数をprintfの%u(十進法表現)相当の変換で文字列化する関数。
     535@author Egtra
     536@date   2008/03/07
     537@param[in,out] sb 書式化した文字列を追加するバッファ。
     538@param[in]  x   文字列化する整数値。
     539@param[in]  d   精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。
     540@param[in]  field   フィールド幅。
     541@param[in]  flags   書式フラグ。
     542*/
     543Sub FormatIntegerU(sb As System.Text.StringBuilder, x As DWord, d As DWord, field As DWord, flags As FormatFlags)
     544    FormatIntegerEx(sb, TraitsIntegerU[0], x As QWord, d, field, flags And (Not (Sign Or Blank)))
     545End Sub
     546
     547/*!
    431548@brief  FormatIntegerUのQWord版
    432549@author Egtra
     
    436553    Return FormatIntegerEx(TraitsIntegerU[1], x, d, field, flags And (Not (Sign Or Blank)))
    437554End Function
     555
     556/*!
     557@brief  FormatIntegerUのQWord版
     558@author Egtra
     559@date   2008/03/07
     560@param[in,out] sb 書式化した文字列を追加するバッファ。
     561@param[in]  x   文字列化する整数値。
     562@param[in]  d   精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。
     563@param[in]  field   フィールド幅。
     564@param[in]  flags   書式フラグ。
     565*/
     566Sub FormatIntegerLU(sb As System.Text.StringBuilder, x As QWord, d As DWord, field As DWord, flags As FormatFlags)
     567    FormatIntegerEx(sb, TraitsIntegerU[0], x, d, field, flags And (Not (Sign Or Blank)))
     568End Sub
    438569
    439570/*!
     
    452583
    453584/*!
     585@brief  符号有り整数をprintfの%d(十進法表現)相当の変換で文字列化する関数。
     586@author Egtra
     587@date   2008/03/07
     588@param[in,out] sb 書式化した文字列を追加するバッファ。
     589@param[in]  x   文字列化する整数値。
     590@param[in]  d   精度、最小限表示される桁数。DWORD_MAXのとき、指定なしとして、既定値1となる。
     591@param[in]  field   フィールド幅。
     592@param[in]  flags   書式フラグ。
     593*/
     594Sub FormatIntegerD(sb As System.Text.StringBuilder, x As Long, d As DWord, field As DWord, flags As FormatFlags)
     595    FormatIntegerEx(sb, TraitsIntegerD[0], (x As Int64) As QWord, d, field, flags)
     596End Sub
     597
     598/*!
    454599@brief  FormatIntegerDのInt64版
    455600@author Egtra
     
    459604    Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, d, field, flags)
    460605End Function
     606
     607/*!
     608@brief  FormatIntegerDのInt64版
     609@author Egtra
     610@date   2007/10/26
     611*/
     612Sub FormatIntegerLD(sb As System.Text.StringBuilder, x As Int64, d As DWord, field As DWord, flags As FormatFlags)
     613    FormatIntegerEx(sb, TraitsIntegerD[1], x As QWord, d, field, flags)
     614End Sub
    461615
    462616/*!
     
    468622    .Convert = AddressOf(IntegerU_Convert)
    469623    .Prefix = AddressOf(IntegerU_Prefix)
    470     .MaxSize = MaxSizeU
    471624End With
    472625
     
    474627    .Convert = AddressOf(IntegerLU_Convert)
    475628    .Prefix = AddressOf(IntegerU_Prefix)
    476     .MaxSize = MaxSizeLU
    477629End With
    478630
     
    485637    .Convert = AddressOf(IntegerD_Convert)
    486638    .Prefix = AddressOf(IntegerD_Prefix)
    487     .MaxSize = MaxSizeU
    488639End With
    489640
     
    491642    .Convert = AddressOf(IntegerLD_Convert)
    492643    .Prefix = AddressOf(IntegerD_Prefix)
    493     .MaxSize = MaxSizeLU
    494644End With
    495645
     
    505655@date   2007/10/26
    506656*/
    507 Function IntegerU_Convert(buf As *StrChar, xq As QWord, flags As FormatFlags) As DWord
     657Function IntegerU_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord
    508658    Dim x = xq As DWord
    509     Dim i = MaxSizeU
     659    Dim i = MaxSizeLO
    510660    While x <> 0
    511         buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策
     661        buf[i] = (x As Int64 Mod 10 + &h30) As Char 'Int64への型変換は#117対策
    512662        x \= 10
    513663        i--
     
    522672@bug    #117のため、現在Int64の最大値を超える値を正しく処理できない。
    523673*/
    524 Function IntegerLU_Convert(buf As *StrChar, x As QWord, flags As FormatFlags) As DWord
    525     Dim i = MaxSizeLU
     674Function IntegerLU_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord
     675    Dim i = MaxSizeLO
    526676    While x <> 0
    527         buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策
     677        buf[i] = (x As Int64 Mod 10 + &h30) As Char 'Int64への型変換は#117対策
    528678        x \= 10
    529679        i--
     
    543693@date   2007/10/28
    544694*/
    545 Function IntegerD_Convert(buf As *StrChar, xq As QWord, flags As FormatFlags) As DWord
     695Function IntegerD_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord
    546696    Return IntegerU_Convert(buf, Abs((xq As DWord) As Long) As DWord, flags)
    547697End Function
     
    552702@date   2007/10/28
    553703*/
    554 Function IntegerLD_Convert(buf As *StrChar, x As QWord, flags As FormatFlags) As DWord
     704Function IntegerLD_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord
    555705    Return IntegerLU_Convert(buf, Abs(x As Int64) As QWord, flags)
    556706End Function
     
    570720End Function
    571721
    572 /*!
    573 @brief  DWordの最大値の八進法表現37777777777の文字数 - 1 + 1。IntegerO_Convert内で使用。
    574 @author Egtra
    575 @date   2007/10/19
    576 上の式で1を加えているのは、八進接頭辞の分。
    577 */
    578 Const MaxSizeO = 11
     722
    579723
    580724/*!
     
    594738    .Convert = AddressOf(IntegerO_Convert)
    595739    .Prefix = AddressOf(IntegerO_Prefix)
    596     .MaxSize = MaxSizeO
    597740End With
    598741
     
    600743    .Convert = AddressOf(IntegerLO_Convert)
    601744    .Prefix = AddressOf(IntegerO_Prefix)
    602     .MaxSize = MaxSizeLO
    603745End With
    604746
     
    630772@date   2007/10/22
    631773*/
    632 Function IntegerO_Convert(buf As *StrChar, xq As QWord, flags As FormatFlags) As DWord
     774Function IntegerO_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord
    633775    Dim x = xq As DWord
    634     Dim i = MaxSizeO
     776    Dim i = MaxSizeLO
    635777    While x <> 0
    636         buf[i] = ((x And &o7) + &h30) As StrChar
     778        buf[i] = ((x And &o7) + &h30) As Char
    637779        x >>= 3
    638780        i--
     
    650792@date   2007/10/26
    651793*/
    652 Function IntegerLO_Convert(buf As *StrChar, x As QWord, flags As FormatFlags) As DWord
     794Function IntegerLO_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord
    653795    Dim i = MaxSizeLO
    654796    While x <> 0
    655         buf[i] = ((x And &o7) + &h30) As StrChar
     797        buf[i] = ((x And &o7) + &h30) As Char
    656798        x >>= 3
    657799        i--
     
    678820
    679821/*!
    680 @brief  DWordの最大値の十六進法表現ffffffffの文字数 - 1。FormatIntegerO内で使用。
    681 @author Egtra
    682 @date   2007/10/24
    683 */
    684 Const MaxSizeX = 7
    685 
    686 /*!
    687 @brief  QWordの最大値の十六進法表現ffffffffffffffffの文字数 - 1。FormatIntegerO内で使用。
    688 @author Egtra
    689 @date   2007/10/26
    690 */
    691 Const MaxSizeLX = 15
    692 
    693 /*!
    694822@author Egtra
    695823@date   2007/10/24
     
    699827    .Convert = AddressOf(IntegerX_Convert)
    700828    .Prefix = AddressOf(IntegerX_Prefix)
    701     .MaxSize = MaxSizeX
    702829End With
    703830
     
    705832    .Convert = AddressOf(IntegerLX_Convert)
    706833    .Prefix = AddressOf(IntegerX_Prefix)
    707     .MaxSize = MaxSizeLX
    708834End With
    709835
     
    731857End Function
    732858
     859/*!
     860@brief  FormatIntegerXのQWord, StringBuilder版。
     861@author Egtra
     862@date   2008/03/07
     863*/
     864Sub FormatIntegerLX(sb As System.Text.StringBuilder, x As QWord, d As DWord, field As DWord, flags As FormatFlags)
     865    FormatIntegerEx(sb, TraitsIntegerX[1], x, d, field, flags)
     866End Sub
     867
    733868/*
    734869@brief  0からFまでの文字を収めた表
     
    741876@date   2007/10/22
    742877*/
    743 Function IntegerX_Convert(buf As *StrChar, xq As QWord, flags As FormatFlags) As DWord
    744     Dim i = MaxSizeX
     878Function IntegerX_Convert(buf As *Char, xq As QWord, flags As FormatFlags) As DWord
     879    Dim i = MaxSizeLO
    745880    Dim x = xq As DWord
    746881    While x <> 0
     
    757892@date   2007/10/22
    758893*/
    759 Function IntegerLX_Convert(buf As *StrChar, x As QWord, flags As FormatFlags) As DWord
    760     Dim i = MaxSizeLX
     894Function IntegerLX_Convert(buf As *Char, x As QWord, flags As FormatFlags) As DWord
     895    Dim i = MaxSizeLO
    761896    While x <> 0
    762897        buf[i] = HexadecimalTable[x And &h0f]
     
    791926Type IntegerConvertTraits
    792927    '!変換を行う関数へのポインタ。
    793     Convert As *Function(buf As *StrChar, x As QWord, flags As FormatFlags) As DWord
     928    Convert As *Function(buf As *Char, x As QWord, flags As FormatFlags) As DWord
    794929    '!接頭辞を取得する関数へのポインタ。
    795930    Prefix As *Function(x As QWord, flags As FormatFlags) As String
    796     '!必要なバッファの大きさ。
    797     MaxSize As DWord
    798931End Type
    799932
    800933/*!
    801 @brief  整数変換全てを行う関数。これを雛形とし、形式毎の差異はIntegerConvertTraitsで表現する。
     934@brief  整数変換全てを行う関数。
    802935@author Egtra
    803936@date 2007/10/22
     
    807940@param[in] field    フィールド幅。
    808941@param[in] flags    フラグ。
     942@return 変換された文字列
    809943*/
    810944Function FormatIntegerEx(ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags) As String
     945    Dim sb = New System.Text.StringBuilder(32)
     946    FormatIntegerEx(sb, tr, x, d, field, flags)
     947    FormatIntegerEx = sb.ToString
     948End Function
     949
     950/*!
     951@brief  整数変換全てを行う関数。これを雛形とし、形式毎の差異はIntegerConvertTraitsで表現する。
     952@author Egtra
     953@date 2008/03/06
     954@param[in,out] sb 書式化した文字列を追加するバッファ。
     955@param[in] tr   特性情報。
     956@param[in] x    変換元の数値。
     957@param[in] d    精度。ここでは最低限出力する桁数。
     958@param[in] field    フィールド幅。
     959@param[in] flags    フラグ。
     960*/
     961Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags)
    811962    If d = DWORD_MAX Then
    812963        d = 1
     
    817968    End If
    818969
    819     Dim sb = New System.Text.StringBuilder
     970    Dim lastLength = sb.Length
     971
    820972    With sb
    821973        Dim prefixFunc = tr.Prefix
     
    828980        End If
    829981
    830 '       Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar
    831         Dim buf[MaxSizeLO] As StrChar
     982        'バッファの量は最も必要文字数の多くなるUInt64の8進法変換にあわせている
     983        Dim buf[MaxSizeLO] As Char
    832984        Dim convertFunc = tr.Convert
    833985        Dim bufStartPos = convertFunc(buf, x, flags)
    834986
    835         Dim len = (tr.MaxSize - bufStartPos) As Long
     987        Dim len = (MaxSizeLO - bufStartPos) As Long
    836988        If len < 0 Then
    837989            Debug
    838990        End If
    839991        If len < d Then
    840             .Append(&h30 As StrChar, d - len)
    841         End If
    842 
     992            .Append(&h30 As Char, d - len)
     993        End If
    843994        .Append(buf, bufStartPos + 1, len)
    844 
    845         AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen)
     995        AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength)
     996        AdjustAlphabet(sb, flags, lastLength)
    846997    End With
    847     FormatIntegerEx = sb.ToString()
    848    
    849     If (flags And Cap) = 0 Then
    850         FormatIntegerEx = FormatIntegerEx.ToLower()
    851     End If
    852 End Function
    853 Sub FormatIntegerEx(sb As System.Text.StringBuilder, ByRef tr As IntegerConvertTraits, x As QWord, d As DWord, field As DWord, flags As FormatFlags)
    854 
    855     If d = DWORD_MAX Then
    856         d = 1
     998End Sub
     999
     1000/*!
     1001@brief 浮動小数点数変換全てを行う関数。これを雛形とし、実際の変換関数は引数converterで与える。
     1002@author Egtra
     1003@date 2008/03/07
     1004@param[in,out] sb 書式化した文字列を追加するバッファ。
     1005@param[in] converter 変換関数。
     1006@param[in] x 変換元の数値。
     1007@param[in] d 精度。ここでは最低限出力する桁数。
     1008@param[in] field フィールド幅。
     1009@param[in] flags フラグ。
     1010*/
     1011Sub FormatFloatEx(sb As System.Text.StringBuilder, converter As FormatFloatProc, x As Double, precision As DWord, field As DWord, flags As FormatFlags)
     1012    Dim lastLength = sb.Length
     1013    If Math.IsNaN(x) Then
     1014        sb.Append("NAN")
     1015        AdjustAlphabet(sb, flags, lastLength)
     1016    ElseIf Math.IsInf(x) Then
     1017        AppendSign(sb, (GetQWord(VarPtr(x)) >> 63) As Boolean, flags)
     1018        sb.Append("INFINITY")
     1019        AdjustAlphabet(sb, flags, lastLength)
    8571020    Else
    858         '精度が指定されているとき、ゼロフラグは無視される。
    859         '仕様上、左揃えのときも無視されるが、それはAdjustFieldWidthが行ってくれる。
    860         flags And= Not Zero
    861     End If
    862 
    863     Dim lastLength = sb.Length
    864 
    865     With sb
    866         Dim prefixFunc = tr.Prefix
    867         Dim prefix = prefixFunc(x, flags)
    868         sb.Append(prefix)
    869 
    870         Dim prefixLen = 0 As DWord
    871         If String.IsNullOrEmpty(prefix) = False Then
    872             prefixLen = prefix.Length As DWord
    873         End If
    874 
    875 '       Dim buf = GC_malloc_atomic((tr.MaxSize + 1) * SizeOf (StrChar)) As *StrChar
    876         Dim buf[MaxSizeLO] As StrChar
    877         Dim convertFunc = tr.Convert
    878         Dim bufStartPos = convertFunc(buf, x, flags)
    879 
    880         Dim len = (tr.MaxSize - bufStartPos) As Long
    881         If len < 0 Then
    882             Debug
    883         End If
    884         If len < d Then
    885             .Append(&h30 As StrChar, d - len)
    886         End If
    887 
    888         .Append(buf, bufStartPos + 1, len)
    889 
    890         AdjustFieldWidth(sb, field, flags And (Not (Sign Or Blank)), prefixLen, lastLength)
    891     End With
    892     Dim t = sb.ToString()
    893    
     1021        converter(sb, x, precision, field, flags)
     1022    End If
     1023    AdjustFieldWidth(sb, field, flags, 0, lastLength)
     1024End Sub
     1025
     1026
     1027/*!
     1028@brief 浮動小数点数変換全てを行う関数。
     1029@author Egtra
     1030@date 2008/03/08
     1031@param[in] converter 変換関数。
     1032@param[in] x 変換元の数値。
     1033@param[in] d 精度。ここでは最低限出力する桁数。
     1034@param[in] field フィールド幅。
     1035@param[in] flags フラグ。
     1036@return 変換された文字列。
     1037*/
     1038Function FormatFloatEx(converter As FormatFloatProc, x As Double, precision As DWord, field As DWord, flags As FormatFlags) As String
     1039    Dim sb = New System.Text.StringBuilder
     1040    FormatFloatEx(sb, converter, x, precision, field, flags)
     1041    FormatFloatEx = sb.ToString
     1042End Function
     1043
     1044/*!
     1045@brief  書式化の仕上げとして、Capフラグが指定されていないときに小文字化する作業を行う。
     1046@author Egtra
     1047@date 2008/03/06
     1048@param[in,out] sb 書式化した文字列を格納しているバッファ。
     1049@param[in] flags フラグ。
     1050@param[in] offset 書式変換した部分の開始位置。
     1051*/
     1052Sub AdjustAlphabet(sb As System.Text.StringBuilder, flags As FormatFlags, offset As Long)
    8941053    If (flags And Cap) = 0 Then
    8951054        Dim len = sb.Length
    8961055        Dim i As Long
    897         For i = lastLength To ELM(len)
     1056        For i = offset To ELM(len)
    8981057            sb[i] = CType.ToLower(sb[i])
    8991058        Next
    9001059    End If
    9011060End Sub
    902 
    903 /*!
    904 @brief  QWordの最大値18446744073709551615の文字数 - 1。FormatIntegerLU内で使用。
    905 @author Egtra
    906 @date   2007/09/18
    907 */
    908 Const MaxSizeLU = 19
    9091061
    9101062/*!
     
    9531105*/
    9541106Function FormatString(x As String, d As DWord, field As DWord, flags As FormatFlags) As String
     1107    Imports System
    9551108    Dim sb = New System.Text.StringBuilder(
    956         x, 0, System.Math.Min(x.Length As DWord, d) As Long, field)
     1109        Math.Max(Math.Min(x.Length As DWord, d), field) As Long + 1)
     1110    FormatString(sb, x, d, field, flags)
    9571111    AdjustFieldWidth(sb, field, flags And LeftSide)
    9581112    FormatString = sb.ToString()
    9591113End Function
     1114
     1115/*!
     1116@brief  文字列をprintfの%s相当の変換で書式化する関数。
     1117@author Egtra
     1118@date   2008/03/07
     1119@param[in,out] sb 書式化した文字列を追加するバッファ。
     1120@param[in] x 文字列。
     1121@param[in] d 精度、最大の文字数。
     1122@param[in] field フィールド幅。
     1123@param[in] flags 書式フラグ。
     1124@return 書式化された文字列。
     1125*/
     1126Sub FormatString(sb As System.Text.StringBuilder, x As String, d As DWord, field As DWord, flags As FormatFlags)
     1127    Dim len = sb.Length
     1128    sb.Append(x, 0, System.Math.Min(x.Length As DWord, d) As Long)
     1129    AdjustFieldWidth(sb, field, flags And LeftSide, 0, len)
     1130End Sub
    9601131
    9611132/*!
     
    9691140@return 書式化された文字列。
    9701141*/
    971 Function FormatCharacter(x As StrChar, d As DWord, field As DWord, flags As FormatFlags) As String
    972     Dim sb = New System.Text.StringBuilder(field + 1)
     1142Function FormatCharacter(x As Char, d As DWord, field As DWord, flags As FormatFlags) As String
     1143    Dim sb = New System.Text.StringBuilder(field + 2)
     1144    FormatCharacter(sb, x, d, field, flags)
     1145    FormatCharacter = sb.ToString()
     1146End Function
     1147
     1148/*!
     1149@brief  文字列をprintfの%s相当の変換で書式化する関数。
     1150@author Egtra
     1151@date   2008/03/07
     1152@param[in,out] sb 書式化した文字列を追加するバッファ。
     1153@param[in] x 文字。
     1154@param[in] d 精度、最大の文字数。
     1155@param[in] field フィールド幅。
     1156@param[in] flags 書式フラグ。
     1157@return 書式化された文字列。
     1158*/
     1159Sub FormatCharacter(sb As System.Text.StringBuilder, x As Char, d As DWord, field As DWord, flags As FormatFlags)
     1160    Dim len = sb.Length
    9731161    sb.Append(x)
    974     AdjustFieldWidth(sb, field, flags And LeftSide)
    975     FormatCharacter = sb.ToString()
    976 End Function
     1162    AdjustFieldWidth(sb, field, flags And LeftSide, 0, len)
     1163End Sub
    9771164
    9781165/*!
     
    9801167@date   2007/10/28
    9811168*/
    982 TypeDef FormatFloatProc = *Function(x As Double, precision As DWord, fieldWidth As DWord, flags As FormatFlags) As String
     1169TypeDef FormatFloatProc = *Sub(sb As System.Text.StringBuilder, x As Double, precision As DWord, fieldWidth As DWord, ByRef flags As FormatFlags)
    9831170
    9841171/*!
     
    9971184        x = param As System.Single
    9981185    End If
    999     s.Append(formatProc(x, precision, field, flags))
     1186    FormatFloatEx(s, formatProc, x, precision, field, flags)
    10001187End Sub
    10011188
     
    10501237        End If
    10511238    End If
    1052 
    1053 '   s.Append(FormatIntegerEx(ByVal traits, x, precision, field, flags))
    10541239    FormatIntegerEx(s, ByVal traits, x, precision, field, flags)
    10551240End Sub
     
    10661251@return 変換して得られた数値。変換できなければ0。
    10671252*/
    1068 Function StrToLong(s As *StrChar, ByRef p As *StrChar) As Long
     1253Function StrToLong(s As *Char, ByRef p As *Char) As Long
    10691254    Dim negative As Boolean
    10701255    Dim i = 0 As Long
     
    10991284そうでなく、fmtに数字(先頭に-符号があっても可)が並んでいれば、それを読み取る。
    11001285*/
    1101 Function ReadInt(ByRef fmt As *StrChar, params As *Object, ByRef paramsCount As SIZE_T, ByRef ret As Long) As Boolean
     1286Function ReadInt(ByRef fmt As *Char, params As *Object, ByRef paramsCount As SIZE_T, ByRef ret As Long) As Boolean
    11021287    If fmt[0] = &h2a Then '*
    11031288        fmt = VarPtr(fmt[1]) 'po
     
    11061291        ReadInt = True
    11071292    Else
    1108         Dim p As *StrChar
     1293        Dim p As *Char
    11091294        ret = StrToLong(fmt, p)
    11101295        If fmt <> p Then
     
    11261311@retval False   読み取り中に文字列が終了した(ヌル文字が現れた)。
    11271312*/
    1128 Function ReadFlags(ByRef fmt As *StrChar, ByRef flags As FormatFlags) As Boolean
     1313Function ReadFlags(ByRef fmt As *Char, ByRef flags As FormatFlags) As Boolean
    11291314    ReadFlags = False
    11301315    Do
     
    11621347@param[in, out] flags
    11631348*/
    1164 Sub ReadFieldWidth(ByRef fmt As *StrChar, params As *Object, ByRef paramsCount As SIZE_T,
     1349Sub ReadFieldWidth(ByRef fmt As *Char, params As *Object, ByRef paramsCount As SIZE_T,
    11651350    ByRef fieldWidth As DWord, ByRef flags As FormatFlags)
    11661351    Dim t As Long
     
    11861371@return 読み取った精度。指定がなかったときには、DWORD_MAX。
    11871372*/
    1188 Function ReadPrecision(ByRef fmt As *StrChar,
     1373Function ReadPrecision(ByRef fmt As *Char,
    11891374    params As *Object, ByRef paramsCount As SIZE_T) As DWord
    11901375
     
    12161401@param[out] lengthSpec
    12171402*/
    1218 Sub ReadLength(ByRef fmt As *StrChar, ByRef lengthSpec As Long)
     1403Sub ReadLength(ByRef fmt As *Char, ByRef lengthSpec As Long)
    12191404    Do
    12201405        Select Case fmt[0]
     
    12401425
    12411426/*!
     1427@brief efg変換用に、精度が指定されていないときに既定の精度を設定する。
     1428@auther Egtra
     1429@date 2008/03/07
     1430*/
     1431Sub AdjustPrecision(ByRef precision As DWord)
     1432    If precision = DWORD_MAX Then
     1433        precision = 6
     1434    End If
     1435End Sub
     1436
     1437/*!
    12421438@biref  Cのsprintfのような書式文字列出力関数
    12431439@author Egtra
     
    12551451    Dim s = New System.Text.StringBuilder
    12561452    Do
    1257         Dim last = format.Length - (((fmt - StrPtr(format)) \ SizeOf (StrChar)) As LONG_PTR) As Long 'po
    1258         Dim pos = ActiveBasic.Strings.ChrFind(fmt, last, &h25 As StrChar) As Long '&h25 = %
     1453        Dim last = format.Length - (((fmt - StrPtr(format)) \ SizeOf (Char)) As LONG_PTR) As Long 'po
     1454        Dim pos = ChrFind(fmt, last, &h25 As Char) As Long '&h25 = %
    12591455        If pos = -1 Then
    12601456            s.Append(fmt, 0, last)
     
    12851481            Case &h75 'u
    12861482                FormatInteger(s, TraitsIntegerU, params[i], False, typeWidth, precision, fieldWidth, flags)
     1483            Case &h4f 'O
     1484                flags Or= Cap
     1485                Goto *O
    12871486            Case &h6f 'o
     1487            *O
    12881488                FormatInteger(s, TraitsIntegerO, params[i], False, typeWidth, precision, fieldWidth, flags)
    1289             Case &h4f 'O
    1290                 FormatInteger(s, TraitsIntegerO, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap)
     1489            Case &h58 'X
     1490                flags Or= Cap
     1491                Goto *X
    12911492            Case &h78 'x
     1493            *X
    12921494                FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags)
    1293             Case &h58 'X
    1294                 FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap)
    12951495'現状ではVoidPtrを引数にする手段は無いはず
    12961496'           Case &h58 'p
    12971497'               FormatInteger(s, TraitsIntegerX, params[i], False, typeWidth, precision, fieldWidth, flags Or Cap)
     1498            Case &h45 'E
     1499                flags Or= Cap
     1500                Goto *E
    12981501            Case &h65 'e
    1299                 FormatFloat(s, AddressOf(FormatFloatE), params[i], precision, fieldWidth, flags)
    1300             Case &h45 'E
    1301                 FormatFloat(s, AddressOf(FormatFloatE), params[i], precision, fieldWidth, flags Or Cap)
     1502            *E
     1503                AdjustPrecision(precision)
     1504                FormatFloat(s, AddressOf(FormatFloatE_Convert), params[i], precision, fieldWidth, flags)
     1505            Case &h46 'F
     1506                flags Or= Cap
     1507                Goto *F
    13021508            Case &h66 'f
    1303                 FormatFloat(s, AddressOf(FormatFloatF), params[i], precision, fieldWidth, flags)
    1304             Case &h46 'F
    1305                 FormatFloat(s, AddressOf(FormatFloatF), params[i], precision, fieldWidth, flags Or Cap)
     1509            *F
     1510                AdjustPrecision(precision)
     1511                FormatFloat(s, AddressOf(FormatFloatF_Convert), params[i], precision, fieldWidth, flags)
     1512            Case &h47 'G
     1513                flags Or= Cap
     1514                Goto *G
    13061515            Case &h67 'g
    1307                 FormatFloat(s, AddressOf(FormatFloatG), params[i], precision, fieldWidth, flags)
    1308             Case &h47 'G
    1309                 FormatFloat(s, AddressOf(FormatFloatG), params[i], precision, fieldWidth, flags Or Cap)
     1516            *G
     1517                AdjustPrecision(precision)
     1518                FormatFloat(s, AddressOf(FormatFloatG_Convert), params[i], precision, fieldWidth, flags)
     1519            Case &h41 'A
     1520                flags Or= Cap
     1521                Goto *A
    13101522            Case &h61 'a
     1523            *A
    13111524                FormatFloat(s, AddressOf(FormatFloatA), params[i], precision, fieldWidth, flags)
    1312             Case &h41 'A
    1313                 FormatFloat(s, AddressOf(FormatFloatA), params[i], precision, fieldWidth, flags Or Cap)
    13141525            Case &h73 's
    1315                 s.Append(FormatString(params[i] As String, precision, fieldWidth, flags))
     1526                FormatString(s, params[i] As String, precision, fieldWidth, flags)
    13161527            Case &h63 'c
    1317                 s.Append(FormatCharacter(params[i] As BoxedStrChar, precision, fieldWidth, flags))
     1528                FormatCharacter(s, params[i] As BoxedStrChar, precision, fieldWidth, flags)
    13181529'           Case &h6e 'n
    13191530            Case &h25 '%
    1320                 s.Append(&h25 As StrChar)
     1531                s.Append(&h25 As Char)
    13211532                i--
    13221533            Case 0
  • trunk/Include/Classes/System/IO/DirectoryInfo.ab

    r409 r468  
    5959            Select Case error
    6060                Case ERROR_ALREADY_EXISTS
    61                     Throw New IOException("DirectoryInfo.CreateDirectory: The directory has already existed.")
     61                    Exit Sub 'ディレクトリが既に存在するときは、何もしない。
    6262                Case Else
    6363                    Throw New IOException("DirectoryInfo.CreateDirectory: Failed to CreateDirectory")
  • trunk/Include/Classes/System/IO/Path.ab

    r429 r468  
    8888    */
    8989    Static Function GetFullPath(path As String) As String
    90         Return Combine(System.Environment.CurrentDirectory, path)
     90        If IsPathRooted(path) Then
     91            Return path
     92        Else
     93            Return Combine(System.Environment.CurrentDirectory, path)
     94        End If
    9195    End Function
    9296
     
    172176    Static Function GetTempPath() As String
    173177        Dim size = WIN32API_GetTempPath(0, 0)
    174         Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PCTSTR
    175         Dim len = WIN32API_GetTempPath(size, p)
     178        Dim buf = New Text.StringBuilder(size)
     179        buf.Length = size
     180        Dim len = WIN32API_GetTempPath(size, StrPtr(buf))
    176181        If (len > size) or len = 0 Then
    177182            Throw New IOException("Path.GetTempPath: Failed to GetTempPath.")
    178183        Else
    179             Return New String(p, len As Long)
     184            buf.Length = len
     185            Return buf.ToString
    180186        End If
    181187    End Function
     
    209215    Static Const ExtensionSeparatorChar = &H2E As StrChar
    210216    Static Const InvalidPathChars = Ex"\q<>|\0\t" As String
    211     Static Const UniformNamingConventionString = Ex"\\\\" As String
     217    Static Const UniformNamingConventionString = "\\" As String
    212218
    213219    '----------------------------------------------------------------
     
    227233        Dim i As Long
    228234        For i = 0 To ELM(InvalidPathChars.Length)
    229             If path.Contains(InvalidPathChars.Substring(i, 1)) Then
     235            If path.Contains(InvalidPathChars[i]) Then
    230236                Throw New IOException("Path.CheckPath: The path contains invalidPathChars.")
    231237            End If
  • trunk/Include/Classes/System/IO/Stream.ab

    r432 r468  
    77
    88Public 'Protected
    9     Sub Stream():   End Sub
     9    Sub Stream()
     10    End Sub
    1011Public
    1112    Virtual Sub ~Stream()
     
    5455        Dispose(True)
    5556    End Sub
    56     Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long: End Function
    57     Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult): End Sub
     57    Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long
     58    End Function
     59    Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult)
     60    End Sub
    5861    Abstract Sub Flush()
    5962    Abstract Function Read(buffer As *Byte, offset As Long, count As Long) As Long
     
    7275    Abstract Sub SetLength(value As Int64)
    7376    Abstract Sub Write(buffer As *Byte, offset As Long, count As Long)
    74 
    7577    Virtual Sub WriteByte(b As Byte)
    7678        Write(VarPtr(b), 0, 1)
  • trunk/Include/Classes/System/IO/StreamWriter.ab

    r271 r468  
    44   
    55Class StreamWriter
    6     ' TODO: 実装
     6    Inherits TextWriter
     7Public
     8    /*
     9    @date 2008/02/25
     10    @auther Egtra
     11    */
     12    Sub StreamWriter(path As String)
     13        init(New FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None))
     14    End Sub
     15
     16    /*
     17    @date 2008/02/25
     18    @auther Egtra
     19    */
     20    Sub StreamWriter(stream As Stream)
     21        init(stream)
     22    End Sub
     23
     24    Override Sub Write(str As String)
     25        buf.Append(str)
     26        Dim len = buf.Length
     27        If len >= 2048 Then
     28            s.Write(StrPtr(buf) As *Byte, 0, len)
     29            buf.Length = 0
     30        End If
     31    End Sub
     32
     33    Override Sub Write(x As Boolean)
     34        buf.Append(x)
     35    End Sub
     36   
     37    Override Sub Write(x As Char)
     38        buf.Append(x)
     39    End Sub
     40
     41    Override Sub Write(x As Byte)
     42        buf.Append(x)
     43    End Sub
     44#ifdef UNICODE
     45    Override Sub Write(x As SByte)
     46        buf.Append(x)
     47    End Sub
     48#else
     49    Override Sub Write(x As Word)
     50        buf.Append(x)
     51    End Sub
     52#endif
     53    Override Sub Write(x As Integer)
     54        buf.Append(x)
     55    End Sub
     56
     57    Override Sub Write(x As DWord)
     58        buf.Append(x)
     59    End Sub
     60
     61    Override Sub Write(x As Long)
     62        buf.Append(x)
     63    End Sub
     64
     65    Override Sub Write(x As QWord)
     66        buf.Append(x)
     67    End Sub
     68
     69    Override Sub Write(x As Int64)
     70        buf.Append(x)
     71    End Sub
     72
     73    Override Sub Write(x As Single)
     74        buf.Append(x)
     75    End Sub
     76
     77    Override Sub Write(x As Double)
     78        buf.Append(x)
     79    End Sub
     80
     81    Override Sub Write(x As Object)
     82        Write(x.ToString)
     83    End Sub
     84
     85Protected
     86    Override Sub Dispose(disposing As Boolean)
     87        If disposing Then
     88            s.Dispose()
     89        End If
     90    End Sub
     91
     92Private
     93    Sub init(stream As Stream)
     94        s = stream
     95        buf = New System.Text.StringBuilder(4096)
     96    End Sub
     97
     98    buf As Text.StringBuilder
     99    s As System.IO.Stream
    7100End Class
    8101
  • trunk/Include/Classes/System/IO/TextReader.ab

    r457 r468  
    101101
    102102Protected
    103     Abstract Sub Dispose(disposing As Boolean)
     103    Virtual Sub Dispose(disposing As Boolean)
     104    End Sub
    104105
    105106    /*
  • trunk/Include/Classes/System/String.ab

    r457 r468  
    55#require <Classes/ActiveBasic/Strings/Strings.ab>
    66
    7 #ifdef __STRING_IS_NOT_ALWAYS_UNICODE
    8 
    9 #ifndef UNICODE
    107TypeDef StrChar = Char
    11 #define __STRING_IS_NOT_UNICODE
    12 #endif
    13 
    14 #endif
    15 
    16 #ifndef __STRING_IS_NOT_UNICODE
    17 TypeDef StrChar = WCHAR
    188
    199#ifdef UNICODE
    2010#define __STRING_IS_UNICODE
    2111#else
    22 #define __STRING_UNICODE_WINDOWS_ANSI
     12#define __STRING_IS_NOT_UNICODE
    2313#endif
    24 #endif
    2514
    2615Namespace System
    2716
    2817    Class String
    29         Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable<StrChar>, IEquatable<String>*/
     18        Implements /*IComparable, ICloneable, IConvertible, IComparable<String>, IEnumerable, IEnumerable<Char>, IEquatable<String>*/
    3019
    3120        m_Length As Long
    32         Chars As *StrChar
     21        Chars As *Char
    3322
    3423        Sub validPointerCheck(p As VoidPtr, size = 1 As Long)
     
    8978        End Sub
    9079
    91         Sub String(initChar As StrChar, length As Long)
     80        Sub String(initChar As Char, length As Long)
    9281            AllocStringBuffer(length)
    9382            ActiveBasic.Strings.ChrFill(Chars, length, initChar)
     
    10594        End Function
    10695
    107         Function Operator() As *StrChar
     96        Function Operator() As *Char
    10897            Return Chars
    10998        End Function
    11099
    111         Const Function Operator [] (n As Long) As StrChar
     100        Const Function Operator [] (n As Long) As Char
    112101            rangeCheck(n)
    113102            Return Chars[n]
     
    154143        End Function
    155144
    156         Const Function Operator == (y As *StrChar) As Boolean
     145        Const Function Operator == (y As *Char) As Boolean
    157146            Return Compare(This, y) = 0
    158147        End Function
     
    162151        End Function
    163152
    164         Const Function Operator <> (y As *StrChar) As Boolean
     153        Const Function Operator <> (y As *Char) As Boolean
    165154            Return Compare(This, y) <> 0
    166155        End Function
     
    170159        End Function
    171160
    172         Const Function Operator < (y As *StrChar) As Boolean
     161        Const Function Operator < (y As *Char) As Boolean
    173162            Return Compare(This, y) < 0
    174163        End Function
     
    178167        End Function
    179168
    180         Const Function Operator > (y As *StrChar) As Boolean
     169        Const Function Operator > (y As *Char) As Boolean
    181170            Return Compare(This, y) > 0
    182171        End Function
     
    186175        End Function
    187176
    188         Const Function Operator <= (y As *StrChar) As Boolean
     177        Const Function Operator <= (y As *Char) As Boolean
    189178            Return Compare(This, y) <= 0
    190179        End Function
     
    194183        End Function
    195184
    196         Const Function Operator >= (y As *StrChar) As Boolean
     185        Const Function Operator >= (y As *Char) As Boolean
    197186            Return Compare(This, y) >= 0
    198187        End Function
     
    217206        End Function
    218207    Private
    219         Static Function Compare(x As String, y As *StrChar) As Long
     208        Static Function Compare(x As String, y As *Char) As Long
    220209            Return CompareOrdinal(x, y)
    221210        End Function
    222211
    223         Static Function CompareOrdinal(x As String, y As *StrChar) As Long
     212        Static Function CompareOrdinal(x As String, y As *Char) As Long
    224213            Return CompareOrdinal(StrPtr(x), y)
    225214        End Function
    226215
    227         Static Function CompareOrdinal(x As *StrChar, y As *StrChar) As Long
     216        Static Function CompareOrdinal(x As *Char, y As *Char) As Long
    228217            If x = 0 Then
    229218                If y = 0 Then
     
    238227        End Function
    239228
    240         Static Function CompareOrdinal(x As *StrChar, indexX As Long, y As *StrChar, indexY As Long, length As Long) As Long
     229        Static Function CompareOrdinal(x As *Char, indexX As Long, y As *Char, indexY As Long, length As Long) As Long
    241230            If x = 0 Then
    242231                If y = 0 Then
     
    273262        End Function
    274263
    275         Const Function StrPtr() As *StrChar
     264        Const Function StrPtr() As *Char
    276265            Return Chars
    277266        End Function
     
    280269        Sub Assign(text As PCSTR, textLengthA As Long)
    281270#ifdef __STRING_IS_NOT_UNICODE
    282             AssignFromStrChar(text, textLengthA)
     271            AssignFromCharPtr(text, textLengthA)
    283272#else
    284273            Dim textLengthW = MultiByteToWideChar(CP_THREAD_ACP, 0, text, textLengthA, 0, 0)
     
    298287            End If
    299288#else
    300             AssignFromStrChar(text, textLengthW)
     289            AssignFromCharPtr(text, textLengthW)
    301290#endif
    302291        End Sub
    303292
    304293    Private
    305         Static Function ConcatStrChar(text1 As *StrChar, text1Length As Long, text2 As *StrChar, text2Length As Long) As String
    306             ConcatStrChar = New String()
    307             With ConcatStrChar
     294        Static Function ConcatChar(text1 As *Char, text1Length As Long, text2 As *Char, text2Length As Long) As String
     295            ConcatChar = New String()
     296            With ConcatChar
    308297                .AllocStringBuffer(text1Length + text2Length)
    309298                ActiveBasic.Strings.ChrCopy(.Chars, text1, text1Length As SIZE_T)
     
    315304        Const Function Concat(text As PCSTR, len As Long) As String
    316305#ifdef __STRING_IS_NOT_UNICODE
    317             Return ConcatStrChar(This.Chars, m_Length, text, len)
     306            Return ConcatChar(This.Chars, m_Length, text, len)
    318307#else
    319308            With Concat
     
    339328            End With
    340329#else
    341             Return ConcatStrChar(This.Chars, m_Length, text, len)
     330            Return ConcatChar(This.Chars, m_Length, text, len)
    342331#endif
    343332        End Function
     
    375364        End Function
    376365
    377         Const Function Contains(c As StrChar) As Boolean
     366        Const Function Contains(c As Char) As Boolean
    378367            Return IndexOf(c) >= 0
    379368        End Function
     
    389378        End Function
    390379
    391         Const Function IndexOf(c As StrChar) As Long
     380        Const Function IndexOf(c As Char) As Long
    392381            Return indexOfCore(c, 0, m_Length)
    393382        End Function
    394383
    395         Const Function IndexOf(c As StrChar, start As Long) As Long
     384        Const Function IndexOf(c As Char, start As Long) As Long
    396385            rangeCheck(start)
    397386            Return indexOfCore(c, start, m_Length - start)
    398387        End Function
    399388
    400         Const Function IndexOf(c As StrChar, start As Long, count As Long) As Long
     389        Const Function IndexOf(c As Char, start As Long, count As Long) As Long
    401390            rangeCheck(start, count)
    402391            Return indexOfCore(c, start, count)
    403392        End Function
    404393    Private
    405         Const Function indexOfCore(c As StrChar, start As Long, count As Long) As Long
     394        Const Function indexOfCore(c As Char, start As Long, count As Long) As Long
    406395            indexOfCore = ActiveBasic.Strings.ChrFind(VarPtr(Chars[start]), count, c) As Long
    407396            If indexOfCore <> -1 Then
     
    440429        End Function
    441430
    442         Const Function LastIndexOf(c As StrChar) As Long
     431        Const Function LastIndexOf(c As Char) As Long
    443432            Return lastIndexOf(c, m_Length - 1, m_Length)
    444433        End Function
    445434
    446         Const Function LastIndexOf(c As StrChar, start As Long) As Long
     435        Const Function LastIndexOf(c As Char, start As Long) As Long
    447436            rangeCheck(start)
    448437            Return lastIndexOf(c, start, start + 1)
    449438        End Function
    450439
    451         Const Function LastIndexOf(c As StrChar, start As Long, count As Long) As Long
     440        Const Function LastIndexOf(c As Char, start As Long, count As Long) As Long
    452441            rangeCheck(start)
    453442            Dim lastFindPos = start - (count - 1)
     
    458447        End Function
    459448    Private
    460         Const Function lastIndexOf(c As StrChar, start As Long, count As Long) As Long
     449        Const Function lastIndexOf(c As Char, start As Long, count As Long) As Long
    461450            Dim lastFindPos = start - (count - 1)
    462451            Dim i As Long
     
    504493        End Function
    505494
    506         Const Function StartsWith(c As StrChar) As Boolean
     495        Const Function StartsWith(c As Char) As Boolean
    507496            Return IndexOf(c) = 0
    508497        End Function
     
    512501        End Function
    513502
    514         Const Function EndsWith(c As StrChar) As Boolean
     503        Const Function EndsWith(c As Char) As Boolean
    515504            Return LastIndexOf(c) = m_Length - 1
    516505        End Function
     
    556545        End Function
    557546
    558         Const Function Replace(oldChar As StrChar, newChar As StrChar) As String
     547        Const Function Replace(oldChar As Char, newChar As Char) As String
    559548            Dim sb = New Text.StringBuilder(This)
    560549            sb.Replace(oldChar, newChar)
     
    604593        End Function
    605594
    606         Sub CopyTo(sourceIndex As Long, destination As *StrChar, destinationIndex As Long, count As Long)
     595        Sub CopyTo(sourceIndex As Long, destination As *Char, destinationIndex As Long, count As Long)
    607596            ActiveBasic.Strings.ChrCopy(VarPtr(destination[destinationIndex]), VarPtr(Chars[sourceIndex]), count As SIZE_T)
    608597        End Sub
     
    618607
    619608        Function PadLeft(total As Long) As String
    620             PadLeft(total, &h30 As StrChar)
    621         End Function
    622 
    623         Function PadLeft(total As Long, c As StrChar) As String
     609            PadLeft(total, &h30 As Char)
     610        End Function
     611
     612        Function PadLeft(total As Long, c As Char) As String
    624613            If total < 0 Then
    625614                Throw New ArgumentOutOfRangeException("String.PadLeft: An arguments is out of range value.", "total")
     
    635624
    636625        Function PadRight(total As Long) As String
    637             PadRight(total, &h30 As StrChar)
    638         End Function
    639 
    640         Function PadRight(total As Long, c As StrChar) As String
     626            PadRight(total, &h30 As Char)
     627        End Function
     628
     629        Function PadRight(total As Long, c As Char) As String
    641630            If total < 0 Then
    642631                Throw New ArgumentOutOfRangeException("String.PadRight: An arguments is out of range value.", "total")
     
    651640        End Function
    652641    Private
    653         Function AllocStringBuffer(textLength As Long) As *StrChar
     642        Function AllocStringBuffer(textLength As Long) As *Char
    654643            If textLength < 0 Then
    655644                Return 0
    656645            End If
    657             AllocStringBuffer = GC_malloc_atomic(SizeOf(StrChar) * (textLength + 1))
     646            AllocStringBuffer = GC_malloc_atomic(SizeOf(Char) * (textLength + 1))
    658647            If AllocStringBuffer = 0 Then
    659648                'Throw New OutOfMemoryException
     
    663652        End Function
    664653
    665         Sub AssignFromStrChar(text As *StrChar, textLength As Long)
     654        Sub AssignFromCharPtr(text As *Char, textLength As Long)
    666655            AllocStringBuffer(textLength)
    667656            ActiveBasic.Strings.ChrCopy(Chars, text, textLength As SIZE_T)
  • trunk/Include/Classes/System/Text/StringBuilder.ab

    r457 r468  
    4040    End Function
    4141
    42     Function Append(x As StrChar) As StringBuilder
     42    Function Append(x As Char) As StringBuilder
    4343        EnsureCapacity(size + 1)
    4444        separateBuffer()
     
    4747        Return This
    4848    End Function
    49 
    50 #ifdef __STRING_IS_NOT_UNICODE
     49#ifdef UNICODE
     50    Function Append(x As SByte) As StringBuilder
     51        ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0)
     52        Return This
     53    End Function
     54#endif
     55    Function Append(x As Byte) As StringBuilder
     56        ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0)
     57        Return This
     58    End Function
     59
     60    Function Append(x As Integer) As StringBuilder
     61        ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0)
     62        Return This
     63    End Function
     64#ifndef UNICODE
    5165    Function Append(x As Word) As StringBuilder
    52         Append(Str$(x As DWord))
    53         Return This
    54     End Function
    55 #else
    56     Function Append(x As SByte) As StringBuilder
    57         Append(Str$(x As Long))
     66        ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0)
    5867        Return This
    5968    End Function
    6069#endif
    61    
    62     Function Append(x As Byte) As StringBuilder
    63         Append(Str$(x As DWord))
    64         Return This
    65     End Function
    66 
    67     Function Append(x As Integer) As StringBuilder
    68         Append(Str$(x As Long))
    69         Return This
    70     End Function
    71 
    7270    Function Append(x As Long) As StringBuilder
    73         Append(Str$(x))
     71        ActiveBasic.Strings.Detail.FormatIntegerD(This, x, DWORD_MAX, 0, 0)
    7472        Return This
    7573    End Function
    7674
    7775    Function Append(x As DWord) As StringBuilder
    78         Append(Str$(x))
     76        ActiveBasic.Strings.Detail.FormatIntegerU(This, x, DWORD_MAX, 0, 0)
    7977        Return This
    8078    End Function
    8179
    8280    Function Append(x As Int64) As StringBuilder
    83         Append(Str$(x))
     81        ActiveBasic.Strings.Detail.FormatIntegerLD(This, x, DWORD_MAX, 0, 0)
    8482        Return This
    8583    End Function
    8684
    8785    Function Append(x As QWord) As StringBuilder
    88         Append(Str$(x))
     86        ActiveBasic.Strings.Detail.FormatIntegerLU(This, x, DWORD_MAX, 0, 0)
    8987        Return This
    9088    End Function
    9189
    9290    Function Append(x As Single) As StringBuilder
    93         Append(Str$(x))
     91        ActiveBasic.Strings.Detail.FormatFloatG(This, x, DWORD_MAX, 0, 0)
    9492        Return This
    9593    End Function
    9694
    9795    Function Append(x As Double) As StringBuilder
    98         Append(Str$(x))
     96        ActiveBasic.Strings.Detail.FormatFloatG(This, x, DWORD_MAX, 0, 0)
    9997        Return This
    10098    End Function
     
    105103    End Function
    106104
    107     Function Append(c As StrChar, n As Long) As StringBuilder
     105    Function Append(c As Char, n As Long) As StringBuilder
    108106        EnsureCapacity(size + n)
    109107        ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), n As SIZE_T, c)
     
    123121    End Function
    124122
    125     Function Append(s As *StrChar, startIndex As Long, count As Long) As StringBuilder
     123    Function Append(s As *Char, startIndex As Long, count As Long) As StringBuilder
    126124        If s = 0 Then
    127125            If startIndex = 0 And count = 0 Then
     
    137135    End Function
    138136Private
    139     Sub appendCore(s As *StrChar, start As Long, count As Long)
     137    Sub appendCore(s As *Char, start As Long, count As Long)
    140138        EnsureCapacity(size + count)
    141139        separateBuffer()
     
    167165    End Function
    168166
    169     Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)
     167    Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As Char, destIndex As Long, count As Long)
    170168        If dest = 0 Then
    171169            Throw New ArgumentNullException("StringBuilder.CopyTo: An argument is null", "sourceIndex")
     
    174172        End If
    175173
    176         memcpy(VarPtr(dest[destIndex]), VarPtr(chars[sourceIndex]), count * SizeOf (StrChar))
     174        memcpy(VarPtr(dest[destIndex]), VarPtr(chars[sourceIndex]), count * SizeOf (Char))
    177175    End Sub
    178176
     
    181179            Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument is out of range value.", "c")
    182180        ElseIf c > Capacity Then
    183             Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar
     181            Dim p = GC_malloc_atomic((c + 1) * SizeOf (Char)) As *Char
    184182            ActiveBasic.Strings.ChrCopy(p, chars, size As SIZE_T)
    185183            chars = p
     
    212210    End Function
    213211
    214     Function Insert(i As Long, x As StrChar) As StringBuilder
     212    Function Insert(i As Long, x As Char) As StringBuilder
    215213        Insert(i, VarPtr(x), 0, 1)
    216214        Return This
     
    303301    End Function
    304302
    305     Function Insert(i As Long, x As *StrChar, index As Long, count As Long) As StringBuilder
     303    Function Insert(i As Long, x As *Char, index As Long, count As Long) As StringBuilder
    306304        rangeCheck(i)
    307305        If x = 0 Then
     
    342340    End Function
    343341
    344     Function Replace(oldChar As StrChar, newChar As StrChar) As StringBuilder
     342    Function Replace(oldChar As Char, newChar As Char) As StringBuilder
    345343        replaceCore(oldChar, newChar, 0, size)
    346344        Return This
     
    352350    End Function
    353351
    354     Function Replace(oldChar As StrChar, newChar As StrChar, startIndex As Long, count As Long) As StringBuilder
     352    Function Replace(oldChar As Char, newChar As Char, startIndex As Long, count As Long) As StringBuilder
    355353        rangeCheck(startIndex, count)
    356354        replaceCore(oldChar, newChar, startIndex, count)
     
    364362    End Function
    365363Private
    366     Sub replaceCore(oldChar As StrChar, newChar As StrChar, start As Long, count As Long)
     364    Sub replaceCore(oldChar As Char, newChar As Char, start As Long, count As Long)
    367365        separateBuffer()
    368366        Dim i As Long
     
    386384        Dim last = start + count
    387385        Do
    388             Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As *StrChar, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T) As Long
     386            Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As *Char, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T) As Long
    389387            If nextPos = -1 As SIZE_T Or curPos > last Then
    390388                s.appendCore(chars, curPos, size - curPos)
     
    411409    End Function
    412410
    413     Const Function Operator [](i As Long) As StrChar
     411    Const Function Operator [](i As Long) As Char
    414412        Return Chars[i]
    415413    End Function
    416414
    417     Sub Operator []=(i As Long, c As StrChar)
     415    Sub Operator []=(i As Long, c As Char)
    418416        Chars[i] = c
    419417    End Sub
     
    431429    End Sub
    432430
    433     Const Function Chars(i As Long) As StrChar
     431    Const Function Chars(i As Long) As Char
    434432        If i >= Length Or i < 0 Then
    435433            Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' is out of range value.")
     
    438436    End Function
    439437
    440     Sub Chars(i As Long, c As StrChar)
     438    Sub Chars(i As Long, c As Char)
    441439        If i >= Length Or i < 0 Then
    442440            Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument is out of range value.", "i")
     
    452450        EnsureCapacity(i) 'iが適切な値かどうかの確認はこの中で行う
    453451        If size < i Then
    454             ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), (i - size + 1) As SIZE_T, 0 As StrChar)
     452            ActiveBasic.Strings.ChrFill(VarPtr(chars[size]), (i - size + 1) As SIZE_T, 0 As Char)
    455453        End If
    456454        size = i
     
    461459    End Function
    462460
    463     Function __Chars() As *StrChar
     461    Function __Chars() As *Char
    464462        Return chars
    465463    End Function
     
    483481        This.maxCapacity = maxCapacity
    484482        This.size = 0
    485         This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf (StrChar))
     483        This.chars = GC_malloc_atomic((This.capacity + 1) * SizeOf (Char))
    486484    End Sub
    487485
     
    516514    Sub separateBuffer()
    517515        If stringized Then
    518             Dim newChars = GC_malloc_atomic(SizeOf (StrChar) * capacity) As *StrChar
     516            Dim newChars = GC_malloc_atomic(SizeOf (Char) * capacity) As *Char
    519517            ActiveBasic.Strings.ChrCopy(newChars, chars, capacity As SIZE_T)
    520518            chars = newChars
     
    523521    End Sub
    524522
    525     chars As *StrChar
     523    chars As *Char
    526524    maxCapacity As Long
    527525    capacity As Long
     
    534532
    535533'暫定
    536 Function StrPtr(sb As System.Text.StringBuilder) As *StrChar
     534Function StrPtr(sb As System.Text.StringBuilder) As *Char
    537535    Return sb.__Chars
    538536End Function
  • trunk/Include/Classes/System/Xml/XmlDocument.ab

    r463 r468  
    136136        Save( fileStream )
    137137    End Sub
     138
     139    /*!
     140    @brief  指定したテキストライタにXML文書を保存する。
     141    @param  テキストライタ。
     142    */
     143    Virtual Sub Save( writer As System.IO.TextWriter )
     144        writer.Write(InnerXmlSupportedIndent( True ))
     145    End Sub
    138146End Class
    139147
  • trunk/Include/Classes/System/misc.ab

    r467 r468  
    11' Classes/System/misc.ab
    2 
    3 #ifndef __SYSTEM_MISC_AB__
    4 #define __SYSTEM_MISC_AB__
    5 
    6 '#require <Classes/System/Threading/WaitHandle.ab>
    72
    83Namespace System
     
    3631End Class
    3732
     33Delegate Sub EventHandler(sender As Object, e As EventArgs)
     34
    3835Delegate Sub AsyncCallback(ar As IAsyncResult)
    3936
    40 
    4137End Namespace 'System
    42 #require <Classes/System/Threading/WaitHandle.ab>
    43 
    44 #endif '__SYSTEM_MISC_AB__
  • trunk/Include/Classes/index.ab

    r461 r468  
    6868#require "./System/IO/Stream.ab"
    6969#require "./System/IO/TextReader.ab"
     70#require "./System/IO/TextWriter.ab"
    7071#require "./System/IO/StreamReader.ab"
    7172#require "./System/IO/StringReader.ab"
  • trunk/Include/basic.sbp

    r400 r468  
    6464TypeDef Char = SByte
    6565#endif
    66 
    67 ' 文字型
    68 #ifdef UNICODE
    69 TypeDef Char = Word
    70 #else
    71 TypeDef Char = SByte
    72 #endif
    73 
    7466
    7567'------------------
  • trunk/TestCase/SimpleTestCase/SPrintFTest.ab

    r385 r468  
    118118    s = FormatFloatG(0.0000123456, 4, 0, None)
    119119    UnitTest("FormatFloatG(0.0000123456, precision = 4) = 1.234e-05", s, "1.234e-05")
     120    s = FormatFloatG(ActiveBasic.Math.Detail.GetNaN(), DWORD_MAX, 0, None)
     121    UnitTest(Ex"FormatFloatG(NaN) = \qnan\q", s, "nan")
     122    s = FormatFloatG(ActiveBasic.Math.Detail.GetInf(False), DWORD_MAX, 0, Sign)
     123    UnitTest(Ex"FormatFloatG(Inf, Sign) = \q+infinity\q", s, "+infinity")
    120124
    121125    s = FormatFloatA(1, DWORD_MAX, 0, None)
     
    127131    s = FormatFloatA(3.1415926535897932384626433832795, DWORD_MAX, 0, None)
    128132    UnitTest("FormatFloatA(π) = 0x1.921fb54442d18p+1", s, "0x1.921fb54442d18p+1")
     133    s = FormatFloatA(3.1415926535897932384626433832795, 4, 0, None)
     134    UnitTest("FormatFloatA(π, precision = 4) = 0x1.921fp+1", s, "0x1.921fp+1")
    129135    s = FormatFloatA(0, DWORD_MAX, 0, None)
    130136    UnitTest("FormatFloatA(0)", s, "0x0p+0")
  • trunk/TestCase/SimpleTestCase/SimpleTestCase.ab

    r465 r468  
    55Dim hStdOut = _System_hConsoleOut
    66
     7Function GetTempDirectory() As String
     8    Return System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp\"
     9'   Return System.IO.Path.GetTempPath()
     10End Function
     11
    712Sub Initialize()
    813    ' 初期化関数
    914
    1015    ' 一時ディレクトリを空にしておく
    11     Dim tempDir = System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp"
     16    Dim tempDir = GetTempDirectory()
    1217    If System.IO.Directory.Exists( tempDir ) Then
    13         ' 存在するときは一旦消す
    14         System.IO.Directory.Delete( tempDir, True )
     18        Try
     19            ' 存在するときは一旦消す
     20            System.IO.Directory.Delete( tempDir, True )
     21        Catch e As System.IO.IOException
     22            OutputDebugString(e.ToString)
     23        End Try
    1524    End If
    1625    System.IO.Directory.CreateDirectory( tempDir )
     
    2433#include "SimpleTestCase.idx"
    2534
     35Dim failureCount = 0 As DWord
     36
    2637Sub UnitTest( msg As String, isSuccessful As Boolean )
    2738    Dim resultStr = Nothing As String
     
    3041    Else
    3142        resultStr = Ex"FAILURE!"
     43        failureCount++
    3244    End If
    3345
     
    4961        SetConsoleTextAttribute(hStdOut, BACKGROUND_RED Or BACKGROUND_GREEN Or BACKGROUND_INTENSITY)
    5062        Print Ex"FAILURE!"; msg
    51         Print "  test string = '" + test + "'"
     63        Print "  期待 = '" + expectation + "'" + " 結果 = '" + test + "'"
    5264        SetConsoleTextAttribute(hStdOut, csbi.wAttributes)
     65        failureCount++
    5366    End If
    5467End Sub
    5568
    5669Function GetExclusiveTempDirPath( testCaseName As String ) As String
    57     Dim tempDir = System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath ) + "\temp"
    58     Dim exclusiveTempDirPath = tempDir + "\" + testCaseName
     70    Dim tempDir = GetTempDirectory()
     71    Dim exclusiveTempDirPath = tempDir + testCaseName
    5972
    6073    If Not System.IO.Directory.Exists( exclusiveTempDirPath ) Then
     
    6679End Function
    6780
     81Print "失敗"; failureCount; "個"
    6882Print "Please Enter key"
    6983System.Console.ReadLine()
  • trunk/TestCase/SimpleTestCase/StringBuilderTest.ab

    r457 r468  
    1818    sb.Replace("こい", "いけ").Replace("いけ", "こい")
    1919    UnitTest("StringBuilder.Replace (String)", sb.ToString, "でてこいでてこいこいのこい")
     20    sb.Length = 0
     21    sb.Append(123)
     22    UnitTest("StringBuilder.Append (Long)", sb.ToString, "123")
    2023End Sub
    2124
     
    2326
    2427StringBuilderTest.TestMain()
    25 
  • trunk/TestCase/SimpleTestCase/XmlTest.ab

    r465 r468  
    1919
    2020    ' 書いて
    21     doc.Save( tempDir + "\test.xml" )
     21    doc.Save( tempDir + "test.xml" )
    2222
    2323    ' 読んで
    2424    Dim clone = New System.Xml.XmlDocument
    25     clone.Load( tempDir + "\test.xml" )
     25    clone.Load( tempDir + "test.xml" )
    2626
    2727    ' 比較してみる
Note: See TracChangeset for help on using the changeset viewer.