Changeset 30


Ignore:
Timestamp:
Dec 12, 2006, 8:32:18 PM (18 years ago)
Author:
OverTaker
Message:

Chars,Lengthをprivateメンバに変更

File:
1 edited

Legend:

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

    r1 r30  
    11Class String
     2    m_Chars As LPSTR
     3    m_Length As Long
    24Public
    3     Chars As LPSTR
    4     Length As Long
    55
    66    Sub String()
    7         Chars = _System_calloc(1)
    8         Length = 0
     7        m_Chars = _System_calloc(1)
     8        m_Length = 0
    99    End Sub
    1010
     
    1313        Assign(initStr)
    1414    End Sub
    15 /*
    16     Sub String(ByRef initStr As String)
     15
     16/*  Sub String(ByRef initStr As String)
    1717        String()
    1818        Assign(initStr)
     
    2929
    3030    Sub ~String()
    31         _System_free(Chars)
    32         Chars = 0
     31        _System_free(m_Chars)
     32        m_Chars = 0
    3333#ifdef _DEBUG
    34         Length = 0
     34        m_Length = 0
    3535#endif
    3636    End Sub
    3737
     38    Function Chars() As LPSTR
     39        Return m_Chars
     40    End Function
     41
     42    Function Length() As Long
     43        Return m_Length
     44    End Function
     45
    3846    Function Operator() As LPSTR
    39         Return Chars
     47        Return m_Chars
    4048    End Function
    4149
    4250    Sub Operator = (ByRef objString As String)
    43         Assign(objString.Chars, objString.Length)
     51        Assign(objString.m_Chars, objString.m_Length)
    4452    End Sub
    4553
     
    4957
    5058    Function Operator[] (n As Long) As Byte
    51         Return Chars[n]
     59        Return m_Chars[n]
    5260    End Function
    5361
    5462    Sub Operator[]= (n As Long, c As Byte)
    55         Chars[n] = c
     63        m_Chars[n] = c
    5664    End Sub
    5765
     
    6169
    6270    Function Operator+ (ByRef objString As String) As String
    63         Return Concat(objString, objString.Length)
     71        Return Concat(objString, objString.m_Length)
    6472    End Function
    6573
     
    165173
    166174    Function StrPtr() As LPSTR
    167         Return Chars
     175        Return m_Chars
    168176    End Function
    169177
    170178    Sub ReSize(allocLength As Long)
    171179        If allocLength < 0 Then Exit Sub
    172         If allocLength > Length Then
     180        If allocLength > m_Length Then
    173181            Dim oldLength As Long
    174             oldLength = Length
     182            oldLength = m_Length
    175183            If AllocStringBuffer(allocLength) <> 0 Then
    176                 ZeroMemory(Chars + oldLength, Length - oldLength + 1)
     184                ZeroMemory(m_Chars + oldLength, m_Length - oldLength + 1)
    177185            End If
    178186        Else
    179             Length = allocLength
    180             Chars[Length] = 0
     187            m_Length = allocLength
     188            m_Chars[m_Length] = 0
    181189        End If
    182190    End Sub
     
    185193        If allocLength < 0 Then
    186194            Exit Sub
    187         ElseIf allocLength > Length Then
     195        ElseIf allocLength > m_Length Then
    188196            Dim oldLength As Long
    189             oldLength = Length
     197            oldLength = m_Length
    190198            If AllocStringBuffer(allocLength) <> 0 Then
    191                 FillMemory(Chars + oldLength, Length - oldLength, c)
     199                FillMemory(m_Chars + oldLength, m_Length - oldLength, c)
    192200            End If
    193201        Else
    194             Length = allocLength
    195         End If
    196         Chars[Length] = 0
     202            m_Length = allocLength
     203        End If
     204        m_Chars[m_Length] = 0
    197205    End Sub
    198206
    199207    Sub Assign(lpszText As LPSTR, textLength As Long)
    200         If lpszText = Chars Then Exit Sub
     208        If lpszText = m_Chars Then Exit Sub
    201209        If AllocStringBuffer(textLength) <> 0 Then
    202             memcpy(Chars, lpszText, textLength)
    203             Chars[Length] = 0
     210            memcpy(m_Chars, lpszText, textLength)
     211            m_Chars[m_Length] = 0
    204212        End If     
    205213    End Sub
    206214
    207215    Sub Assign(ByRef objString As String)
    208         Assign(objString.Chars, objString.Length)
     216        Assign(objString.m_Chars, objString.m_Length)
    209217    End Sub
    210218
     
    213221            Assign(lpszText, lstrlen(lpszText))
    214222        Else
    215             'Chars=_System_realloc(Chars,1)
    216             Chars[0] = 0
    217             Length = 0
     223            'm_Chars=_System_realloc(m_Chars,1)
     224            m_Chars[0] = 0
     225            m_Length = 0
    218226        End If
    219227    End Sub
     
    221229    Sub Append(lpszText As LPSTR, textLength As Long)
    222230        Dim prevLen As Long
    223         prevLen = Length
    224         If AllocStringBuffer(Length + textLength) <> 0 Then
    225             memcpy(Chars + prevLen, lpszText, textLength)
    226             Chars[Length] = 0
     231        prevLen = m_Length
     232        If AllocStringBuffer(m_Length + textLength) <> 0 Then
     233            memcpy(m_Chars + prevLen, lpszText, textLength)
     234            m_Chars[m_Length] = 0
    227235        End If
    228236    End Sub
     
    233241
    234242    Sub Append(ByRef str As String)
    235         Append(str.Chars, str.Length)
     243        Append(str.m_Chars, str.m_Length)
    236244    End Sub
    237245
     
    239247        Dim tempString As String
    240248        With tempString
    241             .AllocStringBuffer(This.Length + textLength)
    242             memcpy(.Chars, This.Chars, This.Length)
    243             memcpy(.Chars + This.Length, lpszText, textLength)
    244             .Chars[.Length] = 0
     249            .AllocStringBuffer(This.m_Length + textLength)
     250            memcpy(.m_Chars, This.m_Chars, This.m_Length)
     251            memcpy(.m_Chars + This.m_Length, lpszText, textLength)
     252            .m_Chars[.m_Length] = 0
    245253        End With
    246254        Return tempString
     
    248256
    249257    Function Contains(ByRef objString As String) As BOOL
    250         If IndexOf(objString, 0, Length) >= 0 Then
     258        If IndexOf(objString, 0, m_Length) >= 0 Then
    251259            Return _System_TRUE
    252260        Else
     
    256264
    257265    Function Contains(lpszText As LPSTR) As BOOL
    258         If IndexOf(lpszText, 0, Length) >= 0 Then
     266        If IndexOf(lpszText, 0, m_Length) >= 0 Then
    259267            Return _System_TRUE
    260268        Else
     
    264272
    265273    Function IndexOf(lpszText As LPSTR) As Long
    266         Return IndexOf(lpszText, 0, Length)
     274        Return IndexOf(lpszText, 0, m_Length)
    267275    End Function
    268276
    269277    Function IndexOf(lpszText As LPSTR, startIndex As Long) As Long
    270         Return IndexOf(lpszText, startIndex, Length - startIndex)
     278        Return IndexOf(lpszText, startIndex, m_Length - startIndex)
    271279    End Function
    272280
     
    276284
    277285        If startIndex < 0 Then Return -1
    278         If count < 1 Or count + startIndex > Length Then Return -1
    279         If length > Length Then Return -1
     286        If count < 1 Or count + startIndex > m_Length Then Return -1
     287        If length > m_Length Then Return -1
    280288
    281289        If length = 0 Then Return startIndex
     
    284292        For i = startIndex To startIndex + count - 1
    285293            For j = 0 To length - 1
    286                 If Chars[i + j] = lpszText[j] Then
     294                If m_Chars[i + j] = lpszText[j] Then
    287295                    If j = length - 1 Then Return i
    288296                Else
     
    295303
    296304    Function LastIndexOf(lpszText As LPSTR) As Long
    297         Return LastIndexOf(lpszText, Length - 1, Length)
     305        Return LastIndexOf(lpszText, m_Length - 1, m_Length)
    298306    End Function
    299307
     
    306314        length = lstrlen(lpszText)
    307315
    308         If startIndex < 0 Or startIndex > Length - 1 Then Return -1
     316        If startIndex < 0 Or startIndex > m_Length - 1 Then Return -1
    309317        If count < 1 Or count > startIndex + 2 Then Return -1
    310         If length > Length Then Return -1
     318        If length > m_Length Then Return -1
    311319
    312320        If length = 0 Then Return startIndex
     
    315323        For i = startIndex To  startIndex - count + 1 Step -1
    316324            For j = length - 1 To 0 Step -1
    317                 If Chars[i + j] = lpszText[j] Then
     325                If m_Chars[i + j] = lpszText[j] Then
    318326                    If j = 0 Then Return i
    319327                Else
     
    334342
    335343    Function EndsWith(lpszText As LPSTR) As BOOL
    336         If LastIndexOf(lpszText) = Length - lstrlen(lpszText) Then
     344        If LastIndexOf(lpszText) = m_Length - lstrlen(lpszText) Then
    337345            Return _System_TRUE
    338346        Else
     
    345353        length = lstrlen(lpszText)
    346354
    347         If startIndex < 0 Or startIndex > Length Then Return -1
     355        If startIndex < 0 Or startIndex > m_Length Then Return -1
    348356
    349357        Dim newChars As LPSTR
    350         newChars = _System_malloc(length + Length + 1)
     358        newChars = _System_malloc(length + m_Length + 1)
    351359        If newChars = 0 Then Return -1
    352360
    353         memcpy(newChars, Chars, startIndex)
     361        memcpy(newChars, m_Chars, startIndex)
    354362        memcpy(newChars + startIndex, lpszText, length)
    355         memcpy(newChars + startIndex + length, Chars + startIndex, Length - startIndex + 1)
    356 
    357         _System_free(Chars)
    358         Chars = newChars
    359         Length = length + Length
    360         Return Length
     363        memcpy(newChars + startIndex + length, m_Chars + startIndex, m_Length - startIndex + 1)
     364
     365        _System_free(m_Chars)
     366        m_Chars = newChars
     367        m_Length = length + m_Length
     368        Return m_Length
    361369    End Function
    362370
    363371    Function SubString(startIndex As Long) As String
    364         Return SubString(startIndex, Length - startIndex)
     372        Return SubString(startIndex, m_Length - startIndex)
    365373    End Function
    366374
    367375    Function SubString(startIndex As Long, length As Long) As String
    368376        If startIndex < 0 Or length <= 0 Then Return ""
    369         If startIndex + length > Length Then Return ""
     377        If startIndex + length > m_Length Then Return ""
    370378
    371379        Dim temp As String
    372380        temp.AllocStringBuffer(length)
    373         memcpy(temp.Chars, VarPtr(Chars[startIndex]), length)
    374         Chars[Length] = 0
     381        memcpy(temp.m_Chars, VarPtr(m_Chars[startIndex]), length)
     382        m_Chars[m_Length] = 0
    375383        Return temp
    376384    End Function
    377385
    378386    Function Remove(startIndex As Long) As Long
    379         If startIndex < 0 Or startIndex > Length Then Return -1
    380         Chars[startIndex] = 0
    381         Length = startIndex
    382         Return Length
     387        If startIndex < 0 Or startIndex > m_Length Then Return -1
     388        m_Chars[startIndex] = 0
     389        m_Length = startIndex
     390        Return m_Length
    383391    End Function
    384392
    385393    Function Remove(startIndex As Long, count As Long) As Long
    386394        If startIndex < 0 Or count < 0 Then Return -1
    387         If startIndex + count > Length Then Return -1
     395        If startIndex + count > m_Length Then Return -1
    388396
    389397        Dim newChars As LPSTR
    390         newChars = _System_malloc(Length - count + 1)
     398        newChars = _System_malloc(m_Length - count + 1)
    391399        If newChars = 0 Then Return -1
    392400
    393         memcpy(newChars, Chars, startIndex)
    394         memcpy(newChars + startIndex, Chars + startIndex + count, Length - startIndex - count)
    395         newChars[Length - count] = 0
    396 
    397         _System_free(Chars)
    398         Chars = newChars
    399         Length = Length - count
    400         Return Length
     401        memcpy(newChars, m_Chars, startIndex)
     402        memcpy(newChars + startIndex, m_Chars + startIndex + count, m_Length - startIndex - count)
     403        newChars[m_Length - count] = 0
     404
     405        _System_free(m_Chars)
     406        m_Chars = newChars
     407        m_Length = m_Length - count
     408        Return m_Length
    401409    End Function
    402410
    403411    Function IsNullOrEmpty() As BOOL
    404         If Length = 0 Then
     412        If m_Length = 0 Then
    405413            Return _System_TRUE
    406414        Else
     
    411419    Sub Replace(oldChar As Byte, newChar As Byte)
    412420        Dim i As Long
    413         For i = 0 To ELM(Length)
    414             If Chars[i] = oldChar Then
    415                 Chars[i] = newChar
     421        For i = 0 To ELM(m_Length)
     422            If m_Chars[i] = oldChar Then
     423                m_Chars[i] = newChar
    416424            End If
    417425        Next
     
    419427
    420428    Sub Replace(ByRef oldStr As String, ByRef newStr As String)
    421         Replace(oldStr, oldStr.Length, newStr, newStr.Length)
     429        Replace(oldStr, oldStr.m_Length, newStr, newStr.m_Length)
    422430    End Sub
    423431
     
    436444                    Exit Do
    437445                End If
    438                 .Append(Chars + current, pos - current)
     446                .Append(m_Chars + current, pos - current)
    439447                .Append(newStr, newLen)
    440448                current = pos + oldLen
    441449            Loop
    442             .Append(Chars + current, Length - current)
     450            .Append(m_Chars + current, m_Length - current)
    443451        End With
    444452        Swap(tempString)
     
    446454
    447455    Sub ToLower()
    448         CharLower(Chars)
     456        CharLower(m_Chars)
    449457    End Sub
    450458
    451459    Sub ToUpper()
    452         CharUpper(Chars)
     460        CharUpper(m_Chars)
    453461    End Sub
    454462
     
    456464        Dim tempLen As Long
    457465        Dim tempChars As PSTR
    458         tempLen = x.Length
    459         tempChars = x.Chars
    460         x.Length = This.Length
    461         x.Chars = This.Chars
    462         This.Length = tempLen
    463         This.Chars = tempChars
     466        tempLen = x.m_Length
     467        tempChars = x.m_Chars
     468        x.m_Length = This.m_Length
     469        x.m_Chars = This.m_Chars
     470        This.m_Length = tempLen
     471        This.m_Chars = tempChars
    464472    End Sub
    465473
     
    469477        If textLength < 0 Then
    470478            Return 0
    471         ElseIf textLength > Length Then
    472             AllocStringBuffer = _System_realloc(Chars, textLength + 1)
     479        ElseIf textLength > m_Length Then
     480            AllocStringBuffer = _System_realloc(m_Chars, textLength + 1)
    473481            If AllocStringBuffer <> 0 Then
    474                 Length = textLength
    475                 Chars = AllocStringBuffer
     482                m_Length = textLength
     483                m_Chars = AllocStringBuffer
    476484            End If
    477485        Else
    478             Length = textLength
    479             AllocStringBuffer = Chars
     486            m_Length = textLength
     487            AllocStringBuffer = m_Chars
    480488        End If
    481489    End Function
Note: See TracChangeset for help on using the changeset viewer.