source: trunk/Include/basic/function.sbp@ 457

Last change on this file since 457 was 457, checked in by イグトランス (egtra), 16 years ago

(SPrintF.ab) FormatIntegerExにStringBuilderを引数に取る版を追加。

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