Changeset 121 for Include/Classes
- Timestamp:
- Feb 25, 2007, 12:56:09 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/String.ab
r119 r121 5 5 6 6 Sub String() 7 Chars = _System_calloc( 1)7 Chars = _System_calloc(SizeOf (Char) * 1) 8 8 m_Length = 0 9 9 End Sub … … 19 19 End Sub 20 20 21 /*22 21 Sub String(length As Long) 22 String() 23 23 ReSize(length) 24 24 End Sub 25 */ 25 26 26 Sub String(initChar As Char, length As Long) 27 27 ReSize(length, initChar) … … 29 29 30 30 Sub ~String() 31 _System_free(Chars)31 ' _System_free(Chars) 32 32 Chars = 0 33 33 #ifdef _DEBUG … … 36 36 End Sub 37 37 38 Function Length() As Long38 Const Function Length() As Long 39 39 Return m_Length 40 40 End Function … … 52 52 End Sub 53 53 54 Function Operator[] (n As Long) As Char54 Const Function Operator[] (n As Long) As Char 55 55 Return Chars[n] 56 56 End Function … … 60 60 End Sub 61 61 62 Function Operator+ (lpszText As *Char) As String62 Const Function Operator + (lpszText As *Char) As String 63 63 Return Concat(lpszText, lstrlen(lpszText)) 64 64 End Function 65 65 66 Function Operator+ (ByRef objString As String) As String66 Const Function Operator + (ByRef objString As String) As String 67 67 Return Concat(objString, objString.m_Length) 68 68 End Function 69 69 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 73 72 Return tempString 74 73 End Function 75 74 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 79 77 Return tempString 80 78 End Function … … 178 176 oldLength = m_Length 179 177 If AllocStringBuffer(allocLength) <> 0 Then 180 ZeroMemory( Chars + oldLength, m_Length - oldLength + 1)178 ZeroMemory(VarPtr(Chars[oldLength]), SizeOf (Char) * (m_Length - oldLength + 1)) 181 179 End If 182 180 Else … … 193 191 oldLength = m_Length 194 192 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 196 199 End If 197 200 Else … … 201 204 End Sub 202 205 203 Sub Assign( lpszText As *Char, textLength As Long)204 If lpszText = Chars Then Exit Sub206 Sub Assign(text As *Char, textLength As Long) 207 If text = Chars Then Exit Sub 205 208 If AllocStringBuffer(textLength) <> 0 Then 206 memcpy(Chars, lpszText,textLength)209 memcpy(Chars, text, SizeOf (Char) * textLength) 207 210 Chars[m_Length] = 0 208 211 End If … … 213 216 End Sub 214 217 215 Sub Assign( lpszText As *Char)216 If lpszText Then217 Assign( lpszText, lstrlen(lpszText))218 Sub Assign(text As *Char) 219 If text Then 220 Assign(text, lstrlen(text)) 218 221 Else 219 222 'Chars=_System_realloc(Chars,1) … … 223 226 End Sub 224 227 225 Sub Append( lpszText As *Char, textLength As Long)228 Sub Append(text As *Char, textLength As Long) 226 229 Dim prevLen As Long 227 230 prevLen = m_Length 228 231 If AllocStringBuffer(m_Length + textLength) <> 0 Then 229 memcpy( Chars + prevLen, lpszText,textLength)232 memcpy(VarPtr(Chars[prevLen]), text, SizeOf (Char) * textLength) 230 233 Chars[m_Length] = 0 231 234 End If … … 244 247 With tempString 245 248 .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) 248 251 .Chars[.m_Length] = 0 249 252 End With … … 345 348 End Function 346 349 347 Function Insert(startIndex As Long, lpszText As *Char) As Long350 Function Insert(startIndex As Long, text As *Char) As Long 348 351 Dim length As Long 349 length = lstrlen( lpszText)352 length = lstrlen(text) 350 353 351 354 If startIndex < 0 Or startIndex > m_Length Then Return -1 352 355 353 356 Dim newChars As *Char 354 newChars = _System_malloc( length + m_Length + 1)357 newChars = _System_malloc(SizeOf (Char) * (length + m_Length + 1)) 355 358 If newChars = 0 Then Return -1 356 359 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)) 360 363 361 364 _System_free(Chars) … … 375 378 Dim temp As String 376 379 temp.AllocStringBuffer(length) 377 memcpy(temp.Chars, VarPtr(Chars[startIndex]), length)380 memcpy(temp.Chars, VarPtr(Chars[startIndex]), SizeOf (Char) * length) 378 381 Chars[m_Length] = 0 379 382 Return temp … … 392 395 393 396 Dim newChars As *Char 394 newChars = _System_malloc( m_Length - count + 1)397 newChars = _System_malloc(SizeOf (Char) * (m_Length - count + 1)) 395 398 If newChars = 0 Then Return -1 396 399 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)) 399 402 newChars[m_Length - count] = 0 400 403 … … 479 482 Return 0 480 483 ElseIf textLength > m_Length Then 481 AllocStringBuffer = _System_realloc(Chars, textLength + 1)484 AllocStringBuffer = _System_realloc(Chars, SizeOf(Char) * (textLength + 1)) 482 485 If AllocStringBuffer <> 0 Then 483 486 m_Length = textLength
Note:
See TracChangeset
for help on using the changeset viewer.