Changeset 385 for trunk/Include
- Timestamp:
- Nov 20, 2007, 12:04:07 AM (17 years ago)
- Location:
- trunk/Include
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/ActiveBasic/Strings/SPrintF.ab
r384 r385 90 90 Zero = &h4 91 91 '! 左揃え、-。フィールド内で左揃えにする。 92 Left = &h892 LeftSide = &h8 93 93 /*! 代替表記、#。 94 94 <ul> … … 867 867 If .Length < field Then 868 868 Dim embeddedSize = field - .Length 869 If flags And Left Then869 If flags And LeftSide Then 870 870 .Append(&h20, embeddedSize) 871 871 Else … … 898 898 Dim sb = New System.Text.StringBuilder( 899 899 x, 0, System.Math.Min(x.Length As DWord, d) As Long, field) 900 AdjustFieldWidth(sb, field, flags And Left )900 AdjustFieldWidth(sb, field, flags And LeftSide) 901 901 FormatString = sb.ToString() 902 902 End Function … … 915 915 Dim sb = New System.Text.StringBuilder(field + 1) 916 916 sb.Append(x) 917 AdjustFieldWidth(sb, field, flags And Left )917 AdjustFieldWidth(sb, field, flags And LeftSide) 918 918 FormatCharacter = sb.ToString() 919 919 End Function … … 1094 1094 flags Or= Sign 1095 1095 Case &h2d '- 1096 flags Or = Left 1096 flags Or = LeftSide 1097 1097 Case &h26 '& 1098 1098 flags Or= BPrefix … … 1122 1122 If ReadInt(fmt, params, paramsCount, t) Then 1123 1123 If t < 0 Then 1124 flags Or= Left 1124 flags Or= LeftSide 1125 1125 fieldWidth = -t As DWord 1126 1126 Else -
trunk/Include/Classes/ActiveBasic/Strings/Strings.ab
r383 r385 95 95 ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2)) 96 96 If ChrCmp = 0 Then 97 ChrCmp = ( size1 - size2) As Long97 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long 98 98 End If 99 99 End Function … … 102 102 ChrCmp = ChrCmp(s1, s2, System.Math.Min(size1, size2)) 103 103 If ChrCmp = 0 Then 104 ChrCmp = ( size1 - size2) As Long104 ChrCmp = (( size1 - size2 ) As LONG_PTR) As Long 105 105 End If 106 106 End Function -
trunk/Include/Classes/System/Text/StringBuilder.ab
r383 r385 120 120 121 121 Function Append(s As String, startIndex As Long, count As Long) As StringBuilder 122 If s = 0 Then 123 If startIndex = 0 And count = 0 Then 124 Return This 125 Else 126 'Throw ArgumentNullException 127 End If 128 End If 129 StringBuilder.rangeCheck2(s.Length, startIndex, count) 130 appendCore(s, startIndex, count) 131 Return This 122 Return Append(StrPtr(s), startIndex, count) 132 123 End Function 133 124 … … 137 128 Return This 138 129 Else 139 'Throw ArgumentNullException130 Throw New ArgumentNullException("StringBuilder.Append: An argument was null", "s") 140 131 End If 141 132 ElseIf startIndex < 0 Or count < 0 Then 142 'Throw ArgumentOutOfRangeException133 Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "startIndex or count or both") 143 134 End If 144 135 appendCore(s, startIndex, count) … … 178 169 Const Sub CopyTo(sourceIndex As Long, ByRef dest[] As StrChar, destIndex As Long, count As Long) 179 170 If dest = 0 Then 180 'Throw ArgumentNullException171 Throw New ArgumentNullException("StringBuilder.CopyTo: An argument was null", "sourceIndex") 181 172 ElseIf size < sourceIndex + count Or sourceIndex < 0 Or destIndex < 0 Or count < 0 Then 182 'Throw ArgumentOutOfRangeException173 Throw New ArgumentOutOfRangeException("StringBuilder.CopyTo: One or more arguments have out of range value.", "startIndex or count or both") 183 174 End If 184 175 … … 188 179 Function EnsureCapacity(c As Long) As Long 189 180 If c < 0 Or c > MaxCapacity Then 190 'Throw ArgumentOutOfRangeException181 Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument was out of range value.", "c") 191 182 ElseIf c > Capacity Then 192 183 Dim p = GC_malloc_atomic((c + 1) * SizeOf (StrChar)) As *StrChar … … 300 291 rangeCheck(index) 301 292 If n < 0 Then 302 'Throw New ArgumentOutOfRangeException 303 Debug 293 Throw New ArgumentOutOfRangeException("StringBuilder.Insert: An argument was out of range value.", "n") 304 294 End If 305 295 Dim len = x.Length … … 308 298 EnsureCapacity(newSize) 309 299 separateBuffer() 310 311 ' TODO: fix me!(定義されていない変数iが使われています)312 'ActiveBasic.Strings.ChrMove(VarPtr(chars[i + lenTotal]), VarPtr(chars[i]), (size - index) As SIZE_T)313 300 314 301 Dim i As Long … … 320 307 End Function 321 308 322 323 309 Function Insert(i As Long, x As *StrChar, index As Long, count As Long) As StringBuilder 324 310 rangeCheck(i) 325 311 If x = 0 Then 326 'Throw New ArgumentNullException 327 Debug 312 Throw New ArgumentNullException("StringBuilder.Insert: An argument was null", "x") 328 313 ElseIf index < 0 Or count < 0 Then 329 'Throw New ArgumentNullException 330 Debug 314 Throw New ArgumentOutOfRangeException("StringBuilder.Append: One or more arguments have out of range value.", "index or count or both") 331 315 End If 332 316 … … 396 380 397 381 Sub replaceCore(oldStr As String, newStr As String, start As Long, count As Long) 398 If Object.ReferenceEquals(oldStr, Nothing) Then 399 'Throw ArgumentNullException 400 Debug 382 If ActiveBasic.IsNothing(oldStr) Then 383 Throw New ArgumentNullException("StringBuilder.Replace: An argument was null", "oldStr") 401 384 ElseIf oldStr.Length = 0 Then 402 'Throw ArgumentException 403 Debug 385 Throw New ArgumentException("StringBuilder.Replace: The argument 'oldStr' is empty string. ", "oldStr") 404 386 End If 405 387 … … 412 394 End If 413 395 414 s.appendCore(chars, curPos, nextPos )396 s.appendCore(chars, curPos, nextPos As Long) 415 397 s.Append(newStr) 416 curPos += nextPos + oldStr.Length398 curPos += nextPos As Long + oldStr.Length 417 399 Loop 418 400 chars = s.chars … … 446 428 Sub Capacity(c As Long) 447 429 If c < size Or c > MaxCapacity Then 'sizeとの比較でcが負の場合も対応 448 'Throw ArgumentOutOfRangeException430 Throw New ArgumentOutOfRangeException("StringBuilder.Append: An argument have out of range value.", "c") 449 431 End If 450 432 EnsureCapacity(c) … … 453 435 Const Function Chars(i As Long) As StrChar 454 436 If i >= Length Or i < 0 Then 455 'Throw IndexOutOfRangeException 456 Debug 437 Throw New IndexOutOfRangeException("StringBuilder.Chars: The index argument 'i' have out of range value.") 457 438 End If 458 439 Return chars[i] … … 461 442 Sub Chars(i As Long, c As StrChar) 462 443 If i >= Length Or i < 0 Then 463 'Throw ArgumentOutOfRangeException 464 Debug 444 Throw New ArgumentOutOfRangeException("StringBuilder.Chars: An argument have out of range value.", "i") 465 445 End If 466 446 chars[i] = c … … 494 474 Sub initialize(capacity As Long, maxCapacity = LONG_MAX As Long) 495 475 If capacity < 0 Or maxCapacity < 1 Or maxCapacity < capacity Then 496 'Throw ArgumentOutOfRangeException476 Throw New ArgumentOutOfRangeException("StringBuilder constructor: One or more arguments have out of range value.", "capacity or maxCapacity or both") 497 477 End If 498 478 … … 526 506 Sub rangeCheck(index As Long) 527 507 If index < 0 Or index > size Then 528 'Throw ArgumentOutOfRangeException 529 Debug 508 Throw New ArgumentOutOfRangeException("StringBuilder: Index argument has out of range value.") 530 509 End If 531 510 End Sub … … 538 517 'length < 0は判定に入っていないことに注意 539 518 If startIndex < 0 Or count < 0 Or startIndex + count > length Then 540 'Throw ArgumentOutOfRangeException 541 Debug 519 Throw New ArgumentOutOfRangeException("StringBuilder: One or more arguments have out of range value.", "startIndex or count or both") 542 520 End If 543 521 End Sub -
trunk/Include/Classes/index.ab
r371 r385 1 #require "./ActiveBasic/misc.ab" 1 2 #require "./ActiveBasic/Core/InterfaceInfo.ab" 2 3 #require "./ActiveBasic/Core/TypeInfo.ab" … … 11 12 #require "./System/Delegate.ab" 12 13 #require "./System/Environment.ab" 14 #require "./System/Exception.ab" 13 15 #require "./System/GC.ab" 14 16 #require "./System/Math.ab" -
trunk/Include/basic/function.sbp
r383 r385 427 427 End Function 428 428 429 Dim _System_ecvt_buffer[16] As StrChar 430 Sub _ecvt_support(count As Long) 429 Sub _ecvt_support(buf As *StrChar, count As Long, size As Long) 431 430 Dim i As Long 432 If _System_ecvt_buffer[count]=9 Then433 _System_ecvt_buffer[count]=0434 If count =0 Then435 For i =16To 1 Step -1436 _System_ecvt_buffer[i]=_System_ecvt_buffer[i-1]431 If buf[count] = 9 Then 432 buf[count] = 0 433 If count = 0 Then 434 For i = size To 1 Step -1 435 buf[i] = buf[i-1] 437 436 Next 438 _System_ecvt_buffer[0]=1437 buf[0] = 1 439 438 Else 440 _ecvt_support( count-1)441 End If 442 Else 443 _System_ecvt_buffer[count]++439 _ecvt_support(buf, count-1, size) 440 End If 441 Else 442 buf[count]++ 444 443 End If 445 444 End Sub 446 Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar 445 446 Sub _ecvt(buffer As *StrChar, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean) 447 447 Dim i As Long, i2 As Long 448 449 _ecvt=_System_ecvt_buffer450 448 451 449 '値が0の場合 452 450 If value = 0 Then 453 ActiveBasic.Strings.ChrFill( _System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)454 _System_ecvt_buffer[count] = 0451 ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As StrChar) 452 buffer[count] = 0 455 453 dec = 0 456 454 sign = 0 … … 460 458 '符号の判断(同時に符号を取り除く) 461 459 If value < 0 Then 462 sign = 1460 sign = True 463 461 value = -value 464 462 Else 465 sign = 0463 sign = False 466 464 End If 467 465 … … 477 475 Wend 478 476 479 For i=0 To count-1 480 _System_ecvt_buffer[i] = Int(value) As StrChar 481 477 For i = 0 To count - 1 478 buffer[i] = Int(value) As StrChar 482 479 value = (value-CDbl(Int(value))) * 10 483 480 Next 484 _System_ecvt_buffer[i] = 0485 481 486 482 i-- 487 483 If value >= 5 Then 488 484 '切り上げ処理 489 _ecvt_support( i)490 End If 491 492 For i =0 To ELM(count)493 _System_ecvt_buffer[i] += &H30485 _ecvt_support(buffer, i, count) 486 End If 487 488 For i = 0 To count - 1 489 buffer[i] += &H30 494 490 Next 495 _System_ecvt_buffer[i] = 0496 End Function491 buffer[i] = 0 492 End Sub 497 493 498 494 Function Str$(dbl As Double) As String … … 506 502 End If 507 503 End If 508 Dim dec As Long, sign As Long509 Dim buffer[32] As StrChar, temp As *StrChar510 Dim i As Long, i2 As Long, i3As Long504 Dim dec As Long, sign As Boolean 505 Dim buffer[32] As StrChar, temp[15] As StrChar 506 Dim i = 0 As Long 511 507 512 508 '浮動小数点を文字列に変換 513 temp = _ecvt(dbl, 15, dec, sign) 514 515 i=0 509 _ecvt(temp, dbl, 15, dec, sign) 516 510 517 511 '符号の取り付け … … 521 515 End If 522 516 523 If dec >15Then524 '指数表示 (桁が大きい場合)517 If dec > 15 Or dec < -3 Then 518 '指数表示 525 519 buffer[i] = temp[0] 526 520 i++ … … 529 523 ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T) 530 524 i += 14 531 buffer[i] = Asc("e") 532 i++ 533 _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応 534 535 Return MakeStr(buffer) 536 End If 537 538 If dec < -3 Then 539 '指数表示(桁が小さい場合) 540 buffer[i] = temp[0] 541 i++ 542 buffer[i] = Asc(".") 543 i++ 544 ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T) 545 i+=14 546 buffer[i] = Asc("e") 547 i++ 548 _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1) 'ToDo: __STRING_UNICODE_WINDOWS_ANSI状態への対応 549 550 Return MakeStr(buffer) 525 buffer[i] = 0 526 Return MakeStr(buffer) + ActiveBasic.Strings.SPrintf("e%+03d", New System.Int32(dec - 1)) 551 527 End If 552 528 553 529 '整数部 554 i2=dec555 i3=0530 Dim i2 = dec 531 Dim i3 = 0 556 532 If i2>0 Then 557 533 While i2>0 … … 593 569 End Function 594 570 595 Function Str$(i As Int64) As String 596 If i < 0 Then 597 Return "-" & Str$(-i As QWord) 598 Else 599 Return Str$(i As QWord) 600 End If 571 Function Str$(x As Int64) As String 572 Imports ActiveBasic.Strings.Detail 573 Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None) 601 574 End Function 602 575 603 576 Function Str$(x As QWord) As String 604 If x = 0 Then 605 Return "0" 606 End If 607 608 Dim buf[20] As StrChar 609 'buf[20] = 0 610 Dim i = 19 As Long 611 Do 612 buf[i] = (x Mod 10 + &h30) As StrChar 613 x \= 10 614 If x = 0 Then 615 Exit Do 616 End If 617 i-- 618 Loop 619 Return New String(VarPtr(buf[i]), 20 - i) 577 Imports ActiveBasic.Strings.Detail 578 Return FormatIntegerEx(TraitsIntegerU[1], x, 1, 0, None) 620 579 End Function 621 580 622 581 Function Str$(x As Long) As String 623 #ifdef _WIN64 624 Return Str$(x As Int64) 625 #else 626 If x < 0 Then 627 Return "-" & Str$(-x As DWord) 628 Else 629 Return Str$(x As DWord) 630 End If 631 #endif 582 Imports ActiveBasic.Strings.Detail 583 Return FormatIntegerEx(TraitsIntegerD[0], x, 1, 0, None) 632 584 End Function 633 585 634 586 Function Str$(x As DWord) As String 635 #ifdef _WIN64 636 Return Str$(x As QWord) 637 #else 638 If x = 0 Then 639 Return "0" 640 End If 641 642 Dim buf[10] As StrChar 643 buf[10] = 0 644 Dim i = 9 As Long 645 Do 646 buf[i] = (x As Int64 Mod 10 + &h30) As StrChar 'Int64への型変換は#117対策 647 x \= 10 648 If x = 0 Then 649 Return New String(VarPtr(buf[i]), 10 - i) 650 End If 651 i-- 652 Loop 653 #endif 587 Imports ActiveBasic.Strings.Detail 588 Return FormatIntegerEx(TraitsIntegerU[0], x, 1, 0, None) 654 589 End Function 655 590 656 591 Function Str$(x As Word) As String 657 Return Str$(x As ULONG_PTR)592 Return Str$(x As DWord) 658 593 End Function 659 594 660 595 Function Str$(x As Integer) As String 661 Return Str$(x As L ONG_PTR)596 Return Str$(x As Long) 662 597 End Function 663 598 664 599 Function Str$(x As Byte) As String 665 Return Str$(x As ULONG_PTR)600 Return Str$(x As DWord) 666 601 End Function 667 602 668 603 Function Str$(x As SByte) As String 669 Return Str$(x As L ONG_PTR)604 Return Str$(x As Long) 670 605 End Function 671 606 -
trunk/Include/system/string.sbp
r383 r385 9 9 10 10 Function StrPtr(s As String) As *StrChar 11 StrPtr = s.StrPtr 11 If ActiveBasic.IsNothing(s) Then 12 StrPtr = s.StrPtr 13 End If 12 14 End Function 13 15 'StringBuilder版はClasses/System/Text/StringBuilder.abに定義されている … … 39 41 Function GetStr(psz As PSTR, len As SIZE_T, ByRef wcs As PWSTR) As SIZE_T 40 42 If psz = 0 Then Return 0 41 Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, lenAs Long, 0, 0)43 Dim lenWCS = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0) 42 44 wcs = _System_AllocForConvertedString(SizeOf (WCHAR) * (lenWCS + 1)) As PWSTR 43 GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, lenAs Long, wcs, lenWCS)45 GetStr = MultiByteToWideChar(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, wcs, lenWCS) 44 46 wcs[GetStr] = 0 45 47 End Function … … 73 75 Function GetStr(psz As PWSTR, len As SIZE_T, ByRef mbs As PSTR) As SIZE_T 74 76 If psz = 0 Then Return 0 75 Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, lenAs Long, 0, 0, 0, 0)77 Dim lenMBS = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, 0, 0, 0, 0) 76 78 mbs = _System_AllocForConvertedString(SizeOf (SByte) * (lenMBS + 1)) As PSTR 77 GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, lenAs Long, mbs, lenMBS, 0, 0) As SIZE_T79 GetStr = WideCharToMultiByte(CP_THREAD_ACP, 0, psz, (len As DWord) As Long, mbs, lenMBS, 0, 0) As SIZE_T 78 80 mbs[GetStr] = 0 79 81 End Function
Note:
See TracChangeset
for help on using the changeset viewer.