Changeset 706


Ignore:
Timestamp:
Jun 28, 2009, 2:23:39 AM (15 years ago)
Author:
イグトランス (egtra)
Message:

String.Joinで引数stringsの配列の要素が0だった場合にもエラーを返さないように修正。また、stringsがNothingのときには例外を投げるように修正。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/String.ab

    r676 r706  
    607607        End Function
    608608
    609         Static Function Join(separator As String, strings As System.Collections.Generic.List<String>) As String
     609        Static Function Join(separator As String, strings As System.Collections.Generic.IList<String>) As String
    610610            Return Join(separator, strings, 0, strings.Count)
    611611        End Function
    612612
    613         Static Function Join(separator As String, strings As System.Collections.Generic.List<String>, startIndex As Long, count As Long) As String
    614             If (startIndex+count > strings.Count) or (startIndex < 0) or (count < 1) Then
     613        Static Function Join(separator As String, strings As System.Collections.Generic.IList<String>, startIndex As Long, count As Long) As String
     614            If ObjPtr(strings) = NULL Then ' IsNothingだとエラーになる
     615                Throw New ArgumentNullException("strings")
     616            ElseIf (startIndex+count > strings.Count) or (startIndex < 0) or (count < 0) Then
    615617                Throw New ArgumentOutOfRangeException("String.Join: One or more arguments are out of range value.", "startIndex or count")
    616618            End If
    617619
    618             Dim string As String
    619             Dim i As Long
    620             For i = startIndex To startIndex + count - 2
    621                 string += strings[i] + separator
    622             Next
    623             Return string + strings[i]
     620            If count = 0 Then
     621                Return ""
     622            Else
     623                Dim string As String
     624                Dim i As Long
     625                For i = startIndex To startIndex + count - 2
     626                    string += strings.Item[i] + separator
     627                Next
     628                Return string + strings.Item[i]
     629            End If
    624630        End Function
    625631
     
    687693            sb.Append(c, total - m_Length)
    688694            sb.Append(This)
    689             Return sb.ToString
     695            Return sb.ToString()
    690696        End Function
    691697
     
    704710            sb.Append(This)
    705711            sb.Append(c, total - m_Length)
    706             Return sb.ToString
     712            Return sb.ToString()
    707713        End Function
    708714    Private
Note: See TracChangeset for help on using the changeset viewer.