Changeset 531 for trunk


Ignore:
Timestamp:
Jun 29, 2008, 11:42:27 AM (16 years ago)
Author:
OverTaker
Message:

String.Split,Joinメソッド実装

Location:
trunk/ab5.0/ablib/src/Classes/System
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Collections/Generic/List.ab

    r526 r531  
    162162    */
    163163    Override Function ToString() As String
    164         Dim object As Object
    165         Dim s As String
    166         Foreach object In This
    167             s += object.ToString() + Ex"\r\n"
     164        Dim string As String
     165        Dim i As Long
     166        For i = 0 To This.Count-2
     167            string += This[i].ToString() + Ex"\r\n"
    168168        Next
    169         Return s
     169        Return string + This[i].ToString()
    170170    End Function
    171171
  • trunk/ab5.0/ablib/src/Classes/System/IO/Directory.ab

    r431 r531  
    185185    @return ファイルやディレクトリのパス文字列が列挙された配列
    186186    */
    187     Static Function GetFileSystemEnties(path As String) As List<String>
    188         Return GetFileSystemEnties(path, "?*")
     187    Static Function GetFileSystemEntries(path As String) As List<String>
     188        Return GetFileSystemEntries(path, "?*")
    189189    End Function
    190190
     
    195195    @return ファイルやディレクトリのパス文字列が列挙された配列
    196196    */
    197     Static Function GetFileSystemEnties(path As String, searchPattern As String) As List<String>
     197    Static Function GetFileSystemEntries(path As String, searchPattern As String) As List<String>
    198198        Dim info = New DirectoryInfo(path)
    199199        Dim infos = info.GetFileSystemInfos(searchPattern) As List<FileSystemInfo>
  • trunk/ab5.0/ablib/src/Classes/System/String.ab

    r497 r531  
    547547        End Function
    548548
     549        Function Split(separator As System.Collections.Generic.List<String>) As System.Collections.Generic.List<String>
     550            Return Split(separator, -1, StringSplitOptions.None)
     551        End Function
     552
     553        Function Split(separator As System.Collections.Generic.List<String>, options As StringSplitOptions) As System.Collections.Generic.List<String>
     554            Return Split(separator, -1, options)
     555        End Function
     556
     557        Function Split(separator As System.Collections.Generic.List<String>, count As Long, options As StringSplitOptions) As System.Collections.Generic.List<String>
     558            Dim split As System.Collections.Generic.List<String>
     559            Dim index As Long, t1Index As Long, t2Index As Long
     560            Dim s As String, substring As String
     561            Dim flag As Boolean
     562
     563            Do
     564                t1Index = Length
     565                flag = True
     566                Foreach s In separator
     567                    t2Index = IndexOf(s, index)
     568                    If t2Index > -1 Then
     569                        t1Index = Math.Min(t1Index, t2Index)
     570                        flag = False
     571                    End If
     572                Next
     573
     574                substring = Substring(index, t1Index - index)
     575                If Not ( IsNullOrEmpty(substring) and (options = StringSplitOptions.RemoveEmptyEntries) ) Then
     576                    split.Add(substring)
     577                End If
     578
     579                If flag Then Return split
     580                If split.Count = count Then Return split
     581               
     582                index = t1Index + 1
     583            Loop
     584        End Function
     585
     586        Static Function Join(separator As String, strings As System.Collections.Generic.List<String>) As String
     587            Return Join(separator, strings, 0, strings.Count)
     588        End Function
     589
     590        Static Function Join(separator As String, strings As System.Collections.Generic.List<String>, startIndex As Long, count As Long) As String
     591            If (startIndex+count > strings.Count) or (startIndex < 0) or (count < 1) Then
     592                Throw New ArgumentOutOfRangeException("String.Join: One or more arguments are out of range value.", "startIndex or count")
     593            End If
     594
     595            Dim string As String
     596            Dim i As Long
     597            For i = startIndex To startIndex + count - 2
     598                string += strings[i] + separator
     599            Next
     600            Return string + strings[i]
     601        End Function
     602
    549603        Const Function ToLower() As String
    550604            Dim sb = New Text.StringBuilder(m_Length)
     
    669723    End Class
    670724
     725    Enum StringSplitOptions
     726        None
     727        RemoveEmptyEntries
     728    End Enum
     729
    671730End Namespace
Note: See TracChangeset for help on using the changeset viewer.