Changeset 121 for Include/Classes


Ignore:
Timestamp:
Feb 25, 2007, 12:56:09 AM (18 years ago)
Author:
イグトランス (egtra)
Message:

#51対応

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/String.ab

    r119 r121  
    55
    66    Sub String()
    7         Chars = _System_calloc(1)
     7        Chars = _System_calloc(SizeOf (Char) * 1)
    88        m_Length = 0
    99    End Sub
     
    1919    End Sub
    2020
    21 /*
    2221    Sub String(length As Long)
     22        String()
    2323        ReSize(length)
    2424    End Sub
    25 */
     25
    2626    Sub String(initChar As Char, length As Long)
    2727        ReSize(length, initChar)
     
    2929
    3030    Sub ~String()
    31         _System_free(Chars)
     31'       _System_free(Chars)
    3232        Chars = 0
    3333#ifdef _DEBUG
     
    3636    End Sub
    3737
    38     Function Length() As Long
     38    Const Function Length() As Long
    3939        Return m_Length
    4040    End Function
     
    5252    End Sub
    5353
    54     Function Operator[] (n As Long) As Char
     54    Const Function Operator[] (n As Long) As Char
    5555        Return Chars[n]
    5656    End Function
     
    6060    End Sub
    6161
    62     Function Operator+ (lpszText As *Char) As String
     62    Const Function Operator + (lpszText As *Char) As String
    6363        Return Concat(lpszText, lstrlen(lpszText))
    6464    End Function
    6565
    66     Function Operator+ (ByRef objString As String) As String
     66    Const Function Operator + (ByRef objString As String) As String
    6767        Return Concat(objString, objString.m_Length)
    6868    End Function
    6969
    70     Function Operator& (lpszText As *Char) As String
    71         Dim tempString As String
    72         tempString=This+lpszText
     70    Const Function Operator & (lpszText As *Char) As String
     71        Dim tempString = This + lpszText
    7372        Return tempString
    7473    End Function
    7574
    76     Function Operator& (ByRef objString As String) As String
    77         Dim tempString As String
    78         tempString=This+objString
     75    Const Function Operator & (ByRef objString As String) As String
     76        Dim tempString = This + objString
    7977        Return tempString
    8078    End Function
     
    178176            oldLength = m_Length
    179177            If AllocStringBuffer(allocLength) <> 0 Then
    180                 ZeroMemory(Chars + oldLength, m_Length - oldLength + 1)
     178                ZeroMemory(VarPtr(Chars[oldLength]), SizeOf (Char) * (m_Length - oldLength + 1))
    181179            End If
    182180        Else
     
    193191            oldLength = m_Length
    194192            If AllocStringBuffer(allocLength) <> 0 Then
    195                 FillMemory(Chars + oldLength, m_Length - oldLength, c)
     193                Dim p = VarPtr(Chars[oldLength]) As *Char
     194                Dim fillLen = m_Length - oldLength
     195                Dim i As Long
     196                For i = 0 To ELM(fillLen)
     197                    p[i] = c
     198                Next
    196199            End If
    197200        Else
     
    201204    End Sub
    202205
    203     Sub Assign(lpszText As *Char, textLength As Long)
    204         If lpszText = Chars Then Exit Sub
     206    Sub Assign(text As *Char, textLength As Long)
     207        If text = Chars Then Exit Sub
    205208        If AllocStringBuffer(textLength) <> 0 Then
    206             memcpy(Chars, lpszText, textLength)
     209            memcpy(Chars, text, SizeOf (Char) * textLength)
    207210            Chars[m_Length] = 0
    208211        End If     
     
    213216    End Sub
    214217
    215     Sub Assign(lpszText As *Char)
    216         If lpszText Then
    217             Assign(lpszText, lstrlen(lpszText))
     218    Sub Assign(text As *Char)
     219        If text Then
     220            Assign(text, lstrlen(text))
    218221        Else
    219222            'Chars=_System_realloc(Chars,1)
     
    223226    End Sub
    224227
    225     Sub Append(lpszText As *Char, textLength As Long)
     228    Sub Append(text As *Char, textLength As Long)
    226229        Dim prevLen As Long
    227230        prevLen = m_Length
    228231        If AllocStringBuffer(m_Length + textLength) <> 0 Then
    229             memcpy(Chars + prevLen, lpszText, textLength)
     232            memcpy(VarPtr(Chars[prevLen]), text, SizeOf (Char) * textLength)
    230233            Chars[m_Length] = 0
    231234        End If
     
    244247        With tempString
    245248            .AllocStringBuffer(This.m_Length + textLength)
    246             memcpy(.Chars, This.Chars, This.m_Length)
    247             memcpy(.Chars + This.m_Length, lpszText, textLength)
     249            memcpy(.Chars, This.Chars, SizeOf (Char) * This.m_Length)
     250            memcpy(VarPtr(.Chars[This.m_Length]), lpszText, SizeOf (Char) * textLength)
    248251            .Chars[.m_Length] = 0
    249252        End With
     
    345348    End Function
    346349
    347     Function Insert(startIndex As Long, lpszText As *Char) As Long
     350    Function Insert(startIndex As Long, text As *Char) As Long
    348351        Dim length As Long
    349         length = lstrlen(lpszText)
     352        length = lstrlen(text)
    350353
    351354        If startIndex < 0 Or startIndex > m_Length Then Return -1
    352355
    353356        Dim newChars As *Char
    354         newChars = _System_malloc(length + m_Length + 1)
     357        newChars = _System_malloc(SizeOf (Char) * (length + m_Length + 1))
    355358        If newChars = 0 Then Return -1
    356359
    357         memcpy(newChars, Chars, startIndex)
    358         memcpy(newChars + startIndex, lpszText, length)
    359         memcpy(newChars + startIndex + length, Chars + startIndex, m_Length - startIndex + 1)
     360        memcpy(newChars, Chars, SizeOf (Char) * startIndex)
     361        memcpy(VarPtr(newChars[startIndex]), text, SizeOf (Char) * length)
     362        memcpy(VarPtr(newChars[startIndex + length]), VarPtr(Chars[startIndex]), SizeOf (Char) * (m_Length - startIndex + 1))
    360363
    361364        _System_free(Chars)
     
    375378        Dim temp As String
    376379        temp.AllocStringBuffer(length)
    377         memcpy(temp.Chars, VarPtr(Chars[startIndex]), length)
     380        memcpy(temp.Chars, VarPtr(Chars[startIndex]), SizeOf (Char) * length)
    378381        Chars[m_Length] = 0
    379382        Return temp
     
    392395
    393396        Dim newChars As *Char
    394         newChars = _System_malloc(m_Length - count + 1)
     397        newChars = _System_malloc(SizeOf (Char) * (m_Length - count + 1))
    395398        If newChars = 0 Then Return -1
    396399
    397         memcpy(newChars, Chars, startIndex)
    398         memcpy(newChars + startIndex, Chars + startIndex + count, m_Length - startIndex - count)
     400        memcpy(newChars, Chars, SizeOf (Char) * startIndex)
     401        memcpy(VarPtr(newChars[startIndex]), VarPtr(Chars[startIndex + count]), SizeOf (Char) * (m_Length - startIndex - count))
    399402        newChars[m_Length - count] = 0
    400403
     
    479482            Return 0
    480483        ElseIf textLength > m_Length Then
    481             AllocStringBuffer = _System_realloc(Chars, textLength + 1)
     484            AllocStringBuffer = _System_realloc(Chars, SizeOf(Char) * (textLength + 1))
    482485            If AllocStringBuffer <> 0 Then
    483486                m_Length = textLength
Note: See TracChangeset for help on using the changeset viewer.