[1] | 1 | 'function.sbp
|
---|
| 2 |
|
---|
| 3 |
|
---|
| 4 | #ifndef _INC_FUNCTION
|
---|
| 5 | #define _INC_FUNCTION
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | Const _System_PI = 3.14159265358979323846264
|
---|
| 9 | Const _System_LOG2 = 0.6931471805599453094172321214581765680755
|
---|
| 10 | Const _System_SQRT2 = 1.41421356237309504880168872421
|
---|
[257] | 11 | Const _System_Log_N = 7 As Long
|
---|
[1] | 12 |
|
---|
| 13 |
|
---|
[167] | 14 | #require <Classes/System/Math.ab>
|
---|
[272] | 15 | #require <Classes/System/DateTime.ab>
|
---|
| 16 | #require <Classes/System/Text/StringBuilder.ab>
|
---|
[269] | 17 | #require <Classes/ActiveBasic/Math/Math.ab>
|
---|
[272] | 18 | #require <Classes/ActiveBasic/Strings/Strings.ab>
|
---|
[16] | 19 |
|
---|
| 20 |
|
---|
[1] | 21 | '------------- サポート関数の定義 -------------
|
---|
| 22 |
|
---|
| 23 | Function ldexp(x As Double, n As Long) As Double
|
---|
| 24 | If x = 0 Then
|
---|
| 25 | ldexp = 0
|
---|
| 26 | Exit Function
|
---|
| 27 | End If
|
---|
[257] | 28 | Dim pSrc = VarPtr(x) As *QWord
|
---|
| 29 | Dim pDest = VarPtr(ldexp) As *QWord
|
---|
[1] | 30 | n += (pSrc[0] >> 52) As DWord And &h7FF
|
---|
| 31 | pDest[0] = n << 52 Or (pSrc[0] And &h800FFFFFFFFFFFFF)
|
---|
| 32 | End Function
|
---|
| 33 |
|
---|
| 34 | Function frexp(x As Double, ByRef n As Long) As Double
|
---|
| 35 | If x = 0 Then
|
---|
| 36 | n = 0
|
---|
| 37 | frexp = 0
|
---|
| 38 | Exit Function
|
---|
| 39 | End If
|
---|
| 40 |
|
---|
[257] | 41 | Dim pSrc = VarPtr(x) As *QWord
|
---|
| 42 | Dim pDest = VarPtr(frexp) As *QWord
|
---|
[1] | 43 | n = ((pSrc[0] >> 52) As DWord And &h7FF) - 1022
|
---|
| 44 | pDest[0] = (pSrc[0] And &h800FFFFFFFFFFFFF) Or &h3FE0000000000000
|
---|
| 45 | End Function
|
---|
| 46 |
|
---|
| 47 | Function frexp(x As Single, ByRef n As Long) As Single
|
---|
| 48 | If x = 0 Then
|
---|
| 49 | n = 0
|
---|
| 50 | frexp = 0
|
---|
| 51 | Exit Function
|
---|
| 52 | End If
|
---|
| 53 |
|
---|
| 54 | Dim pSrc As *DWord, pDest As *DWord
|
---|
| 55 | pSrc = VarPtr(x) As *DWord
|
---|
| 56 | pDest = VarPtr(frexp) As *DWord
|
---|
| 57 | n = ((pSrc[0] >> 23) And &hFF) - 126
|
---|
| 58 | pDest[0] = (pSrc[0] And &h807FFFFF) Or &h7E000000
|
---|
| 59 | End Function
|
---|
| 60 |
|
---|
| 61 | Function ipow(x As Double, n As Long) As Double
|
---|
| 62 | Dim abs_n As Long
|
---|
[10] | 63 | Dim r = 1 As Double
|
---|
[1] | 64 |
|
---|
| 65 | abs_n=Abs(n) As Long
|
---|
| 66 | While abs_n<>0
|
---|
[10] | 67 | If abs_n and 1 Then r *= x
|
---|
[1] | 68 | x = x * x
|
---|
| 69 | abs_n >>= 1 ' abs_n \= 2
|
---|
| 70 | Wend
|
---|
| 71 |
|
---|
| 72 | If n>=0 Then
|
---|
| 73 | ipow=r
|
---|
| 74 | Else
|
---|
| 75 | ipow=1/r
|
---|
| 76 | End If
|
---|
| 77 | End Function
|
---|
| 78 |
|
---|
| 79 | Function pow(x As Double, y As Double) As Double
|
---|
[388] | 80 | ' If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
|
---|
| 81 | If y = (y As Long) Then
|
---|
| 82 | pow = ipow(x, y As Long)
|
---|
| 83 | ElseIf x>0 Then
|
---|
| 84 | pow = Exp(y * Log(x))
|
---|
[1] | 85 | Exit Function
|
---|
[388] | 86 | ElseIf x<>0 or y<=0 Then
|
---|
| 87 | pow = ActiveBasic.Math.Detail.GetNaN()
|
---|
| 88 | Else
|
---|
| 89 | pow = 0
|
---|
[1] | 90 | End If
|
---|
| 91 | End Function
|
---|
| 92 |
|
---|
[272] | 93 | Const RAND_MAX = &H7FFFFFFF
|
---|
| 94 | Dim _System_RndNext = 1 As DWord
|
---|
[1] | 95 |
|
---|
| 96 | Function rand() As Long
|
---|
| 97 | _System_RndNext = _System_RndNext * 1103515245 + 12345
|
---|
[272] | 98 | rand = (_System_RndNext >> 1) As Long
|
---|
[1] | 99 | End Function
|
---|
| 100 |
|
---|
| 101 | Sub srand(dwSeek As DWord)
|
---|
| 102 | _System_RndNext = dwSeek
|
---|
| 103 | End Sub
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | '------------- ここからBasic標準関数の定義 -------------
|
---|
| 107 |
|
---|
| 108 | '------------------
|
---|
| 109 | ' データ型変換関数
|
---|
| 110 | '------------------
|
---|
| 111 |
|
---|
| 112 | Function CDbl(number As Double) As Double
|
---|
| 113 | CDbl=number
|
---|
| 114 | End Function
|
---|
| 115 |
|
---|
| 116 | Function _CUDbl(number As QWord) As Double
|
---|
| 117 | _CUDbl=number As Double
|
---|
| 118 | End Function
|
---|
| 119 |
|
---|
| 120 | Function CDWord(num As Double) As DWord
|
---|
[92] | 121 | CDWord=num As DWord
|
---|
[1] | 122 | End Function
|
---|
| 123 |
|
---|
| 124 | Function CInt(number As Double) As Long
|
---|
[92] | 125 | CInt=number As Long
|
---|
[1] | 126 | End Function
|
---|
| 127 |
|
---|
| 128 | Function CSng(number As Double) As Single
|
---|
[92] | 129 | CSng=number As Single
|
---|
[1] | 130 | End Function
|
---|
| 131 |
|
---|
| 132 | #ifdef _WIN64
|
---|
| 133 | Function Fix(number As Double) As Long
|
---|
| 134 | Fix=number As Long
|
---|
| 135 | End Function
|
---|
| 136 | #else
|
---|
| 137 | 'Fix関数はコンパイラに組み込まれている
|
---|
| 138 | 'Function Fix(number As Double) As Long
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | Function Int(number As Double) As Long
|
---|
[269] | 142 | Int = Fix(number)
|
---|
| 143 | If number < 0 Then
|
---|
| 144 | If number < Fix(number) Then Int--
|
---|
[1] | 145 | End If
|
---|
| 146 | End Function
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | '-------------------------------------
|
---|
| 150 | ' ポインタ関数(コンパイラに組み込み)
|
---|
| 151 | '-------------------------------------
|
---|
| 152 |
|
---|
| 153 | 'Function GetDouble(p As DWord) As Double
|
---|
| 154 | 'Function GetSingle(p As DWord) As Single
|
---|
| 155 | 'Function GetDWord(p As DWord) As DWord
|
---|
| 156 | 'Function GetWord(p As DWord) As Word
|
---|
| 157 | 'Function GetByte(p As DWord) As Byte
|
---|
| 158 | 'Sub SetDouble(p As DWord, dblData As Double)
|
---|
| 159 | 'Sub SetSingle(p As DWord, fltData As Single)
|
---|
| 160 | 'Sub SetDWord(p As DWord, dwData As DWord)
|
---|
| 161 | 'Sub SetWord(p As DWord, wData As Word)
|
---|
| 162 | 'Sub SetByte(p As DWord, byteData As Byte)
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | '----------
|
---|
| 166 | ' 算術関数
|
---|
| 167 | '----------
|
---|
| 168 |
|
---|
| 169 | Function Abs(number As Double) As Double
|
---|
[269] | 170 | 'Abs = System.Math.Abs(number)
|
---|
[1] | 171 | If number < 0 then
|
---|
[383] | 172 | Abs = -number
|
---|
[1] | 173 | Else
|
---|
[383] | 174 | Abs = number
|
---|
[1] | 175 | End If
|
---|
| 176 | End Function
|
---|
| 177 |
|
---|
[383] | 178 | Function Abs(number As Int64) As Int64
|
---|
| 179 | If number < 0 then
|
---|
| 180 | Abs = -number
|
---|
| 181 | Else
|
---|
| 182 | Abs = number
|
---|
| 183 | End If
|
---|
| 184 | End Function
|
---|
| 185 |
|
---|
| 186 | Function Abs(number As Long) As Long
|
---|
| 187 | If number < 0 then
|
---|
| 188 | Abs = -number
|
---|
| 189 | Else
|
---|
| 190 | Abs = number
|
---|
| 191 | End If
|
---|
| 192 | End Function
|
---|
| 193 |
|
---|
[1] | 194 | Function Exp(x As Double) As Double
|
---|
[269] | 195 | Exp = System.Math.Exp(x)
|
---|
[1] | 196 | End Function
|
---|
| 197 |
|
---|
| 198 | Function Log(x As Double) As Double
|
---|
[269] | 199 | Log = System.Math.Log(x)
|
---|
[1] | 200 | End Function
|
---|
| 201 |
|
---|
| 202 | Function Sgn(number As Double) As Long
|
---|
[269] | 203 | Sgn = System.Math.Sign(number)
|
---|
[1] | 204 | End Function
|
---|
| 205 |
|
---|
| 206 | Function Sqr(number As Double) As Double
|
---|
[269] | 207 | Sqr = System.Math.Sqrt(number)
|
---|
[1] | 208 | End Function
|
---|
| 209 |
|
---|
| 210 | Function Atn(number As Double) As Double
|
---|
[269] | 211 | Atn = System.Math.Atan(number)
|
---|
[1] | 212 | End Function
|
---|
| 213 |
|
---|
| 214 | Function Atn2(y As Double, x As Double) As Double
|
---|
[269] | 215 | Atn2 = System.Math.Atan2(y, x)
|
---|
[1] | 216 | End Function
|
---|
| 217 |
|
---|
| 218 | Function Sin(number As Double) As Double
|
---|
[269] | 219 | Sin = System.Math.Sin(number)
|
---|
[1] | 220 | End Function
|
---|
| 221 |
|
---|
| 222 | Function Cos(number As Double) As Double
|
---|
[269] | 223 | Cos = System.Math.Cos(number)
|
---|
[1] | 224 | End Function
|
---|
| 225 |
|
---|
| 226 | Function Tan(number As Double) As Double
|
---|
[269] | 227 | Tan = System.Math.Tan(number)
|
---|
[1] | 228 | End Function
|
---|
| 229 |
|
---|
| 230 | Const RAND_UNIT = (1.0 / (LONG_MAX + 1.0))
|
---|
| 231 | Function Rnd() As Double
|
---|
| 232 | Rnd = RAND_UNIT * rand()
|
---|
| 233 | End Function
|
---|
| 234 |
|
---|
[167] | 235 | Const HIDWORD(qw) = (((qw As QWord) >> 32) And &HFFFFFFFF) As DWord
|
---|
| 236 | Const LODWORD(qw) = ((qw As QWord) And &HFFFFFFFF) As DWord
|
---|
[1] | 237 |
|
---|
[167] | 238 | Const MAKEDWORD(l, h) = (((l As DWord) And &HFFFF) Or (((h As DWord) And &HFFFF) << 16)) As DWord
|
---|
| 239 | Const MAKEQWORD(l, h) = (((l As QWord) And &HFFFFFFFF) Or (((h As QWord) And &HFFFFFFFF) << 32)) As QWord
|
---|
[1] | 240 |
|
---|
| 241 | '------------
|
---|
| 242 | ' 文字列関数
|
---|
| 243 | '------------
|
---|
| 244 |
|
---|
[394] | 245 | Function Asc(buf As String) As StrChar
|
---|
[1] | 246 | Asc = buf[0]
|
---|
| 247 | End Function
|
---|
| 248 |
|
---|
[142] | 249 | Function Chr$(code As StrChar) As String
|
---|
[272] | 250 | Chr$ = New String(code, 1)
|
---|
[1] | 251 | End Function
|
---|
| 252 |
|
---|
[142] | 253 | #ifndef __STRING_IS_NOT_UNICODE
|
---|
[383] | 254 | Function AscW(s As String) As UCSCHAR
|
---|
[394] | 255 | If String.IsNullOrEmpty(s) Then
|
---|
[121] | 256 | AscW = 0
|
---|
[394] | 257 | 'ArgumentNullExceptionに変えるかも
|
---|
[121] | 258 | Else
|
---|
[394] | 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)
|
---|
[400] | 265 | AscW += &h10000
|
---|
[394] | 266 | Exit Function
|
---|
| 267 | End If
|
---|
| 268 | End If
|
---|
[121] | 269 | Else
|
---|
| 270 | AscW = s[0]
|
---|
| 271 | End If
|
---|
| 272 | End If
|
---|
| 273 | End Function
|
---|
| 274 |
|
---|
| 275 | Function ChrW(c As UCSCHAR) As String
|
---|
| 276 | If c <= &hFFFF Then
|
---|
[272] | 277 | Return New String(c As StrChar, 1)
|
---|
[394] | 278 | ElseIf c <= &h10FFFF Then
|
---|
[400] | 279 | c -= &h10000
|
---|
[394] | 280 | Dim t[1] As WCHAR
|
---|
| 281 | t[0] = (&hD800 Or (c >> 10)) As WCHAR
|
---|
| 282 | t[1] = (&hDC00 Or (c And &h3FF)) As WCHAR
|
---|
[272] | 283 | Return New String(t, 2)
|
---|
[121] | 284 | Else
|
---|
[394] | 285 | Throw New System.ArgumentOutOfRangeException("ChrW: c is invalid Unicode code point.", "c")
|
---|
[121] | 286 | End If
|
---|
| 287 | End Function
|
---|
| 288 | #endif
|
---|
| 289 |
|
---|
[1] | 290 | Function Date$() As String
|
---|
[289] | 291 | Dim date = System.DateTime.Now
|
---|
[272] | 292 | Dim buf = New System.Text.StringBuilder(10)
|
---|
[1] | 293 |
|
---|
| 294 | 'year
|
---|
[272] | 295 | buf.Append(date.Year)
|
---|
[1] | 296 |
|
---|
| 297 | 'month
|
---|
[272] | 298 | If date.Month < 10 Then
|
---|
| 299 | buf.Append("/0")
|
---|
[1] | 300 | Else
|
---|
[272] | 301 | buf.Append("/")
|
---|
[1] | 302 | End If
|
---|
[272] | 303 | buf.Append(date.Month)
|
---|
[1] | 304 |
|
---|
| 305 | 'day
|
---|
[272] | 306 | If date.Day < 10 Then
|
---|
| 307 | buf.Append("/0")
|
---|
[1] | 308 | Else
|
---|
[272] | 309 | buf.Append("/")
|
---|
[1] | 310 | End If
|
---|
[272] | 311 | buf.Append(date.Day)
|
---|
| 312 |
|
---|
| 313 | Date$ = buf.ToString
|
---|
[1] | 314 | End Function
|
---|
| 315 |
|
---|
[167] | 316 | Function Hex$(x As DWord) As String
|
---|
[388] | 317 | Imports ActiveBasic.Strings.Detail
|
---|
| 318 | Hex$ = FormatIntegerX(x, 1, 0, None)
|
---|
[167] | 319 | End Function
|
---|
| 320 |
|
---|
[121] | 321 | Function Hex$(x As QWord) As String
|
---|
[388] | 322 | Imports ActiveBasic.Strings.Detail
|
---|
| 323 | Hex$ = FormatIntegerLX(x, 1, 0, None)
|
---|
[1] | 324 | End Function
|
---|
| 325 |
|
---|
| 326 | Function InStr(StartPos As Long, buf1 As String, buf2 As String) As Long
|
---|
[167] | 327 | Dim i As Long, i2 As Long, i3 As Long
|
---|
[1] | 328 |
|
---|
[167] | 329 | Dim len1 = buf1.Length
|
---|
| 330 | Dim len2 = buf2.Length
|
---|
[1] | 331 |
|
---|
| 332 | If len2=0 Then
|
---|
| 333 | InStr=StartPos
|
---|
| 334 | Exit Function
|
---|
| 335 | End If
|
---|
| 336 |
|
---|
[10] | 337 | StartPos--
|
---|
[1] | 338 | If StartPos<0 Then
|
---|
| 339 | 'error
|
---|
| 340 | InStr=0
|
---|
| 341 | Exit Function
|
---|
| 342 | End If
|
---|
| 343 |
|
---|
| 344 | i=StartPos:InStr=0
|
---|
| 345 | While i<=len1-len2
|
---|
| 346 | i2=i:i3=0
|
---|
| 347 | Do
|
---|
| 348 | If i3=len2 Then
|
---|
| 349 | InStr=i+1
|
---|
| 350 | Exit Do
|
---|
| 351 | End If
|
---|
| 352 | If buf1[i2]<>buf2[i3] Then Exit Do
|
---|
| 353 |
|
---|
[10] | 354 | i2++
|
---|
| 355 | i3++
|
---|
[1] | 356 | Loop
|
---|
| 357 | If InStr Then Exit While
|
---|
[10] | 358 | i++
|
---|
[1] | 359 | Wend
|
---|
| 360 | End Function
|
---|
| 361 |
|
---|
[272] | 362 | Function Left$(s As String, length As Long) As String
|
---|
| 363 | Left$ = s.Substring(0, System.Math.Min(s.Length, length))
|
---|
[1] | 364 | End Function
|
---|
| 365 |
|
---|
[272] | 366 | Function Mid$(s As String, startPos As Long) As String
|
---|
| 367 | startPos--
|
---|
| 368 | Mid$ = s.Substring(startPos)
|
---|
| 369 | End Function
|
---|
[1] | 370 |
|
---|
[272] | 371 | Function Mid$(s As String, startPos As Long, readLength = 0 As Long) As String
|
---|
| 372 | startPos--
|
---|
| 373 | Dim length = s.Length
|
---|
| 374 | Mid$ = s.Substring(System.Math.Min(startPos, length), System.Math.Min(readLength, length - startPos))
|
---|
[1] | 375 | End Function
|
---|
| 376 |
|
---|
[272] | 377 | Function Oct$(n As QWord) As String
|
---|
[388] | 378 | Imports ActiveBasic.Strings.Detail
|
---|
| 379 | Oct$ = FormatIntegerLO(n, 1, 0, None)
|
---|
[272] | 380 | End Function
|
---|
[1] | 381 |
|
---|
[272] | 382 | Function Oct$(n As DWord) As String
|
---|
[388] | 383 | Imports ActiveBasic.Strings.Detail
|
---|
| 384 | Oct$ = FormatIntegerO(n, 1, 0, None)
|
---|
[1] | 385 | End Function
|
---|
| 386 |
|
---|
[272] | 387 | Function Right$(s As String, length As Long) As String
|
---|
| 388 | Right$ = s.Substring(System.Math.Max(0, s.Length - length), s.Length)
|
---|
[1] | 389 | End Function
|
---|
| 390 |
|
---|
| 391 | Function Space$(length As Long) As String
|
---|
[208] | 392 | Return New String(&h20 As StrChar, length)
|
---|
[1] | 393 | End Function
|
---|
| 394 |
|
---|
[385] | 395 | Sub _ecvt_support(buf As *StrChar, count As Long, size As Long)
|
---|
[1] | 396 | Dim i As Long
|
---|
[385] | 397 | If buf[count] = 9 Then
|
---|
| 398 | buf[count] = 0
|
---|
| 399 | If count = 0 Then
|
---|
| 400 | For i = size To 1 Step -1
|
---|
| 401 | buf[i] = buf[i-1]
|
---|
[1] | 402 | Next
|
---|
[385] | 403 | buf[0] = 1
|
---|
[1] | 404 | Else
|
---|
[385] | 405 | _ecvt_support(buf, count-1, size)
|
---|
[1] | 406 | End If
|
---|
| 407 | Else
|
---|
[385] | 408 | buf[count]++
|
---|
[1] | 409 | End If
|
---|
| 410 | End Sub
|
---|
[385] | 411 |
|
---|
| 412 | Sub _ecvt(buffer As *StrChar, value As Double, count As Long, ByRef dec As Long, ByRef sign As Boolean)
|
---|
[1] | 413 | Dim i As Long, i2 As Long
|
---|
| 414 |
|
---|
| 415 | '値が0の場合
|
---|
[167] | 416 | If value = 0 Then
|
---|
[385] | 417 | ActiveBasic.Strings.ChrFill(buffer, count As SIZE_T, &h30 As StrChar)
|
---|
| 418 | buffer[count] = 0
|
---|
[123] | 419 | dec = 0
|
---|
| 420 | sign = 0
|
---|
[1] | 421 | Exit Function
|
---|
| 422 | End If
|
---|
| 423 |
|
---|
| 424 | '符号の判断(同時に符号を取り除く)
|
---|
[167] | 425 | If value < 0 Then
|
---|
[385] | 426 | sign = True
|
---|
[167] | 427 | value = -value
|
---|
[1] | 428 | Else
|
---|
[385] | 429 | sign = False
|
---|
[1] | 430 | End If
|
---|
| 431 |
|
---|
| 432 | '正規化
|
---|
[167] | 433 | dec = 1
|
---|
| 434 | While value < 0.999999999999999 'value<1
|
---|
[119] | 435 | value *= 10
|
---|
| 436 | dec--
|
---|
[1] | 437 | Wend
|
---|
[167] | 438 | While 9.99999999999999 <= value '10<=value
|
---|
[119] | 439 | value /= 10
|
---|
| 440 | dec++
|
---|
[1] | 441 | Wend
|
---|
| 442 |
|
---|
[385] | 443 | For i = 0 To count - 1
|
---|
| 444 | buffer[i] = Int(value) As StrChar
|
---|
[167] | 445 | value = (value-CDbl(Int(value))) * 10
|
---|
[1] | 446 | Next
|
---|
| 447 |
|
---|
[119] | 448 | i--
|
---|
[167] | 449 | If value >= 5 Then
|
---|
[1] | 450 | '切り上げ処理
|
---|
[385] | 451 | _ecvt_support(buffer, i, count)
|
---|
[1] | 452 | End If
|
---|
| 453 |
|
---|
[385] | 454 | For i = 0 To count - 1
|
---|
| 455 | buffer[i] += &H30
|
---|
[1] | 456 | Next
|
---|
[385] | 457 | buffer[i] = 0
|
---|
| 458 | End Sub
|
---|
[1] | 459 |
|
---|
| 460 | Function Str$(dbl As Double) As String
|
---|
[388] | 461 | Imports ActiveBasic.Math
|
---|
| 462 | Imports ActiveBasic.Strings
|
---|
| 463 | If IsNaN(dbl) Then
|
---|
[1] | 464 | Return "NaN"
|
---|
[388] | 465 | ElseIf IsInf(dbl) Then
|
---|
[1] | 466 | If dbl > 0 Then
|
---|
| 467 | Return "Infinity"
|
---|
| 468 | Else
|
---|
| 469 | Return "-Infinity"
|
---|
| 470 | End If
|
---|
| 471 | End If
|
---|
[385] | 472 | Dim dec As Long, sign As Boolean
|
---|
| 473 | Dim buffer[32] As StrChar, temp[15] As StrChar
|
---|
| 474 | Dim i = 0 As Long
|
---|
[1] | 475 |
|
---|
| 476 | '浮動小数点を文字列に変換
|
---|
[385] | 477 | _ecvt(temp, dbl, 15, dec, sign)
|
---|
[1] | 478 |
|
---|
| 479 | '符号の取り付け
|
---|
| 480 | If sign Then
|
---|
[167] | 481 | buffer[i] = Asc("-")
|
---|
[10] | 482 | i++
|
---|
[1] | 483 | End If
|
---|
| 484 |
|
---|
[385] | 485 | If dec > 15 Or dec < -3 Then
|
---|
| 486 | '指数表示
|
---|
[167] | 487 | buffer[i] = temp[0]
|
---|
[10] | 488 | i++
|
---|
[167] | 489 | buffer[i] = Asc(".")
|
---|
[10] | 490 | i++
|
---|
[388] | 491 | ChrCopy(VarPtr(buffer[i]), VarPtr(temp[1]), 14 As SIZE_T)
|
---|
[167] | 492 | i += 14
|
---|
[385] | 493 | buffer[i] = 0
|
---|
[388] | 494 | Return MakeStr(buffer) + SPrintf("e%+03d", New System.Int32(dec - 1))
|
---|
[1] | 495 | End If
|
---|
| 496 |
|
---|
| 497 | '整数部
|
---|
[385] | 498 | Dim i2 = dec
|
---|
| 499 | Dim i3 = 0
|
---|
[1] | 500 | If i2>0 Then
|
---|
| 501 | While i2>0
|
---|
| 502 | buffer[i]=temp[i3]
|
---|
[10] | 503 | i++
|
---|
| 504 | i3++
|
---|
| 505 | i2--
|
---|
[1] | 506 | Wend
|
---|
| 507 | buffer[i]=Asc(".")
|
---|
[10] | 508 | i++
|
---|
[1] | 509 | Else
|
---|
| 510 | buffer[i]=&H30
|
---|
[10] | 511 | i++
|
---|
[1] | 512 | buffer[i]=Asc(".")
|
---|
[10] | 513 | i++
|
---|
[1] | 514 |
|
---|
| 515 | i2=dec
|
---|
| 516 | While i2<0
|
---|
| 517 | buffer[i]=&H30
|
---|
[10] | 518 | i++
|
---|
| 519 | i2++
|
---|
[1] | 520 | Wend
|
---|
| 521 | End If
|
---|
| 522 |
|
---|
| 523 | '小数部
|
---|
| 524 | While i3<15
|
---|
| 525 | buffer[i]=temp[i3]
|
---|
[10] | 526 | i++
|
---|
| 527 | i3++
|
---|
[1] | 528 | Wend
|
---|
| 529 |
|
---|
| 530 | While buffer[i-1]=&H30
|
---|
[10] | 531 | i--
|
---|
[1] | 532 | Wend
|
---|
[10] | 533 | If buffer[i-1]=Asc(".") Then i--
|
---|
[1] | 534 |
|
---|
| 535 | buffer[i]=0
|
---|
| 536 | Return MakeStr(buffer)
|
---|
| 537 | End Function
|
---|
[167] | 538 |
|
---|
[385] | 539 | Function Str$(x As Int64) As String
|
---|
| 540 | Imports ActiveBasic.Strings.Detail
|
---|
| 541 | Return FormatIntegerEx(TraitsIntegerD[1], x As QWord, 1, 0, None)
|
---|
[1] | 542 | End Function
|
---|
| 543 |
|
---|
[269] | 544 | Function Str$(x As QWord) As String
|
---|
[385] | 545 | Imports ActiveBasic.Strings.Detail
|
---|
| 546 | Return FormatIntegerEx(TraitsIntegerU[1], x, 1, 0, None)
|
---|
[269] | 547 | End Function
|
---|
| 548 |
|
---|
| 549 | Function Str$(x As Long) As String
|
---|
[385] | 550 | Imports ActiveBasic.Strings.Detail
|
---|
| 551 | Return FormatIntegerEx(TraitsIntegerD[0], x, 1, 0, None)
|
---|
[269] | 552 | End Function
|
---|
| 553 |
|
---|
| 554 | Function Str$(x As DWord) As String
|
---|
[385] | 555 | Imports ActiveBasic.Strings.Detail
|
---|
| 556 | Return FormatIntegerEx(TraitsIntegerU[0], x, 1, 0, None)
|
---|
[269] | 557 | End Function
|
---|
| 558 |
|
---|
| 559 | Function Str$(x As Word) As String
|
---|
[385] | 560 | Return Str$(x As DWord)
|
---|
[269] | 561 | End Function
|
---|
| 562 |
|
---|
| 563 | Function Str$(x As Integer) As String
|
---|
[385] | 564 | Return Str$(x As Long)
|
---|
[269] | 565 | End Function
|
---|
| 566 |
|
---|
| 567 | Function Str$(x As Byte) As String
|
---|
[385] | 568 | Return Str$(x As DWord)
|
---|
[269] | 569 | End Function
|
---|
| 570 |
|
---|
| 571 | Function Str$(x As SByte) As String
|
---|
[385] | 572 | Return Str$(x As Long)
|
---|
[269] | 573 | End Function
|
---|
| 574 |
|
---|
| 575 | Function Str$(x As Single) As String
|
---|
| 576 | Return Str$(x As Double)
|
---|
| 577 | End Function
|
---|
| 578 |
|
---|
| 579 | Function Str$(b As Boolean) As String
|
---|
| 580 | If b Then
|
---|
| 581 | Return "True"
|
---|
| 582 | Else
|
---|
| 583 | Return "False"
|
---|
| 584 | End If
|
---|
| 585 | End Function
|
---|
| 586 |
|
---|
[272] | 587 | Function String$(n As Long, s As StrChar) As String
|
---|
| 588 | Return New String(s, n)
|
---|
| 589 | End Function
|
---|
| 590 |
|
---|
| 591 | #ifdef _AB4_COMPATIBILITY_STRING$_
|
---|
| 592 | Function String$(n As Long, s As String) As String
|
---|
| 593 | If n < 0 Then
|
---|
| 594 | 'Throw ArgumentOutOfRangeException
|
---|
| 595 | End If
|
---|
[1] | 596 |
|
---|
[272] | 597 | Dim buf = New System.Text.StringBuilder(s.Length * n)
|
---|
[1] | 598 | Dim i As Long
|
---|
[272] | 599 | For i = 0 To n
|
---|
| 600 | buf.Append(s)
|
---|
[1] | 601 | Next
|
---|
| 602 | End Function
|
---|
[272] | 603 | #else
|
---|
| 604 | Function String$(n As Long, s As String) As String
|
---|
| 605 | If String.IsNullOrEmpty(s) Then
|
---|
| 606 | Return New String(0 As StrChar, n)
|
---|
[388] | 607 | Else
|
---|
[272] | 608 | Return New String(s[0], n)
|
---|
| 609 | End If
|
---|
| 610 | End Function
|
---|
| 611 | #endif
|
---|
[1] | 612 |
|
---|
| 613 | Function Time$() As String
|
---|
[289] | 614 | Dim time = System.DateTime.Now
|
---|
[1] | 615 |
|
---|
[272] | 616 | Dim buf = New System.Text.StringBuilder(8)
|
---|
[1] | 617 |
|
---|
| 618 | 'hour
|
---|
[272] | 619 | If time.Hour < 10 Then
|
---|
| 620 | buf.Append("0")
|
---|
[1] | 621 | End If
|
---|
[272] | 622 | buf.Append(time.Hour)
|
---|
[1] | 623 |
|
---|
| 624 | 'minute
|
---|
[272] | 625 | If time.Minute < 10 Then
|
---|
| 626 | buf.Append(":0")
|
---|
[1] | 627 | Else
|
---|
[272] | 628 | buf.Append(":")
|
---|
[1] | 629 | End If
|
---|
[272] | 630 | buf.Append(time.Minute)
|
---|
[1] | 631 |
|
---|
| 632 | 'second
|
---|
[272] | 633 | If time.Second < 10 Then
|
---|
| 634 | buf.Append(":0")
|
---|
[1] | 635 | Else
|
---|
[272] | 636 | buf.Append(":")
|
---|
[1] | 637 | End If
|
---|
[272] | 638 | buf.Append(time.Second)
|
---|
| 639 | Time$ = buf.ToString
|
---|
[1] | 640 | End Function
|
---|
| 641 |
|
---|
[167] | 642 | Function Val(buf As *StrChar) As Double
|
---|
[1] | 643 | Dim i As Long, i2 As Long, i3 As Long, i4 As Long
|
---|
| 644 | Dim temporary As String
|
---|
[167] | 645 | Dim TempPtr As *StrChar
|
---|
[1] | 646 | Dim dbl As Double
|
---|
| 647 | Dim i64data As Int64
|
---|
| 648 |
|
---|
| 649 | Val=0
|
---|
| 650 |
|
---|
[400] | 651 | While ActiveBasic.CType.IsSpace(buf[0])
|
---|
[269] | 652 | buf = VarPtr(buf[1])
|
---|
[1] | 653 | Wend
|
---|
| 654 |
|
---|
| 655 | If buf[0]=Asc("&") Then
|
---|
[145] | 656 | temporary = New String( buf )
|
---|
[272] | 657 | temporary = temporary.ToUpper()
|
---|
[123] | 658 | TempPtr = StrPtr(temporary)
|
---|
[400] | 659 | If TempPtr(1) = Asc("O") Then
|
---|
[1] | 660 | '8進数
|
---|
| 661 | i=2
|
---|
| 662 | While 1
|
---|
| 663 | '数字以外の文字の場合は抜け出す
|
---|
| 664 | i3=TempPtr[i]-&H30
|
---|
| 665 | If Not (0<=i3 And i3<=7) Then Exit While
|
---|
| 666 |
|
---|
[167] | 667 | TempPtr[i]=i3 As StrChar
|
---|
[1] | 668 | i++
|
---|
| 669 | Wend
|
---|
| 670 | i--
|
---|
| 671 |
|
---|
| 672 | i64data=1
|
---|
| 673 | While i>=2
|
---|
[214] | 674 | Val += ( i64data * TempPtr[i] ) As Double
|
---|
[1] | 675 |
|
---|
[123] | 676 | i64data *= &O10
|
---|
[10] | 677 | i--
|
---|
[1] | 678 | Wend
|
---|
| 679 | ElseIf TempPtr(1)=Asc("H") Then
|
---|
| 680 | '16進数
|
---|
| 681 | i=2
|
---|
| 682 | While 1
|
---|
| 683 | '数字以外の文字の場合は抜け出す
|
---|
| 684 | i3=TempPtr[i]-&H30
|
---|
| 685 | If Not(0<=i3 and i3<=9) Then
|
---|
| 686 | i3=TempPtr[i]-&H41+10
|
---|
| 687 | If Not(&HA<=i3 and i3<=&HF) Then Exit While
|
---|
| 688 | End If
|
---|
| 689 |
|
---|
[167] | 690 | TempPtr[i]=i3 As StrChar
|
---|
[1] | 691 | i++
|
---|
| 692 | Wend
|
---|
| 693 | i--
|
---|
| 694 |
|
---|
| 695 | i64data=1
|
---|
| 696 | While i>=2
|
---|
[22] | 697 | Val += (i64data*TempPtr[i]) As Double
|
---|
[1] | 698 |
|
---|
[10] | 699 | i64data *= &H10
|
---|
[1] | 700 | i--
|
---|
| 701 | Wend
|
---|
| 702 | End If
|
---|
| 703 | Else
|
---|
| 704 | '10進数
|
---|
[394] | 705 | #ifdef __STRING_IS_NOT_UNICODE
|
---|
[251] | 706 | sscanf(buf,"%lf",VarPtr(Val))
|
---|
[394] | 707 | #else
|
---|
| 708 | swscanf(buf,ToWCStr("%lf"),VarPtr(Val))
|
---|
| 709 | #endif
|
---|
[1] | 710 | End If
|
---|
| 711 | End Function
|
---|
| 712 |
|
---|
| 713 |
|
---|
| 714 | '--------------
|
---|
| 715 | ' ファイル関数
|
---|
| 716 | '--------------
|
---|
| 717 |
|
---|
| 718 | Function Eof(FileNum As Long) As Long
|
---|
| 719 | FileNum--
|
---|
[400] | 720 | Dim dwCurrent = SetFilePointer(_System_hFile(FileNum), 0,NULL, FILE_CURRENT)
|
---|
| 721 | Dim dwEnd = SetFilePointer(_System_hFile(FileNum), 0, NULL, FILE_END)
|
---|
| 722 | SetFilePointer(_System_hFile(FileNum), dwCurrent, NULL, FILE_BEGIN)
|
---|
[1] | 723 |
|
---|
| 724 | If dwCurrent>=dwEnd Then
|
---|
| 725 | Eof=-1
|
---|
| 726 | Else
|
---|
| 727 | Eof=0
|
---|
| 728 | End If
|
---|
| 729 | End Function
|
---|
| 730 |
|
---|
| 731 | Function Lof(FileNum As Long) As Long
|
---|
[142] | 732 | Lof = GetFileSize(_System_hFile(FileNum-1), 0)
|
---|
[1] | 733 | End Function
|
---|
| 734 |
|
---|
| 735 | Function Loc(FileNum As Long) As Long
|
---|
[10] | 736 | FileNum--
|
---|
[1] | 737 |
|
---|
[272] | 738 | Dim NowPos = SetFilePointer(_System_hFile(FileNum), 0, 0, FILE_CURRENT)
|
---|
| 739 | Dim BeginPos = SetFilePointer(_System_hFile(FileNum), 0, 0, FILE_BEGIN)
|
---|
| 740 | SetFilePointer(_System_hFile(FileNum), NowPos - BeginPos, 0, FILE_BEGIN)
|
---|
[1] | 741 |
|
---|
[272] | 742 | Loc = NowPos - BeginPos
|
---|
[1] | 743 | End Function
|
---|
| 744 |
|
---|
| 745 |
|
---|
| 746 | '------------------
|
---|
| 747 | ' メモリ関連の関数
|
---|
| 748 | '------------------
|
---|
| 749 |
|
---|
| 750 | Function malloc(stSize As SIZE_T) As VoidPtr
|
---|
[145] | 751 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC)
|
---|
[1] | 752 | End Function
|
---|
| 753 |
|
---|
| 754 | Function calloc(stSize As SIZE_T) As VoidPtr
|
---|
[145] | 755 | Return _System_pGC->__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_ATOMIC or _System_GC_FLAG_INITZERO)
|
---|
[1] | 756 | End Function
|
---|
| 757 |
|
---|
| 758 | Function realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
| 759 | If lpMem = 0 Then
|
---|
| 760 | Return malloc(stSize)
|
---|
| 761 | Else
|
---|
[145] | 762 | Return _System_pGC->__realloc(lpMem,stSize)
|
---|
[1] | 763 | End If
|
---|
| 764 | End Function
|
---|
| 765 |
|
---|
| 766 | Sub free(lpMem As VoidPtr)
|
---|
[145] | 767 | _System_pGC->__free(lpMem)
|
---|
[1] | 768 | End Sub
|
---|
| 769 |
|
---|
| 770 | Function _System_malloc(stSize As SIZE_T) As VoidPtr
|
---|
[400] | 771 | Return HeapAlloc(_System_hProcessHeap, 0, stSize)
|
---|
[1] | 772 | End Function
|
---|
| 773 |
|
---|
| 774 | Function _System_calloc(stSize As SIZE_T) As VoidPtr
|
---|
[400] | 775 | Return HeapAlloc(_System_hProcessHeap, HEAP_ZERO_MEMORY, stSize)
|
---|
[1] | 776 | End Function
|
---|
| 777 |
|
---|
| 778 | Function _System_realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
| 779 | If lpMem = 0 Then
|
---|
| 780 | Return HeapAlloc(_System_hProcessHeap, 0, stSize)
|
---|
| 781 | Else
|
---|
| 782 | Return HeapReAlloc(_System_hProcessHeap, 0, lpMem, stSize)
|
---|
| 783 | End If
|
---|
| 784 | End Function
|
---|
| 785 |
|
---|
| 786 | Sub _System_free(lpMem As VoidPtr)
|
---|
[400] | 787 | HeapFree(_System_hProcessHeap, 0, lpMem)
|
---|
[1] | 788 | End Sub
|
---|
| 789 |
|
---|
| 790 |
|
---|
| 791 | '--------
|
---|
| 792 | ' その他
|
---|
| 793 | '--------
|
---|
| 794 |
|
---|
[123] | 795 | Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
|
---|
[1] | 796 | Dim i As Long, i2 As Long, i3 As Long, length As Long
|
---|
[167] | 797 | Dim buffer[MAX_PATH] As SByte
|
---|
[1] | 798 |
|
---|
| 799 | '":\"をチェック
|
---|
| 800 | If not(path[1]=&H3A and path[2]=&H5C) Then Exit Sub
|
---|
| 801 |
|
---|
| 802 | 'ドライブ名をコピー
|
---|
| 803 | If drive Then
|
---|
| 804 | drive[0]=path[0]
|
---|
| 805 | drive[1]=path[1]
|
---|
| 806 | drive[2]=0
|
---|
| 807 | End If
|
---|
| 808 |
|
---|
| 809 | 'ディレクトリ名をコピー
|
---|
| 810 | i=2
|
---|
| 811 | i2=0
|
---|
| 812 | Do
|
---|
[123] | 813 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
[1] | 814 | If dir Then
|
---|
| 815 | dir[i2]=path[i]
|
---|
| 816 | dir[i2+1]=path[i+1]
|
---|
| 817 | End If
|
---|
| 818 |
|
---|
[10] | 819 | i += 2
|
---|
| 820 | i2 += 2
|
---|
[1] | 821 | Continue
|
---|
| 822 | End If
|
---|
| 823 |
|
---|
| 824 | If path[i]=0 Then Exit Do
|
---|
| 825 |
|
---|
| 826 | If path[i]=&H5C Then '"\"記号であるかどうか
|
---|
| 827 | i3=i2+1
|
---|
| 828 | End If
|
---|
| 829 |
|
---|
| 830 | If dir Then dir[i2]=path[i]
|
---|
| 831 |
|
---|
[10] | 832 | i++
|
---|
| 833 | i2++
|
---|
[1] | 834 | Loop
|
---|
| 835 | If dir Then dir[i3]=0
|
---|
[22] | 836 | i3 += i-i2
|
---|
[1] | 837 |
|
---|
| 838 | 'ファイル名をコピー
|
---|
| 839 | i=i3
|
---|
| 840 | i2=0
|
---|
| 841 | i3=-1
|
---|
| 842 | Do
|
---|
[123] | 843 | '#ifdef UNICODE
|
---|
| 844 | ' If _System_IsSurrogatePair(path[i], path[i + 1]) Then
|
---|
| 845 | '#else
|
---|
| 846 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
| 847 | '#endif
|
---|
[1] | 848 | If fname Then
|
---|
| 849 | fname[i2]=path[i]
|
---|
| 850 | fname[i2+1]=path[i+1]
|
---|
| 851 | End If
|
---|
| 852 |
|
---|
[10] | 853 | i += 2
|
---|
| 854 | i2 += 2
|
---|
[1] | 855 | Continue
|
---|
| 856 | End If
|
---|
| 857 |
|
---|
| 858 | If path[i]=0 Then Exit Do
|
---|
| 859 |
|
---|
| 860 | If path[i]=&H2E Then '.'記号であるかどうか
|
---|
| 861 | i3=i2
|
---|
| 862 | End If
|
---|
| 863 |
|
---|
| 864 | If fname Then fname[i2]=path[i]
|
---|
| 865 |
|
---|
[10] | 866 | i++
|
---|
| 867 | i2++
|
---|
[1] | 868 | Loop
|
---|
| 869 | If i3=-1 Then i3=i2
|
---|
| 870 | If fname Then fname[i3]=0
|
---|
[10] | 871 | i3 += i-i2
|
---|
[1] | 872 |
|
---|
| 873 | '拡張子名をコピー
|
---|
| 874 | If ext Then
|
---|
| 875 | If i3 Then
|
---|
| 876 | lstrcpy(ext,path+i3)
|
---|
| 877 | End If
|
---|
| 878 | else ext[0]=0
|
---|
| 879 | End If
|
---|
| 880 | End Sub
|
---|
| 881 |
|
---|
| 882 | Function GetBasicColor(ColorCode As Long) As Long
|
---|
| 883 | Select Case ColorCode
|
---|
| 884 | Case 0
|
---|
| 885 | GetBasicColor=RGB(0,0,0)
|
---|
| 886 | Case 1
|
---|
| 887 | GetBasicColor=RGB(0,0,255)
|
---|
| 888 | Case 2
|
---|
| 889 | GetBasicColor=RGB(255,0,0)
|
---|
| 890 | Case 3
|
---|
| 891 | GetBasicColor=RGB(255,0,255)
|
---|
| 892 | Case 4
|
---|
| 893 | GetBasicColor=RGB(0,255,0)
|
---|
| 894 | Case 5
|
---|
| 895 | GetBasicColor=RGB(0,255,255)
|
---|
| 896 | Case 6
|
---|
| 897 | GetBasicColor=RGB(255,255,0)
|
---|
| 898 | Case 7
|
---|
| 899 | GetBasicColor=RGB(255,255,255)
|
---|
| 900 | End Select
|
---|
| 901 | End Function
|
---|
| 902 |
|
---|
[167] | 903 | Function _System_BSwap(x As Word) As Word
|
---|
| 904 | Dim src = VarPtr(x) As *Byte
|
---|
[223] | 905 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 906 | dst[0] = src[1]
|
---|
| 907 | dst[1] = src[0]
|
---|
| 908 | End Function
|
---|
| 909 |
|
---|
| 910 | Function _System_BSwap(x As DWord) As DWord
|
---|
| 911 | Dim src = VarPtr(x) As *Byte
|
---|
[223] | 912 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 913 | dst[0] = src[3]
|
---|
| 914 | dst[1] = src[2]
|
---|
| 915 | dst[2] = src[1]
|
---|
| 916 | dst[3] = src[0]
|
---|
| 917 | End Function
|
---|
| 918 |
|
---|
| 919 | Function _System_BSwap(x As QWord) As QWord
|
---|
| 920 | Dim src = VarPtr(x) As *Byte
|
---|
[223] | 921 | Dim dst = VarPtr(_System_BSwap) As *Byte
|
---|
[167] | 922 | dst[0] = src[7]
|
---|
| 923 | dst[1] = src[6]
|
---|
| 924 | dst[2] = src[5]
|
---|
| 925 | dst[3] = src[4]
|
---|
| 926 | dst[4] = src[3]
|
---|
| 927 | dst[5] = src[2]
|
---|
| 928 | dst[6] = src[1]
|
---|
| 929 | dst[7] = src[0]
|
---|
| 930 | End Function
|
---|
| 931 |
|
---|
[394] | 932 | Function _System_HashFromUInt(x As QWord) As Long
|
---|
| 933 | Return (HIDWORD(x) Xor LODWORD(x)) As Long
|
---|
| 934 | End Function
|
---|
| 935 |
|
---|
| 936 | Function _System_HashFromUInt(x As DWord) As Long
|
---|
| 937 | Return x As Long
|
---|
| 938 | End Function
|
---|
| 939 |
|
---|
[175] | 940 | Function _System_HashFromPtr(p As VoidPtr) As Long
|
---|
[394] | 941 | Return _System_HashFromUInt(p As ULONG_PTR)
|
---|
[175] | 942 | End Function
|
---|
| 943 |
|
---|
[355] | 944 | /*!
|
---|
[388] | 945 | @brief ObjPtrの逆。ABオブジェクトを指すポインタをObject型へ変換。
|
---|
[355] | 946 | @author Egtra
|
---|
| 947 | @date 2007/08/24
|
---|
[457] | 948 | @param[in] p オブジェクトを指すポインタ
|
---|
[355] | 949 | @return Object参照型
|
---|
| 950 | */
|
---|
[303] | 951 | Function _System_PtrObj(p As VoidPtr) As Object
|
---|
| 952 | SetPointer(VarPtr(_System_PtrObj), p)
|
---|
| 953 | End Function
|
---|
| 954 |
|
---|
[355] | 955 | /*!
|
---|
| 956 | @brief IUnknownその他COMインタフェースを指すポインタをIUnknown参照型へ変換。
|
---|
| 957 | @author Egtra
|
---|
| 958 | @date 2007/09/24
|
---|
| 959 | @param[in] p COMインタフェースを指すポインタ
|
---|
| 960 | @return IUnknown参照型
|
---|
| 961 | */
|
---|
| 962 | Function _System_PtrUnknown(p As VoidPtr) As IUnknown
|
---|
| 963 | SetPointer(VarPtr(_System_PtrUnknown), p)
|
---|
| 964 | End Function
|
---|
| 965 |
|
---|
[142] | 966 | '--------
|
---|
| 967 | ' 文字列関数その2
|
---|
| 968 | '--------
|
---|
[119] | 969 | Function _System_IsSurrogatePair(wcHigh As WCHAR, wcLow As WCHAR) As Boolean
|
---|
[394] | 970 | If _System_IsHighSurrogate(wcHigh) Then
|
---|
| 971 | If _System_IsLowSurrogate(wcLow) Then
|
---|
[119] | 972 | Return True
|
---|
| 973 | End If
|
---|
| 974 | End If
|
---|
| 975 | Return False
|
---|
| 976 | End Function
|
---|
[1] | 977 |
|
---|
[394] | 978 | Function _System_IsHighSurrogate(c As WCHAR) As Boolean
|
---|
| 979 | Return &hD800 <= c And c < &hDC00
|
---|
| 980 | End Function
|
---|
| 981 |
|
---|
| 982 | Function _System_IsLowSurrogate(c As WCHAR) As Boolean
|
---|
| 983 | Return &hDC00 <= c And c < &hE000
|
---|
| 984 | End Function
|
---|
| 985 |
|
---|
[142] | 986 | Function _System_IsDoubleUnitChar(lead As WCHAR, trail As WCHAR) As Boolean
|
---|
[126] | 987 | Return _System_IsSurrogatePair(lead, trail)
|
---|
[142] | 988 | End Function
|
---|
| 989 |
|
---|
| 990 | Function _System_IsDoubleUnitChar(lead As SByte, trail As SByte) As Boolean
|
---|
[126] | 991 | Return IsDBCSLeadByte(lead) <> FALSE
|
---|
| 992 | End Function
|
---|
| 993 |
|
---|
[175] | 994 | Function _System_GetHashFromWordArray(p As *Word, n As SIZE_T) As Long
|
---|
| 995 | Dim hash = 0 As DWord
|
---|
| 996 | Dim i As Long
|
---|
| 997 | For i = 0 To ELM(n)
|
---|
| 998 | hash = ((hash << 16) + p[i]) Mod &h7fffffff
|
---|
| 999 | Next
|
---|
| 1000 | _System_GetHashFromWordArray = hash As Long
|
---|
| 1001 | End Function
|
---|
| 1002 |
|
---|
[1] | 1003 | #endif '_INC_FUNCTION
|
---|