Changeset 31
- Timestamp:
- Dec 12, 2006, 8:41:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/String.ab
r30 r31 1 1 Class String 2 m_Chars As LPSTR3 2 m_Length As Long 4 3 Public 4 Chars As LPSTR 5 5 6 6 Sub String() 7 m_Chars = _System_calloc(1)7 Chars = _System_calloc(1) 8 8 m_Length = 0 9 9 End Sub … … 29 29 30 30 Sub ~String() 31 _System_free( m_Chars)32 m_Chars = 031 _System_free(Chars) 32 Chars = 0 33 33 #ifdef _DEBUG 34 34 m_Length = 0 … … 36 36 End Sub 37 37 38 Function Chars() As LPSTR39 Return m_Chars40 End Function41 42 38 Function Length() As Long 43 39 Return m_Length … … 45 41 46 42 Function Operator() As LPSTR 47 Return m_Chars43 Return Chars 48 44 End Function 49 45 50 46 Sub Operator = (ByRef objString As String) 51 Assign(objString. m_Chars, objString.m_Length)47 Assign(objString.Chars, objString.m_Length) 52 48 End Sub 53 49 … … 57 53 58 54 Function Operator[] (n As Long) As Byte 59 Return m_Chars[n]55 Return Chars[n] 60 56 End Function 61 57 62 58 Sub Operator[]= (n As Long, c As Byte) 63 m_Chars[n] = c59 Chars[n] = c 64 60 End Sub 65 61 … … 173 169 174 170 Function StrPtr() As LPSTR 175 Return m_Chars171 Return Chars 176 172 End Function 177 173 … … 182 178 oldLength = m_Length 183 179 If AllocStringBuffer(allocLength) <> 0 Then 184 ZeroMemory( m_Chars + oldLength, m_Length - oldLength + 1)180 ZeroMemory(Chars + oldLength, m_Length - oldLength + 1) 185 181 End If 186 182 Else 187 183 m_Length = allocLength 188 m_Chars[m_Length] = 0184 Chars[m_Length] = 0 189 185 End If 190 186 End Sub … … 197 193 oldLength = m_Length 198 194 If AllocStringBuffer(allocLength) <> 0 Then 199 FillMemory( m_Chars + oldLength, m_Length - oldLength, c)195 FillMemory(Chars + oldLength, m_Length - oldLength, c) 200 196 End If 201 197 Else 202 198 m_Length = allocLength 203 199 End If 204 m_Chars[m_Length] = 0200 Chars[m_Length] = 0 205 201 End Sub 206 202 207 203 Sub Assign(lpszText As LPSTR, textLength As Long) 208 If lpszText = m_Chars Then Exit Sub204 If lpszText = Chars Then Exit Sub 209 205 If AllocStringBuffer(textLength) <> 0 Then 210 memcpy( m_Chars, lpszText, textLength)211 m_Chars[m_Length] = 0206 memcpy(Chars, lpszText, textLength) 207 Chars[m_Length] = 0 212 208 End If 213 209 End Sub 214 210 215 211 Sub Assign(ByRef objString As String) 216 Assign(objString. m_Chars, objString.m_Length)212 Assign(objString.Chars, objString.m_Length) 217 213 End Sub 218 214 … … 221 217 Assign(lpszText, lstrlen(lpszText)) 222 218 Else 223 ' m_Chars=_System_realloc(m_Chars,1)224 m_Chars[0] = 0219 'Chars=_System_realloc(Chars,1) 220 Chars[0] = 0 225 221 m_Length = 0 226 222 End If … … 231 227 prevLen = m_Length 232 228 If AllocStringBuffer(m_Length + textLength) <> 0 Then 233 memcpy( m_Chars + prevLen, lpszText, textLength)234 m_Chars[m_Length] = 0229 memcpy(Chars + prevLen, lpszText, textLength) 230 Chars[m_Length] = 0 235 231 End If 236 232 End Sub … … 241 237 242 238 Sub Append(ByRef str As String) 243 Append(str. m_Chars, str.m_Length)239 Append(str.Chars, str.m_Length) 244 240 End Sub 245 241 … … 248 244 With tempString 249 245 .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] = 0246 memcpy(.Chars, This.Chars, This.m_Length) 247 memcpy(.Chars + This.m_Length, lpszText, textLength) 248 .Chars[.m_Length] = 0 253 249 End With 254 250 Return tempString … … 292 288 For i = startIndex To startIndex + count - 1 293 289 For j = 0 To length - 1 294 If m_Chars[i + j] = lpszText[j] Then290 If Chars[i + j] = lpszText[j] Then 295 291 If j = length - 1 Then Return i 296 292 Else … … 323 319 For i = startIndex To startIndex - count + 1 Step -1 324 320 For j = length - 1 To 0 Step -1 325 If m_Chars[i + j] = lpszText[j] Then321 If Chars[i + j] = lpszText[j] Then 326 322 If j = 0 Then Return i 327 323 Else … … 359 355 If newChars = 0 Then Return -1 360 356 361 memcpy(newChars, m_Chars, startIndex)357 memcpy(newChars, Chars, startIndex) 362 358 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 = newChars359 memcpy(newChars + startIndex + length, Chars + startIndex, m_Length - startIndex + 1) 360 361 _System_free(Chars) 362 Chars = newChars 367 363 m_Length = length + m_Length 368 364 Return m_Length … … 379 375 Dim temp As String 380 376 temp.AllocStringBuffer(length) 381 memcpy(temp. m_Chars, VarPtr(m_Chars[startIndex]), length)382 m_Chars[m_Length] = 0377 memcpy(temp.Chars, VarPtr(Chars[startIndex]), length) 378 Chars[m_Length] = 0 383 379 Return temp 384 380 End Function … … 386 382 Function Remove(startIndex As Long) As Long 387 383 If startIndex < 0 Or startIndex > m_Length Then Return -1 388 m_Chars[startIndex] = 0384 Chars[startIndex] = 0 389 385 m_Length = startIndex 390 386 Return m_Length … … 399 395 If newChars = 0 Then Return -1 400 396 401 memcpy(newChars, m_Chars, startIndex)402 memcpy(newChars + startIndex, m_Chars + startIndex + count, m_Length - startIndex - count)397 memcpy(newChars, Chars, startIndex) 398 memcpy(newChars + startIndex, Chars + startIndex + count, m_Length - startIndex - count) 403 399 newChars[m_Length - count] = 0 404 400 405 _System_free( m_Chars)406 m_Chars = newChars401 _System_free(Chars) 402 Chars = newChars 407 403 m_Length = m_Length - count 408 404 Return m_Length … … 420 416 Dim i As Long 421 417 For i = 0 To ELM(m_Length) 422 If m_Chars[i] = oldChar Then423 m_Chars[i] = newChar418 If Chars[i] = oldChar Then 419 Chars[i] = newChar 424 420 End If 425 421 Next … … 444 440 Exit Do 445 441 End If 446 .Append( m_Chars + current, pos - current)442 .Append(Chars + current, pos - current) 447 443 .Append(newStr, newLen) 448 444 current = pos + oldLen 449 445 Loop 450 .Append( m_Chars + current, m_Length - current)446 .Append(Chars + current, m_Length - current) 451 447 End With 452 448 Swap(tempString) … … 454 450 455 451 Sub ToLower() 456 CharLower( m_Chars)452 CharLower(Chars) 457 453 End Sub 458 454 459 455 Sub ToUpper() 460 CharUpper( m_Chars)456 CharUpper(Chars) 461 457 End Sub 462 458 … … 465 461 Dim tempChars As PSTR 466 462 tempLen = x.m_Length 467 tempChars = x. m_Chars463 tempChars = x.Chars 468 464 x.m_Length = This.m_Length 469 x. m_Chars = This.m_Chars465 x.Chars = This.Chars 470 466 This.m_Length = tempLen 471 This. m_Chars = tempChars467 This.Chars = tempChars 472 468 End Sub 473 469 … … 478 474 Return 0 479 475 ElseIf textLength > m_Length Then 480 AllocStringBuffer = _System_realloc( m_Chars, textLength + 1)476 AllocStringBuffer = _System_realloc(Chars, textLength + 1) 481 477 If AllocStringBuffer <> 0 Then 482 478 m_Length = textLength 483 m_Chars = AllocStringBuffer479 Chars = AllocStringBuffer 484 480 End If 485 481 Else 486 482 m_Length = textLength 487 AllocStringBuffer = m_Chars483 AllocStringBuffer = Chars 488 484 End If 489 485 End Function
Note:
See TracChangeset
for help on using the changeset viewer.