Ignore:
Timestamp:
Nov 20, 2007, 12:04:07 AM (17 years ago)
Author:
イグトランス (egtra)
Message:

例外クラスの実装。ExceptionTestでSystem.Exceptionを使用するようにした。
StringBuilderでコメント化されていた例外を投げる処理を有効にした(除OutOfMemory)。
Str$の実装にSPrintfなどを使用するようにした。
毎回Object.ReferenceEquals(xxx, Nothing)と打つのが面倒なので、IsNothingを導入。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/Text/StringBuilder.ab

    r383 r385  
    120120
    121121    Function Append(s As String, startIndex As Long, count As Long) As StringBuilder
    122         If s = 0 Then
    123             If startIndex = 0 And count = 0 Then
    124                 Return This
    125             Else
    126                 'Throw ArgumentNullException
    127             End If
    128         End If
    129         StringBuilder.rangeCheck2(s.Length, startIndex, count)
    130         appendCore(s, startIndex, count)
    131         Return This
     122        Return Append(StrPtr(s), startIndex, count)
    132123    End Function
    133124
     
    137128                Return This
    138129            Else
    139                 'Throw ArgumentNullException
     130                Throw New ArgumentNullException("StringBuilder.Append: An argument was null", "s")
    140131            End If
    141132        ElseIf startIndex < 0 Or count < 0 Then
    142             'Throw ArgumentOutOfRangeException
     133            Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "startIndex or count or both")
    143134        End If
    144135        appendCore(s, startIndex, count)
     
    178169    Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long)
    179170        If dest = 0 Then
    180             'Throw ArgumentNullException
     171            Throw New ArgumentNullException("StringBuilder.CopyTo: An argument was null", "sourceIndex")
    181172        ElseIf size < sourceIndex + count Or sourceIndex < 0 Or destIndex < 0 Or count < 0 Then
    182             'Throw ArgumentOutOfRangeException
     173            Throw New ArgumentOutOfRangeException("StringBuilder.CopyTo: One or more arguments have out of range value.", "startIndex or count or both")
    183174        End If
    184175
     
    188179    Function EnsureCapacity(c As Long) As Long
    189180        If c < 0 Or c > MaxCapacity Then
    190             'Throw ArgumentOutOfRangeException
     181            Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument was out of range value.", "c")
    191182        ElseIf c > Capacity Then
    192183            Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar
     
    300291        rangeCheck(index)
    301292        If n < 0 Then
    302             'Throw New ArgumentOutOfRangeException
    303             Debug
     293            Throw New ArgumentOutOfRangeException("StringBuilder.Insert: An argument was out of range value.", "n")
    304294        End If
    305295        Dim len = x.Length
     
    308298        EnsureCapacity(newSize)
    309299        separateBuffer()
    310 
    311         ' TODO: fix me!(定義されていない変数iが使われています)
    312         'ActiveBasic.Strings.ChrMove(VarPtr(chars[i + lenTotal]), VarPtr(chars[i]), (size - index) As SIZE_T)
    313300
    314301        Dim i As Long
     
    320307    End Function
    321308
    322 
    323309    Function Insert(i As Long, x As *StrChar, index As Long, count As Long) As StringBuilder
    324310        rangeCheck(i)
    325311        If x = 0 Then
    326             'Throw New ArgumentNullException
    327             Debug
     312            Throw New ArgumentNullException("StringBuilder.Insert: An argument was null", "x")
    328313        ElseIf index < 0 Or count < 0 Then
    329             'Throw New ArgumentNullException
    330             Debug
     314            Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "index or count or both")
    331315        End If
    332316
     
    396380
    397381    Sub replaceCore(oldStr As String, newStr As String, start As Long, count As Long)
    398         If Object.ReferenceEquals(oldStr, Nothing) Then
    399             'Throw ArgumentNullException
    400             Debug
     382        If ActiveBasic.IsNothing(oldStr) Then
     383            Throw New ArgumentNullException("StringBuilder.Replace: An argument was null", "oldStr")
    401384        ElseIf oldStr.Length = 0 Then
    402             'Throw ArgumentException
    403             Debug
     385            Throw New ArgumentException("StringBuilder.Replace: The argument 'oldStr' is empty string. ", "oldStr")
    404386        End If
    405387
     
    412394            End If
    413395           
    414             s.appendCore(chars, curPos, nextPos)
     396            s.appendCore(chars, curPos, nextPos As Long)
    415397            s.Append(newStr)
    416             curPos += nextPos + oldStr.Length
     398            curPos += nextPos As Long + oldStr.Length
    417399        Loop
    418400        chars = s.chars
     
    446428    Sub Capacity(c As Long)
    447429        If c < size Or c > MaxCapacity Then 'sizeとの比較でcが負の場合も対応
    448             'Throw ArgumentOutOfRangeException
     430            Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument have out of range value.", "c")
    449431        End If
    450432        EnsureCapacity(c)
     
    453435    Const Function Chars(i As Long) As StrChar
    454436        If i >= Length Or i < 0 Then
    455             'Throw IndexOutOfRangeException
    456             Debug
     437            Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' have out of range value.")
    457438        End If
    458439        Return chars[i]
     
    461442    Sub Chars(i As Long, c As StrChar)
    462443        If i >= Length Or i < 0 Then
    463             'Throw ArgumentOutOfRangeException
    464             Debug
     444            Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument have out of range value.", "i")
    465445        End If
    466446        chars[i] = c
     
    494474    Sub initialize(capacity As Long, maxCapacity = LONG_MAX As Long)
    495475        If capacity < 0 Or maxCapacity < 1 Or maxCapacity < capacity Then
    496             'Throw ArgumentOutOfRangeException
     476            Throw New ArgumentOutOfRangeException("StringBuilder constructor: One or more arguments have out of range value.", "capacity or maxCapacity or both")
    497477        End If
    498478
     
    526506    Sub rangeCheck(index As Long)
    527507        If index < 0 Or index > size Then
    528             'Throw ArgumentOutOfRangeException
    529             Debug
     508            Throw New ArgumentOutOfRangeException("StringBuilder: Index argument has out of range value.")
    530509        End If
    531510    End Sub
     
    538517        'length < 0は判定に入っていないことに注意
    539518        If startIndex < 0 Or count < 0 Or startIndex + count > length Then
    540             'Throw ArgumentOutOfRangeException
    541             Debug
     519            Throw New ArgumentOutOfRangeException("StringBuilder: One or more arguments have out of range value.", "startIndex or count or both")
    542520        End If
    543521    End Sub
Note: See TracChangeset for help on using the changeset viewer.