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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.