Changeset 394 for trunk/Include


Ignore:
Timestamp:
Dec 9, 2007, 3:03:51 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

_System_HashFromUIntの追加([392]から必要だった)。AscWで上位サロゲートだけのLength = 1の場合に、2字目を読みに行かないようにした。

File:
1 edited

Legend:

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

    r388 r394  
    243243'------------
    244244
    245 Function Asc(buf As *StrChar) As StrChar
     245Function Asc(buf As String) As StrChar
    246246    Asc = buf[0]
    247247End Function
     
    253253#ifndef __STRING_IS_NOT_UNICODE
    254254Function AscW(s As String) As UCSCHAR
    255     If s.Length = 0 Then
     255    If String.IsNullOrEmpty(s) Then
    256256        AscW = 0
    257     Else
    258         If _System_IsSurrogatePair(s[0], s[1]) Then
    259             AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
     257        'ArgumentNullExceptionに変えるかも
     258    Else
     259        If _System_IsHighSurrogate(s[0]) Then
     260            '有効なサロゲートペアになっていない場合には、
     261            '例外を投げるようにしたほうがよいかもしれない。
     262            If s.Length > 1 Then
     263                If _System_IsLowSurrogate(s[0]) Then
     264                    AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
     265                    Exit Function
     266                End If
     267            End If
    260268        Else
    261269            AscW = s[0]
     
    267275    If c <= &hFFFF Then
    268276        Return New String(c As StrChar, 1)
    269     ElseIf c < &h10FFFF Then
    270         Dim t[1] = [&hD800 Or (c >> 10), &hDC00 Or (c And &h3FF)] As WCHAR
     277    ElseIf c <= &h10FFFF Then
     278        Dim t[1] As WCHAR
     279        t[0] = (&hD800 Or (c >> 10)) As WCHAR
     280        t[1] = (&hDC00 Or (c And &h3FF)) As WCHAR
    271281        Return New String(t, 2)
    272282    Else
    273         'ArgumentOutOfRangeException
     283        Throw New System.ArgumentOutOfRangeException("ChrW: c is invalid Unicode code point.", "c")
    274284    End If
    275285End Function
     
    691701    Else
    692702        '10進数
     703#ifdef __STRING_IS_NOT_UNICODE
    693704        sscanf(buf,"%lf",VarPtr(Val))
     705#else
     706        swscanf(buf,ToWCStr("%lf"),VarPtr(Val))
     707#endif
    694708    End If
    695709End Function
     
    917931End Function
    918932
     933Function _System_HashFromUInt(x As QWord) As Long
     934    Return (HIDWORD(x) Xor LODWORD(x)) As Long
     935End Function
     936
     937Function _System_HashFromUInt(x As DWord) As Long
     938    Return x As Long
     939End Function
     940
    919941Function _System_HashFromPtr(p As VoidPtr) As Long
    920 #ifdef _WIN64
    921     Dim qw = p As QWord
    922     Return (HIDWORD(qw) Xor LODWORD(qw)) As Long
    923 #else
    924     Return p As Long
    925 #endif
     942    Return _System_HashFromUInt(p As ULONG_PTR)
    926943End Function
    927944
     
    952969'--------
    953970Function _System_IsSurrogatePair(wcHigh As WCHAR, wcLow As WCHAR) As Boolean
    954     If &hD800 <= wcHigh And wcHigh < &hDC00 Then
    955         If &hDC00 <= wcLow And wcLow < &hE000 Then
     971    If _System_IsHighSurrogate(wcHigh) Then
     972        If _System_IsLowSurrogate(wcLow) Then
    956973            Return True
    957974        End If
    958975    End If
    959976    Return False
     977End Function
     978
     979Function _System_IsHighSurrogate(c As WCHAR) As Boolean
     980    Return &hD800 <= c And c < &hDC00
     981End Function
     982
     983Function _System_IsLowSurrogate(c As WCHAR) As Boolean
     984    Return &hDC00 <= c And c < &hE000
    960985End Function
    961986
Note: See TracChangeset for help on using the changeset viewer.