Changeset 388 for trunk/Include/Classes/System/String.ab
- Timestamp:
- Nov 25, 2007, 4:31:35 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/String.ab
r383 r388 61 61 Sub String(initStr As PCWSTR, start As Long, length As Long) 62 62 If start < 0 Or length Or start + length < 0 Then 63 'Throw New ArgumentOutOfRangeException63 Throw New ArgumentOutOfRangeException("String constractor: One or more arguments are out of range value.", "start or length or both") 64 64 End If 65 65 validPointerCheck(initStr + start, length) … … 78 78 79 79 Sub String(initStr As PCSTR, start As Long, length As Long) 80 If start < 0 Or length Or start + length< 0 Then81 'Throw New ArgumentOutOfRangeException80 If start < 0 Or length < 0 Then 81 Throw New ArgumentOutOfRangeException("String constructor: One or more arguments are out of range value.", "start or length or both") 82 82 End If 83 83 validPointerCheck(initStr + start, length) … … 97 97 End Sub 98 98 99 Sub String(sb As System.Text.StringBuilder)99 Sub String(sb As Text.StringBuilder) 100 100 Chars = StrPtr(sb) 101 101 m_Length = sb.Length … … 246 246 247 247 Function CompareTo(y As Object) As Long 248 Dim s = y As String 249 ' If y is not String Then 250 ' Throw New ArgumentException 251 ' End If 248 If Not Object.Equals(This.GetType(), y.GetType()) Then 249 Throw New ArgumentException("String.CompareTo: An argument is out of range value.", "y") 250 End If 252 251 Return CompareTo(y As String) 253 252 End Function … … 348 347 Const Function Contains(s As String) As Boolean 349 348 If Object.ReferenceEquals(s, Nothing) Then 350 'Throw New ArgumentNullException 351 End If 352 Return IndexOf(s, 0, m_Length) >= 0 349 Throw New ArgumentNullException("String.Contains: An argument is out of range value.", "s") 350 ElseIf s = "" Then 351 Return True 352 Else 353 Return IndexOf(s, 0, m_Length) >= 0 354 End If 353 355 End Function 354 356 … … 385 387 rangeCheck(startIndex, count) 386 388 If Object.ReferenceEquals(s, Nothing) Then 387 'Throw New ArgumentNullException 388 Debug 389 Throw New ArgumentNullException("String.IndexOf: An argument is out of range value.", "s") 389 390 End If 390 391 … … 405 406 End Function 406 407 408 Const Function LastIndexOf(c As StrChar) As Long 409 Return lastIndexOf(c, m_Length - 1, m_Length) 410 End Function 411 412 Const Function LastIndexOf(c As StrChar, start As Long) As Long 413 rangeCheck(start) 414 Return lastIndexOf(c, start, start + 1) 415 End Function 416 417 Const Function LastIndexOf(c As StrChar, start As Long, count As Long) As Long 418 rangeCheck(start) 419 Dim lastFindPos = start - (count - 1) 420 If Not (m_Length > lastFindPos And lastFindPos >= 0) Then 421 Throw New ArgumentOutOfRangeException("String.LastIndexOf: An argument is out of range value.", "count") 422 End If 423 Return lastIndexOf(c, start, count) 424 End Function 425 Private 426 Const Function lastIndexOf(c As StrChar, start As Long, count As Long) As Long 427 Dim lastFindPos = start - (count - 1) 428 Dim i As Long 429 For i = start To lastFindPos Step -1 430 If Chars[i] = c Then 431 Return i 432 End If 433 Next 434 Return -1 435 End Function 436 437 Public 407 438 Const Function LastIndexOf(s As String) As Long 408 439 Return LastIndexOf(s, m_Length - 1, m_Length) … … 413 444 End Function 414 445 415 Const Function LastIndexOf(s As String, start IndexAs Long, count As Long) As Long446 Const Function LastIndexOf(s As String, start As Long, count As Long) As Long 416 447 If Object.ReferenceEquals(s, Nothing) Then 417 'Throw New ArgumentNullException 418 Debug 419 End If 420 421 If startIndex < 0 Or startIndex > m_Length - 1 Or _ 422 count < 0 Or count > startIndex + 2 Then 423 'Throw New ArgumentOutOfRangeException 424 Debug 425 End If 426 Dim length = s.Length 448 Throw New ArgumentNullException("String.LastIndexOf: An argument is out of range value.", "s") 449 End If 450 451 If start < 0 Or start > m_Length - 1 Or _ 452 count < 0 Or count > start + 2 Then 453 Throw New ArgumentOutOfRangeException("String.LastIndexOf: One or more arguments are out of range value.", "start or count or both") 454 End If 455 Dim length = s.m_Length 427 456 If length > m_Length Then Return -1 428 If length = 0 Then Return start Index457 If length = 0 Then Return start 429 458 430 459 Dim i As Long, j As Long 431 For i = start Index To startIndex- count + 1 Step -1460 For i = start To start - count + 1 Step -1 432 461 For j = length - 1 To 0 Step -1 433 462 If Chars[i + j] = s[j] Then … … 450 479 451 480 Const Function Insert(startIndex As Long, text As String) As String 452 Dim sb = New System.Text.StringBuilder(This)481 Dim sb = New Text.StringBuilder(This) 453 482 sb.Insert(startIndex, text) 454 483 Return sb.ToString … … 471 500 472 501 Const Function Remove(startIndex As Long, count As Long) As String 473 Dim sb = New System.Text.StringBuilder(This)502 Dim sb = New Text.StringBuilder(This) 474 503 sb.Remove(startIndex, count) 475 504 Remove = sb.ToString … … 486 515 487 516 Const Function Replace(oldChar As StrChar, newChar As StrChar) As String 488 Dim sb = New System.Text.StringBuilder(This)517 Dim sb = New Text.StringBuilder(This) 489 518 sb.Replace(oldChar, newChar) 490 519 Replace = sb.ToString … … 492 521 493 522 Const Function Replace(oldStr As String, newStr As String) As String 494 Dim sb = New System.Text.StringBuilder(This)523 Dim sb = New Text.StringBuilder(This) 495 524 sb.Replace(oldStr, newStr) 496 525 Return sb.ToString … … 498 527 499 528 Const Function ToLower() As String 500 Dim sb = New System.Text.StringBuilder(m_Length)529 Dim sb = New Text.StringBuilder(m_Length) 501 530 sb.Length = m_Length 502 531 Dim i As Long 503 532 For i = 0 To ELM(m_Length) 504 sb[i] = _System_ASCII_ToLower(Chars[i])533 sb[i] = ActiveBasic.CType.ToLower(Chars[i]) 505 534 Next 506 535 Return sb.ToString … … 508 537 509 538 Const Function ToUpper() As String 510 Dim sb = New System.Text.StringBuilder(m_Length)539 Dim sb = New Text.StringBuilder(m_Length) 511 540 sb.Length = m_Length 512 541 Dim i As Long 513 542 For i = 0 To ELM(m_Length) 514 sb[i] = _System_ASCII_ToUpper(Chars[i])543 sb[i] = ActiveBasic.CType.ToUpper(Chars[i]) 515 544 Next 516 545 Return sb.ToString … … 539 568 Dim size = m_Length 540 569 #endif 541 Return _System_GetHashFromWordArray(Chars As *Word, size) Xor size570 Return _System_GetHashFromWordArray(Chars As *Word, size) Xor m_Length 542 571 End Function 543 572 … … 548 577 Function PadLeft(total As Long, c As StrChar) As String 549 578 If total < 0 Then 550 'Throw New ArgumentException579 Throw New ArgumentOutOfRangeException("String.PadLeft: An arguments is out of range value.", "total") 551 580 End If 552 581 If total >= m_Length Then 553 582 Return This 554 583 End If 555 Dim sb = New System.Text.StringBuilder(total)584 Dim sb = New Text.StringBuilder(total) 556 585 sb.Append(c, total - m_Length) 557 586 sb.Append(This) … … 565 594 Function PadRight(total As Long, c As StrChar) As String 566 595 If total < 0 Then 567 'Throw New ArgumentException596 Throw New ArgumentOutOfRangeException("String.PadRight: An arguments is out of range value.", "total") 568 597 End If 569 598 If total >= m_Length Then 570 599 Return This 571 600 End If 572 Dim sb = New System.Text.StringBuilder(total)601 Dim sb = New Text.StringBuilder(total) 573 602 sb.Append(This) 574 603 sb.Append(c, total - m_Length) … … 596 625 Const Sub rangeCheck(index As Long) 597 626 If index < 0 Or index > m_Length Then 598 Debug 'ArgumentOutOfRangeException627 Throw New ArgumentOutOfRangeException("String: An arguments is out of range value.", "index") 599 628 End If 600 629 End Sub … … 602 631 Const Sub rangeCheck(start As Long, length As Long) 603 632 If start < 0 Or start > This.m_Length Or length < 0 Then 604 Debug 'ArgumentOutOfRangeException633 Throw New ArgumentOutOfRangeException("String: One or more arguments are out of range value.", "start or length or both") 605 634 End If 606 635 End Sub
Note:
See TracChangeset
for help on using the changeset viewer.