Ignore:
Timestamp:
Nov 20, 2007, 12:04:07 AM (17 years ago)
Author:
イグトランス (egtra)
Message:

例外クラスの実装。ExceptionTestでSystem.Exceptionを使用するようにした。
StringBuilderでコメント化されていた例外を投げる処理を有効にした(除OutOfMemory)。
Str$の実装にSPrintfなどを使用するようにした。
毎回Object.ReferenceEquals(xxx, Nothing)と打つのが面倒なので、IsNothingを導入。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/basic/function.sbp

    r383 r385  
    427427End Function
    428428
    429 Dim _System_ecvt_buffer[16] As StrChar
    430 Sub _ecvt_support(count As Long)
     429Sub _ecvt_support(buf As *StrChar, count As Long, size As Long)
    431430    Dim i As Long
    432     If _System_ecvt_buffer[count]=9 Then
    433         _System_ecvt_buffer[count]=0
    434         If count=0 Then
    435             For i=16 To 1 Step -1
    436                 _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]
    437436            Next
    438             _System_ecvt_buffer[0]=1
     437            buf[0] = 1
    439438        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]++
    444443    End If
    445444End Sub
    446 Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar
     445
     446Sub _ecvt(buffer As *StrChar, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean)
    447447    Dim i As Long, i2 As Long
    448 
    449     _ecvt=_System_ecvt_buffer
    450448
    451449    '値が0の場合
    452450    If value = 0 Then
    453         ActiveBasic.Strings.ChrFill(_System_ecvt_buffer, count As SIZE_T, &H30 As StrChar)
    454         _System_ecvt_buffer[count] = 0
     451        ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As StrChar)
     452        buffer[count] = 0
    455453        dec = 0
    456454        sign = 0
     
    460458    '符号の判断(同時に符号を取り除く)
    461459    If value < 0 Then
    462         sign = 1
     460        sign = True
    463461        value = -value
    464462    Else
    465         sign = 0
     463        sign = False
    466464    End If
    467465
     
    477475    Wend
    478476
    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
    482479        value = (value-CDbl(Int(value))) * 10
    483480    Next
    484     _System_ecvt_buffer[i] = 0
    485481
    486482    i--
    487483    If value >= 5 Then
    488484        '切り上げ処理
    489         _ecvt_support(i)
    490     End If
    491 
    492     For i=0 To ELM(count)
    493         _System_ecvt_buffer[i] += &H30
     485        _ecvt_support(buffer, i, count)
     486    End If
     487
     488    For i = 0 To count - 1
     489        buffer[i] += &H30
    494490    Next
    495     _System_ecvt_buffer[i] = 0
    496 End Function
     491    buffer[i] = 0
     492End Sub
    497493
    498494Function Str$(dbl As Double) As String
     
    506502        End If
    507503    End If
    508     Dim dec As Long, sign As Long
    509     Dim buffer[32] As StrChar, temp As *StrChar
    510     Dim i As Long, i2 As Long, i3 As Long
     504    Dim dec As Long, sign As Boolean
     505    Dim buffer[32] As StrChar, temp[15] As StrChar
     506    Dim i = 0 As Long
    511507
    512508    '浮動小数点を文字列に変換
    513     temp = _ecvt(dbl, 15, dec, sign)
    514 
    515     i=0
     509    _ecvt(temp, dbl, 15, dec, sign)
    516510
    517511    '符号の取り付け
     
    521515    End If
    522516
    523     If dec>15 Then
    524         '指数表示(桁が大きい場合)
     517    If dec > 15 Or dec < -3 Then
     518        '指数表示
    525519        buffer[i] = temp[0]
    526520        i++
     
    529523        ActiveBasic.Strings.ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
    530524        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))
    551527    End If
    552528
    553529    '整数部
    554     i2=dec
    555     i3=0
     530    Dim i2 = dec
     531    Dim i3 = 0
    556532    If i2>0 Then
    557533        While i2>0
     
    593569End Function
    594570
    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
     571Function Str$(x As Int64) As String
     572    Imports ActiveBasic.Strings.Detail
     573    Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None)
    601574End Function
    602575
    603576Function 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)
    620579End Function
    621580
    622581Function 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)
    632584End Function
    633585
    634586Function 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)
    654589End Function
    655590
    656591Function Str$(x As Word) As String
    657     Return Str$(x As ULONG_PTR)
     592    Return Str$(x As DWord)
    658593End Function
    659594
    660595Function Str$(x As Integer) As String
    661     Return Str$(x As LONG_PTR)
     596    Return Str$(x As Long)
    662597End Function
    663598
    664599Function Str$(x As Byte) As String
    665     Return Str$(x As ULONG_PTR)
     600    Return Str$(x As DWord)
    666601End Function
    667602
    668603Function Str$(x As SByte) As String
    669     Return Str$(x As LONG_PTR)
     604    Return Str$(x As Long)
    670605End Function
    671606
Note: See TracChangeset for help on using the changeset viewer.