Ignore:
Timestamp:
Mar 13, 2007, 11:58:58 AM (18 years ago)
Author:
イグトランス (egtra)
Message:

String関連の変更とHex$の修正

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/basic/function.sbp

    r164 r167  
    1111
    1212
    13 #include <Classes/System/Math.ab>
     13#require <Classes/System/Math.ab>
    1414
    1515
     
    330330End Function
    331331
    332 Const HIBYTE(w) = (((w As Word) >> 8) and &HFF) As Byte
    333 Const LOBYTE(w) = ((w As Word) and &HFF) As Byte
    334 Const HIWORD(dw) = (((dw As DWord) >> 16) and &HFFFF) As Word
    335 Const LOWORD(dw) = ((dw As DWord) and &HFFFF) As Word
    336 
    337 Const MAKEWORD(a,b) = (((a As Word) and &HFF) or (((b As Word) and &HFF)<<8)) As Word
    338 Const MAKELONG(a,b) = (((a As DWord) and &HFFFF) or (((b As DWord) and &HFFFF)<<16)) As Long
    339 
    340 
     332Const HIBYTE(w) = (((w As Word) >> 8) And &HFF) As Byte
     333Const LOBYTE(w) = ((w As Word) And &HFF) As Byte
     334Const HIWORD(dw) = (((dw As DWord) >> 16) And &HFFFF) As Word
     335Const LOWORD(dw) = ((dw As DWord) And &HFFFF) As Word
     336Const HIDWORD(qw) = (((qw As QWord) >> 32) And &HFFFFFFFF) As DWord
     337Const LODWORD(qw) = ((qw As QWord) And &HFFFFFFFF) As DWord
     338
     339Const MAKEWORD(l, h) = (((l As Word) And &HFF) Or (((h As Word) And &HFF) << 8)) As Word
     340Const MAKEDWORD(l, h) = (((l As DWord) And &HFFFF) Or (((h As DWord) And &HFFFF) << 16)) As DWord
     341Const MAKEQWORD(l, h) = (((l As QWord) And &HFFFFFFFF) Or (((h As QWord) And &HFFFFFFFF) << 32)) As QWord
     342Const MAKELONG(l, h) = MAKEDWORD(l, h) As Long
    341343
    342344'------------
     
    406408Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
    407409
     410Function _System_Hex(x As DWord, zeroSuppress As Boolean) As String
     411    Dim s[7] As StrChar
     412    Dim i As Long
     413    For i = 0 To ELM(Len (s) \ SizeOf (StrChar))
     414        s[i] = _System_HexadecimalTable[x >> 28] As StrChar
     415        x <<= 4
     416    Next
     417    If zeroSuppress Then
     418        Dim i As Long
     419        For i = 0 To 6
     420            If s[i] <> &h30 Then 'Asc("0")
     421                Exit For
     422            End If
     423        Next
     424        Return New String(VarPtr(s[i]) As *StrChar, Len (s) \ SizeOf (StrChar) - i)
     425    Else
     426        Return New String(s As *StrChar, Len (s) \ SizeOf (StrChar))
     427    End If
     428End Function
     429
    408430Function Hex$(x As DWord) As String
    409     Dim i = 0
    410     Hex$ = ZeroString(8)
    411     While (x And &hf0000000) = 0
    412         x <<= 4
    413     Wend
    414     While x <> 0
    415         Hex$[i] = _System_HexadecimalTable[(x And &hf0000000) >> 28] As Char
    416         x <<= 4
    417         i++
    418     Wend
    419     Hex$.ReSize(i)
     431    Hex$ = _System_Hex(x, True)
    420432End Function
    421433
    422434Function Hex$(x As QWord) As String
    423     Hex$ = Hex$((x >> 32) As DWord) + Hex$((x And &hffffffff) As DWord)
     435    Hex$ = _System_Hex(HIDWORD(x), True) + _System_Hex(LODWORD(x), False)
    424436End Function
    425437
    426438Function InStr(StartPos As Long, buf1 As String, buf2 As String) As Long
    427     Dim len1 As Long, len2 As Long, i As Long, i2 As Long, i3 As Long
    428 
    429     len1=Len(buf1)
    430     len2=Len(buf2)
     439    Dim i As Long, i2 As Long, i3 As Long
     440
     441    Dim len1 = buf1.Length
     442    Dim len2 = buf2.Length
    431443
    432444    If len2=0 Then
     
    462474Function Left$(buf As String, length As Long) As String
    463475    Left$ = ZeroString(length)
    464     memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (Char) * length)
     476    memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (StrChar) * length)
    465477End Function
    466478
     
    487499
    488500    Mid$=ZeroString(ReadLength)
    489     memcpy(StrPtr(Mid$), VarPtr(buf.Chars[StartPos]), SizeOf (Char) * ReadLength)
     501    memcpy(StrPtr(Mid$), VarPtr(buf.Chars[StartPos]), SizeOf (StrChar) * ReadLength)
    490502End Function
    491503
     
    515527    If i>length Then
    516528        Right$=ZeroString(length)
    517         memcpy(StrPtr(Right$), VarPtr(buf.Chars[i-length]), SizeOf (Char) * length)
     529        memcpy(StrPtr(Right$), VarPtr(buf.Chars[i-length]), SizeOf (StrChar) * length)
    518530    Else
    519531        Right$=buf
     
    522534
    523535Function Space$(length As Long) As String
    524     Space$.ReSize(length, &H20 As Char)
    525 End Function
    526 
    527 Dim _System_ecvt_buffer[16] As Char
     536    Space$.ReSize(length, &H20 As StrChar)
     537End Function
     538
     539Dim _System_ecvt_buffer[16] As StrChar
    528540Sub _ecvt_support(count As Long)
    529541    Dim i As Long
     
    542554    End If
    543555End Sub
    544 Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *Char
    545     Dim temp As *Char
     556Function _ecvt(value As Double, count As Long, ByRef dec As Long, ByRef sign As Long) As *StrChar
    546557    Dim i As Long, i2 As Long
    547558
     
    549560
    550561    '値が0の場合
    551     If value=0 Then
     562    If value = 0 Then
    552563        _System_FillChar(_System_ecvt_buffer, count, &H30)
    553564        _System_ecvt_buffer[count] = 0
     
    558569
    559570    '符号の判断(同時に符号を取り除く)
    560     If value<0 Then
    561         sign=1
    562         value=-value
    563     Else
    564         sign=0
     571    If value < 0 Then
     572        sign = 1
     573        value = -value
     574    Else
     575        sign = 0
    565576    End If
    566577
    567578    '正規化
    568     dec=1
    569     While value<0.999999999999999 'value<1
     579    dec = 1
     580    While value < 0.999999999999999 'value<1
    570581        value *= 10
    571582        dec--
    572583    Wend
    573     While 9.99999999999999<=value '10<=value
     584    While 9.99999999999999 <= value '10<=value
    574585        value /= 10
    575586        dec++
     
    577588
    578589    For i=0 To count-1
    579         _System_ecvt_buffer[i]=Int(value) As Char
    580 
    581         value=(value-CDbl(Int(value)))*10
     590        _System_ecvt_buffer[i] = Int(value) As StrChar
     591
     592        value = (value-CDbl(Int(value))) * 10
    582593    Next
    583     _System_ecvt_buffer[i]=0
     594    _System_ecvt_buffer[i] = 0
    584595
    585596    i--
    586     If value>=5 Then
     597    If value >= 5 Then
    587598        '切り上げ処理
    588599        _ecvt_support(i)
    589600    End If
    590601
    591     For i=0 To count-1
     602    For i=0 To ELM(count)
    592603        _System_ecvt_buffer[i] += &H30
    593604    Next
    594     _System_ecvt_buffer[i]=0
     605    _System_ecvt_buffer[i] = 0
    595606End Function
    596607
     
    606617    End If
    607618    Dim dec As Long, sign As Long
    608     Dim buffer[32] As Char, temp As *Char
     619    Dim buffer[32] As StrChar, temp As *StrChar
    609620    Dim i As Long, i2 As Long, i3 As Long
    610621
    611622    '浮動小数点を文字列に変換
    612     temp=_ecvt(dbl,15,dec,sign)
     623    temp = _ecvt(dbl, 15, dec, sign)
    613624
    614625    i=0
     
    616627    '符号の取り付け
    617628    If sign Then
    618         buffer[i]=Asc("-")
     629        buffer[i] = Asc("-")
    619630        i++
    620631    End If
     
    622633    If dec>15 Then
    623634        '指数表示(桁が大きい場合)
    624         buffer[i]=temp[0]
    625         i++
    626         buffer[i]=Asc(".")
    627         i++
    628         memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (Char) * 14)
     635        buffer[i] = temp[0]
     636        i++
     637        buffer[i] = Asc(".")
     638        i++
     639        memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
     640        i += 14
     641        buffer[i] = Asc("e")
     642        i++
     643        _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
     644
     645        Return MakeStr(buffer)
     646    End If
     647
     648    If dec < -3 Then
     649        '指数表示(桁が小さい場合)
     650        buffer[i] = temp[0]
     651        i++
     652        buffer[i] = Asc(".")
     653        i++
     654        memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (StrChar) * 14)
    629655        i+=14
    630         buffer[i]=Asc("e")
    631         i++
    632         _stprintf(VarPtr(buffer[i]), "+%03d", dec-1)
    633 
    634         Return MakeStr(buffer)
    635     End If
    636 
    637     If dec<-3 Then
    638         '指数表示(桁が小さい場合)
    639         buffer[i]=temp[0]
    640         i++
    641         buffer[i]=Asc(".")
    642         i++
    643         memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (Char) * 14)
    644         i+=14
    645         buffer[i]=Asc("e")
    646         i++
    647         _stprintf(VarPtr(buffer[i]), "+%03d", dec-1)
     656        buffer[i] = Asc("e")
     657        i++
     658        _stprintf(VarPtr(buffer[i]), "+%03d", dec - 1)
    648659
    649660        Return MakeStr(buffer)
     
    691702    Return MakeStr(buffer)
    692703End Function
     704
    693705Function Str$(value As Int64) As String
    694706    Dim temp[255] As Char
     
    709721    Dim i As Long
    710722    For i=0 To num-1
    711         memcpy(VarPtr(String$[i*length]), StrPtr(buf), SizeOf (Char) * length)
     723        memcpy(VarPtr(String$[i*length]), StrPtr(buf), SizeOf (StrChar) * length)
    712724    Next
    713725End Function
     
    741753End Function
    742754
    743 Function Val(buf As *Char) As Double
     755Function Val(buf As *StrChar) As Double
    744756    Dim i As Long, i2 As Long, i3 As Long, i4 As Long
    745757    Dim temporary As String
    746     Dim TempPtr As *Char
     758    Dim TempPtr As *StrChar
    747759    Dim dbl As Double
    748760    Dim i64data As Int64
     
    766778                If Not (0<=i3 And i3<=7) Then Exit While
    767779
    768                 TempPtr[i]=i3 As Char
     780                TempPtr[i]=i3 As StrChar
    769781                i++
    770782            Wend
     
    789801                End If
    790802
    791                 TempPtr[i]=i3 As Char
     803                TempPtr[i]=i3 As StrChar
    792804                i++
    793805            Wend
     
    945957Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
    946958    Dim i As Long, i2 As Long, i3 As Long, length As Long
    947     Dim buffer[MAX_PATH] As Char
     959    Dim buffer[MAX_PATH] As SByte
    948960
    949961    '":\"をチェック
     
    961973    i2=0
    962974    Do
    963 '#ifdef UNICODE
    964 '       If _System_IsSurrogatePair(path[i], path[i + 1]) Then
    965 '#else
    966975        If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
    967 '#endif
    968976            If dir Then
    969977                dir[i2]=path[i]
     
    10551063End Function
    10561064
     1065Function _System_BSwap(x As Word) As Word
     1066    Dim src = VarPtr(x) As *Byte
     1067    Dim dst = VarPtr(_System_BSwap) As *SByte
     1068    dst[0] = src[1]
     1069    dst[1] = src[0]
     1070End Function
     1071
     1072Function _System_BSwap(x As DWord) As DWord
     1073    Dim src = VarPtr(x) As *Byte
     1074    Dim dst = VarPtr(_System_BSwap) As *SByte
     1075    dst[0] = src[3]
     1076    dst[1] = src[2]
     1077    dst[2] = src[1]
     1078    dst[3] = src[0]
     1079End Function
     1080
     1081Function _System_BSwap(x As QWord) As QWord
     1082    Dim src = VarPtr(x) As *Byte
     1083    Dim dst = VarPtr(_System_BSwap) As *SByte
     1084    dst[0] = src[7]
     1085    dst[1] = src[6]
     1086    dst[2] = src[5]
     1087    dst[3] = src[4]
     1088    dst[4] = src[3]
     1089    dst[5] = src[2]
     1090    dst[6] = src[1]
     1091    dst[7] = src[0]
     1092End Function
     1093
    10571094'--------
    10581095' 文字列関数その2
Note: See TracChangeset for help on using the changeset viewer.