Changeset 143 for Include/Classes


Ignore:
Timestamp:
Mar 10, 2007, 11:33:10 PM (18 years ago)
Author:
イグトランス (egtra)
Message:

GetHashCodeを実装

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Include/Classes/System/String.ab

    r142 r143  
    565565    End Function
    566566
     567    Override Function GetHashCode() As Long
     568#ifdef __STRING_IS_NOT_UNICODE
     569        Dim size = (m_Length + 1) >> 1
     570#else
     571        Dim size = m_Length
     572#endif
     573        Dim hash = 0 As DWord
     574        Dim p = Chars As *Word
     575        Dim i As Long
     576        For i = 0 To ELM(size)
     577            hash = ((hash << 16) + p[i]) Mod &h7fffffff
     578        Next
     579        Return hash As Long
     580    End Function
    567581Private
    568582    ' メモリ確保に失敗すると元の文字列は失われない。(例外安全でいう強い保障)
     
    604618
    605619End Class
    606 
    607 Function GetMultiByteStr(ByRef s As String) As PCSTR
    608 #ifdef __STRING_IS_NOT_UNICODE
    609     GetMultiByteStr = s.Chars
    610 #else
    611     Dim sizeA = WideCharToMultiByte(CP_THREAD_ACP, 0, s.Chars, s.Length + 1, 0, 0, 0, 0)
    612     GetMultiByteStr = GC_malloc_atomic(SizeOf (SByte) * sizeA)
    613     WideCharToMultiByte(CP_THREAD_ACP, 0, s.Chars, s.Length + 1, GetMultiByteStr, sizeA, 0, 0)
    614 #endif
    615 End Function
    616 
    617 Function GetWideCharStr(ByRef s As String) As PCSTR
    618 #ifdef __STRING_IS_NOT_UNICODE
    619     Dim sizeW = MultiByteToWideChar(CP_THREAD_ACP, 0, s.Chars, s.Length + 1, 0, 0)
    620     GetWideCharStr = GC_malloc_atomic(SizeOf (WCHAR) * sizeW)
    621     MultiByteToWideChar(CP_THREAD_ACP, 0, s.Chars, s.Length + 1, GetWideCharStr, sizeW)
    622 #else
    623     GetMultiByteStr = s.Chars
    624 #endif
    625 End Function
    626 
Note: See TracChangeset for help on using the changeset viewer.