Ignore:
File:
1 edited

Legend:

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

    r30 r1  
    11Class String
    2     m_Chars As LPSTR
    3     m_Length As Long
    42Public
     3    Chars As LPSTR
     4    Length As Long
    55
    66    Sub String()
    7         m_Chars = _System_calloc(1)
    8         m_Length = 0
     7        Chars = _System_calloc(1)
     8        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(m_Chars)
    32         m_Chars = 0
     31        _System_free(Chars)
     32        Chars = 0
    3333#ifdef _DEBUG
    34         m_Length = 0
     34        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 
    4638    Function Operator() As LPSTR
    47         Return m_Chars
     39        Return Chars
    4840    End Function
    4941
    5042    Sub Operator = (ByRef objString As String)
    51         Assign(objString.m_Chars, objString.m_Length)
     43        Assign(objString.Chars, objString.Length)
    5244    End Sub
    5345
     
    5749
    5850    Function Operator[] (n As Long) As Byte
    59         Return m_Chars[n]
     51        Return Chars[n]
    6052    End Function
    6153
    6254    Sub Operator[]= (n As Long, c As Byte)
    63         m_Chars[n] = c
     55        Chars[n] = c
    6456    End Sub
    6557
     
    6961
    7062    Function Operator+ (ByRef objString As String) As String
    71         Return Concat(objString, objString.m_Length)
     63        Return Concat(objString, objString.Length)
    7264    End Function
    7365
     
    173165
    174166    Function StrPtr() As LPSTR
    175         Return m_Chars
     167        Return Chars
    176168    End Function
    177169
    178170    Sub ReSize(allocLength As Long)
    179171        If allocLength < 0 Then Exit Sub
    180         If allocLength > m_Length Then
     172        If allocLength > Length Then
    181173            Dim oldLength As Long
    182             oldLength = m_Length
     174            oldLength = Length
    183175            If AllocStringBuffer(allocLength) <> 0 Then
    184                 ZeroMemory(m_Chars + oldLength, m_Length - oldLength + 1)
     176                ZeroMemory(Chars + oldLength, Length - oldLength + 1)
    185177            End If
    186178        Else
    187             m_Length = allocLength
    188             m_Chars[m_Length] = 0
     179            Length = allocLength
     180            Chars[Length] = 0
    189181        End If
    190182    End Sub
     
    193185        If allocLength < 0 Then
    194186            Exit Sub
    195         ElseIf allocLength > m_Length Then
     187        ElseIf allocLength > Length Then
    196188            Dim oldLength As Long
    197             oldLength = m_Length
     189            oldLength = Length
    198190            If AllocStringBuffer(allocLength) <> 0 Then
    199                 FillMemory(m_Chars + oldLength, m_Length - oldLength, c)
     191                FillMemory(Chars + oldLength, Length - oldLength, c)
    200192            End If
    201193        Else
    202             m_Length = allocLength
    203         End If
    204         m_Chars[m_Length] = 0
     194            Length = allocLength
     195        End If
     196        Chars[Length] = 0
    205197    End Sub
    206198
    207199    Sub Assign(lpszText As LPSTR, textLength As Long)
    208         If lpszText = m_Chars Then Exit Sub
     200        If lpszText = Chars Then Exit Sub
    209201        If AllocStringBuffer(textLength) <> 0 Then
    210             memcpy(m_Chars, lpszText, textLength)
    211             m_Chars[m_Length] = 0
     202            memcpy(Chars, lpszText, textLength)
     203            Chars[Length] = 0
    212204        End If     
    213205    End Sub
    214206
    215207    Sub Assign(ByRef objString As String)
    216         Assign(objString.m_Chars, objString.m_Length)
     208        Assign(objString.Chars, objString.Length)
    217209    End Sub
    218210
     
    221213            Assign(lpszText, lstrlen(lpszText))
    222214        Else
    223             'm_Chars=_System_realloc(m_Chars,1)
    224             m_Chars[0] = 0
    225             m_Length = 0
     215            'Chars=_System_realloc(Chars,1)
     216            Chars[0] = 0
     217            Length = 0
    226218        End If
    227219    End Sub
     
    229221    Sub Append(lpszText As LPSTR, textLength As Long)
    230222        Dim prevLen As Long
    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
     223        prevLen = Length
     224        If AllocStringBuffer(Length + textLength) <> 0 Then
     225            memcpy(Chars + prevLen, lpszText, textLength)
     226            Chars[Length] = 0
    235227        End If
    236228    End Sub
     
    241233
    242234    Sub Append(ByRef str As String)
    243         Append(str.m_Chars, str.m_Length)
     235        Append(str.Chars, str.Length)
    244236    End Sub
    245237
     
    247239        Dim tempString As String
    248240        With tempString
    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
     241            .AllocStringBuffer(This.Length + textLength)
     242            memcpy(.Chars, This.Chars, This.Length)
     243            memcpy(.Chars + This.Length, lpszText, textLength)
     244            .Chars[.Length] = 0
    253245        End With
    254246        Return tempString
     
    256248
    257249    Function Contains(ByRef objString As String) As BOOL
    258         If IndexOf(objString, 0, m_Length) >= 0 Then
     250        If IndexOf(objString, 0, Length) >= 0 Then
    259251            Return _System_TRUE
    260252        Else
     
    264256
    265257    Function Contains(lpszText As LPSTR) As BOOL
    266         If IndexOf(lpszText, 0, m_Length) >= 0 Then
     258        If IndexOf(lpszText, 0, Length) >= 0 Then
    267259            Return _System_TRUE
    268260        Else
     
    272264
    273265    Function IndexOf(lpszText As LPSTR) As Long
    274         Return IndexOf(lpszText, 0, m_Length)
     266        Return IndexOf(lpszText, 0, Length)
    275267    End Function
    276268
    277269    Function IndexOf(lpszText As LPSTR, startIndex As Long) As Long
    278         Return IndexOf(lpszText, startIndex, m_Length - startIndex)
     270        Return IndexOf(lpszText, startIndex, Length - startIndex)
    279271    End Function
    280272
     
    284276
    285277        If startIndex < 0 Then Return -1
    286         If count < 1 Or count + startIndex > m_Length Then Return -1
    287         If length > m_Length Then Return -1
     278        If count < 1 Or count + startIndex > Length Then Return -1
     279        If length > Length Then Return -1
    288280
    289281        If length = 0 Then Return startIndex
     
    292284        For i = startIndex To startIndex + count - 1
    293285            For j = 0 To length - 1
    294                 If m_Chars[i + j] = lpszText[j] Then
     286                If Chars[i + j] = lpszText[j] Then
    295287                    If j = length - 1 Then Return i
    296288                Else
     
    303295
    304296    Function LastIndexOf(lpszText As LPSTR) As Long
    305         Return LastIndexOf(lpszText, m_Length - 1, m_Length)
     297        Return LastIndexOf(lpszText, Length - 1, Length)
    306298    End Function
    307299
     
    314306        length = lstrlen(lpszText)
    315307
    316         If startIndex < 0 Or startIndex > m_Length - 1 Then Return -1
     308        If startIndex < 0 Or startIndex > Length - 1 Then Return -1
    317309        If count < 1 Or count > startIndex + 2 Then Return -1
    318         If length > m_Length Then Return -1
     310        If length > Length Then Return -1
    319311
    320312        If length = 0 Then Return startIndex
     
    323315        For i = startIndex To  startIndex - count + 1 Step -1
    324316            For j = length - 1 To 0 Step -1
    325                 If m_Chars[i + j] = lpszText[j] Then
     317                If Chars[i + j] = lpszText[j] Then
    326318                    If j = 0 Then Return i
    327319                Else
     
    342334
    343335    Function EndsWith(lpszText As LPSTR) As BOOL
    344         If LastIndexOf(lpszText) = m_Length - lstrlen(lpszText) Then
     336        If LastIndexOf(lpszText) = Length - lstrlen(lpszText) Then
    345337            Return _System_TRUE
    346338        Else
     
    353345        length = lstrlen(lpszText)
    354346
    355         If startIndex < 0 Or startIndex > m_Length Then Return -1
     347        If startIndex < 0 Or startIndex > Length Then Return -1
    356348
    357349        Dim newChars As LPSTR
    358         newChars = _System_malloc(length + m_Length + 1)
     350        newChars = _System_malloc(length + Length + 1)
    359351        If newChars = 0 Then Return -1
    360352
    361         memcpy(newChars, m_Chars, startIndex)
     353        memcpy(newChars, Chars, startIndex)
    362354        memcpy(newChars + startIndex, lpszText, 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
     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
    369361    End Function
    370362
    371363    Function SubString(startIndex As Long) As String
    372         Return SubString(startIndex, m_Length - startIndex)
     364        Return SubString(startIndex, Length - startIndex)
    373365    End Function
    374366
    375367    Function SubString(startIndex As Long, length As Long) As String
    376368        If startIndex < 0 Or length <= 0 Then Return ""
    377         If startIndex + length > m_Length Then Return ""
     369        If startIndex + length > Length Then Return ""
    378370
    379371        Dim temp As String
    380372        temp.AllocStringBuffer(length)
    381         memcpy(temp.m_Chars, VarPtr(m_Chars[startIndex]), length)
    382         m_Chars[m_Length] = 0
     373        memcpy(temp.Chars, VarPtr(Chars[startIndex]), length)
     374        Chars[Length] = 0
    383375        Return temp
    384376    End Function
    385377
    386378    Function Remove(startIndex As Long) As Long
    387         If startIndex < 0 Or startIndex > m_Length Then Return -1
    388         m_Chars[startIndex] = 0
    389         m_Length = startIndex
    390         Return m_Length
     379        If startIndex < 0 Or startIndex > Length Then Return -1
     380        Chars[startIndex] = 0
     381        Length = startIndex
     382        Return Length
    391383    End Function
    392384
    393385    Function Remove(startIndex As Long, count As Long) As Long
    394386        If startIndex < 0 Or count < 0 Then Return -1
    395         If startIndex + count > m_Length Then Return -1
     387        If startIndex + count > Length Then Return -1
    396388
    397389        Dim newChars As LPSTR
    398         newChars = _System_malloc(m_Length - count + 1)
     390        newChars = _System_malloc(Length - count + 1)
    399391        If newChars = 0 Then Return -1
    400392
    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
     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
    409401    End Function
    410402
    411403    Function IsNullOrEmpty() As BOOL
    412         If m_Length = 0 Then
     404        If Length = 0 Then
    413405            Return _System_TRUE
    414406        Else
     
    419411    Sub Replace(oldChar As Byte, newChar As Byte)
    420412        Dim i As Long
    421         For i = 0 To ELM(m_Length)
    422             If m_Chars[i] = oldChar Then
    423                 m_Chars[i] = newChar
     413        For i = 0 To ELM(Length)
     414            If Chars[i] = oldChar Then
     415                Chars[i] = newChar
    424416            End If
    425417        Next
     
    427419
    428420    Sub Replace(ByRef oldStr As String, ByRef newStr As String)
    429         Replace(oldStr, oldStr.m_Length, newStr, newStr.m_Length)
     421        Replace(oldStr, oldStr.Length, newStr, newStr.Length)
    430422    End Sub
    431423
     
    444436                    Exit Do
    445437                End If
    446                 .Append(m_Chars + current, pos - current)
     438                .Append(Chars + current, pos - current)
    447439                .Append(newStr, newLen)
    448440                current = pos + oldLen
    449441            Loop
    450             .Append(m_Chars + current, m_Length - current)
     442            .Append(Chars + current, Length - current)
    451443        End With
    452444        Swap(tempString)
     
    454446
    455447    Sub ToLower()
    456         CharLower(m_Chars)
     448        CharLower(Chars)
    457449    End Sub
    458450
    459451    Sub ToUpper()
    460         CharUpper(m_Chars)
     452        CharUpper(Chars)
    461453    End Sub
    462454
     
    464456        Dim tempLen As Long
    465457        Dim tempChars As PSTR
    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
     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
    472464    End Sub
    473465
     
    477469        If textLength < 0 Then
    478470            Return 0
    479         ElseIf textLength > m_Length Then
    480             AllocStringBuffer = _System_realloc(m_Chars, textLength + 1)
     471        ElseIf textLength > Length Then
     472            AllocStringBuffer = _System_realloc(Chars, textLength + 1)
    481473            If AllocStringBuffer <> 0 Then
    482                 m_Length = textLength
    483                 m_Chars = AllocStringBuffer
     474                Length = textLength
     475                Chars = AllocStringBuffer
    484476            End If
    485477        Else
    486             m_Length = textLength
    487             AllocStringBuffer = m_Chars
     478            Length = textLength
     479            AllocStringBuffer = Chars
    488480        End If
    489481    End Function
Note: See TracChangeset for help on using the changeset viewer.