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で取得する版を追加(コメントアウト)。

File:
1 edited

Legend:

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