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
|
---|
11 |
|
---|
12 |
|
---|
13 | #include <Classes/System/Math.ab>
|
---|
14 |
|
---|
15 |
|
---|
16 | '------------- サポート関数の定義 -------------
|
---|
17 |
|
---|
18 | Function ldexp(x As Double, n As Long) As Double
|
---|
19 | If x = 0 Then
|
---|
20 | ldexp = 0
|
---|
21 | Exit Function
|
---|
22 | End If
|
---|
23 | Dim pSrc As *QWord, pDest As *QWord
|
---|
24 | pSrc = VarPtr(x) As *QWord
|
---|
25 | pDest = VarPtr(ldexp) As *QWord
|
---|
26 |
|
---|
27 | n += (pSrc[0] >> 52) As DWord And &h7FF
|
---|
28 |
|
---|
29 | pDest[0] = n << 52 Or (pSrc[0] And &h800FFFFFFFFFFFFF)
|
---|
30 | End Function
|
---|
31 |
|
---|
32 | Function frexp(x As Double, ByRef n As Long) As Double
|
---|
33 | If x = 0 Then
|
---|
34 | n = 0
|
---|
35 | frexp = 0
|
---|
36 | Exit Function
|
---|
37 | End If
|
---|
38 |
|
---|
39 | Dim pSrc As *QWord, pDest As *QWord
|
---|
40 | pSrc = VarPtr(x) As *QWord
|
---|
41 | pDest = VarPtr(frexp) As *QWord
|
---|
42 | n = ((pSrc[0] >> 52) As DWord And &h7FF) - 1022
|
---|
43 | pDest[0] = (pSrc[0] And &h800FFFFFFFFFFFFF) Or &h3FE0000000000000
|
---|
44 | End Function
|
---|
45 |
|
---|
46 | Function frexp(x As Single, ByRef n As Long) As Single
|
---|
47 | If x = 0 Then
|
---|
48 | n = 0
|
---|
49 | frexp = 0
|
---|
50 | Exit Function
|
---|
51 | End If
|
---|
52 |
|
---|
53 | Dim pSrc As *DWord, pDest As *DWord
|
---|
54 | pSrc = VarPtr(x) As *DWord
|
---|
55 | pDest = VarPtr(frexp) As *DWord
|
---|
56 | n = ((pSrc[0] >> 23) And &hFF) - 126
|
---|
57 | pDest[0] = (pSrc[0] And &h807FFFFF) Or &h7E000000
|
---|
58 | End Function
|
---|
59 |
|
---|
60 | Function ipow(x As Double, n As Long) As Double
|
---|
61 | Dim abs_n As Long
|
---|
62 | Dim r = 1 As Double
|
---|
63 |
|
---|
64 | abs_n=Abs(n) As Long
|
---|
65 | While abs_n<>0
|
---|
66 | If abs_n and 1 Then r *= x
|
---|
67 | x = x * x
|
---|
68 | abs_n >>= 1 ' abs_n \= 2
|
---|
69 | Wend
|
---|
70 |
|
---|
71 | If n>=0 Then
|
---|
72 | ipow=r
|
---|
73 | Else
|
---|
74 | ipow=1/r
|
---|
75 | End If
|
---|
76 | End Function
|
---|
77 |
|
---|
78 | Function pow(x As Double, y As Double) As Double
|
---|
79 | If -LONG_MAX<=y and y<=LONG_MAX and y=CDbl(Int(y)) Then
|
---|
80 | pow=ipow(x,y As Long)
|
---|
81 | Exit Function
|
---|
82 | End If
|
---|
83 |
|
---|
84 | If x>0 Then
|
---|
85 | pow=Exp(y*Log(x))
|
---|
86 | Exit Function
|
---|
87 | End If
|
---|
88 |
|
---|
89 | If x<>0 or y<=0 Then
|
---|
90 | 'error
|
---|
91 | End If
|
---|
92 |
|
---|
93 | pow=0
|
---|
94 | End Function
|
---|
95 |
|
---|
96 | #ifdef _WIN64
|
---|
97 |
|
---|
98 | Function _System_GetNaN() As Double
|
---|
99 | SetQWord(VarPtr(_System_GetNaN) As *QWord, &H7FF8000000000000)
|
---|
100 | End Function
|
---|
101 |
|
---|
102 | Function _System_GetInf(sign As BOOL) As Double
|
---|
103 | Dim s = 0 As QWord
|
---|
104 | If sign Then s = 1 << 63
|
---|
105 | SetQWord(VarPtr(_System_GetInf) As *QWord, &h7FF0000000000000 Or s)
|
---|
106 | End Function
|
---|
107 |
|
---|
108 | #else
|
---|
109 |
|
---|
110 | Function _System_GetNaN() As Double
|
---|
111 | Dim p As *DWord
|
---|
112 | p = VarPtr(_System_GetNaN) As *DWord
|
---|
113 | p[0] = 0
|
---|
114 | p[1] = &H7FF80000
|
---|
115 | End Function
|
---|
116 |
|
---|
117 | Function _System_GetInf(sign As BOOL) As Double
|
---|
118 | Dim s = 0 As DWord
|
---|
119 | If sign Then s = (1 As DWord) << 31
|
---|
120 | Dim p As *DWord
|
---|
121 | p = VarPtr(_System_GetInf) As *DWord
|
---|
122 | p[0] = 0
|
---|
123 | p[1] = &h7FF00000 Or s
|
---|
124 | End Function
|
---|
125 |
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | ' xの符号だけをyのものにした値を返す。
|
---|
129 | ' 引数 x 元となる絶対値
|
---|
130 | ' 引数 y 元となる符号
|
---|
131 | Function CopySign(x As Double, y As Double) As Double
|
---|
132 | SetQWord(VarPtr(CopySign), (GetQWord(VarPtr(x)) And &h7fffffffffffffff) Or (GetQWord(VarPtr(y)) And &h8000000000000000))
|
---|
133 | End Function
|
---|
134 |
|
---|
135 | Function CopySign(x As Single, y As Single) As Single
|
---|
136 | SetDWord(VarPtr(CopySign), (GetDWord(VarPtr(x)) And &h7fffffff) Or (GetDWord(VarPtr(y)) And &h80000000))
|
---|
137 | End Function
|
---|
138 |
|
---|
139 | Function _System_SetSign(x As Double, isNegative As Long) As Double
|
---|
140 | #ifdef _WIN64
|
---|
141 | SetQWord(AddressOf(CopySign), (GetQWord(VarPtr(x)) And &h7fffffffffffffff) Or (isNegative << 63))
|
---|
142 | #else
|
---|
143 | SetDWord(AddressOf(CopySign), GetDWord(VarPtr(x)))
|
---|
144 | SetDWord(AddressOf(CopySign) + SizeOf (DWord), GetQWord(VarPtr(x) + SizeOf (DWord)) And &h7fffffff Or (isNegative << 31))
|
---|
145 | #endif
|
---|
146 | End Function
|
---|
147 |
|
---|
148 | Const RAND_MAX=&H7FFFFFFF
|
---|
149 | Dim _System_RndNext=1 As DWord
|
---|
150 |
|
---|
151 | Function rand() As Long
|
---|
152 | _System_RndNext = _System_RndNext * 1103515245 + 12345
|
---|
153 | rand = _System_RndNext >> 1
|
---|
154 | End Function
|
---|
155 |
|
---|
156 | Sub srand(dwSeek As DWord)
|
---|
157 | _System_RndNext = dwSeek
|
---|
158 | End Sub
|
---|
159 |
|
---|
160 |
|
---|
161 | '------------- ここからBasic標準関数の定義 -------------
|
---|
162 |
|
---|
163 |
|
---|
164 | '------------------
|
---|
165 | ' データ型変換関数
|
---|
166 | '------------------
|
---|
167 |
|
---|
168 | Function CDbl(number As Double) As Double
|
---|
169 | CDbl=number
|
---|
170 | End Function
|
---|
171 |
|
---|
172 | Function _CUDbl(number As QWord) As Double
|
---|
173 | _CUDbl=number As Double
|
---|
174 | End Function
|
---|
175 |
|
---|
176 | Function CDWord(num As Double) As DWord
|
---|
177 | CDWord=num As DWord
|
---|
178 | End Function
|
---|
179 |
|
---|
180 | Function CInt(number As Double) As Long
|
---|
181 | CInt=number As Long
|
---|
182 | End Function
|
---|
183 |
|
---|
184 | Function CSng(number As Double) As Single
|
---|
185 | CSng=number As Single
|
---|
186 | End Function
|
---|
187 |
|
---|
188 | #ifdef _WIN64
|
---|
189 | Function Fix(number As Double) As Long
|
---|
190 | Fix=number As Long
|
---|
191 | End Function
|
---|
192 | #else
|
---|
193 | 'Fix関数はコンパイラに組み込まれている
|
---|
194 | 'Function Fix(number As Double) As Long
|
---|
195 | #endif
|
---|
196 |
|
---|
197 | Function Int(number As Double) As Long
|
---|
198 | Int=Fix(number)
|
---|
199 | If number<0 Then
|
---|
200 | If number<Fix(number) Then Int=Int-1
|
---|
201 | End If
|
---|
202 | End Function
|
---|
203 |
|
---|
204 |
|
---|
205 | '-------------------------------------
|
---|
206 | ' ポインタ関数(コンパイラに組み込み)
|
---|
207 | '-------------------------------------
|
---|
208 |
|
---|
209 | 'Function GetDouble(p As DWord) As Double
|
---|
210 | 'Function GetSingle(p As DWord) As Single
|
---|
211 | 'Function GetDWord(p As DWord) As DWord
|
---|
212 | 'Function GetWord(p As DWord) As Word
|
---|
213 | 'Function GetByte(p As DWord) As Byte
|
---|
214 | 'Sub SetDouble(p As DWord, dblData As Double)
|
---|
215 | 'Sub SetSingle(p As DWord, fltData As Single)
|
---|
216 | 'Sub SetDWord(p As DWord, dwData As DWord)
|
---|
217 | 'Sub SetWord(p As DWord, wData As Word)
|
---|
218 | 'Sub SetByte(p As DWord, byteData As Byte)
|
---|
219 |
|
---|
220 |
|
---|
221 | '----------
|
---|
222 | ' 算術関数
|
---|
223 | '----------
|
---|
224 |
|
---|
225 | Function Abs(number As Double) As Double
|
---|
226 | 'Abs = Math.Abs(number)
|
---|
227 | If number < 0 then
|
---|
228 | return -number
|
---|
229 | Else
|
---|
230 | return number
|
---|
231 | End If
|
---|
232 | End Function
|
---|
233 |
|
---|
234 | Function Exp(x As Double) As Double
|
---|
235 | Exp = Math.Exp(x)
|
---|
236 | End Function
|
---|
237 |
|
---|
238 | Function Log(x As Double) As Double
|
---|
239 | Log = Math.Log(x)
|
---|
240 | End Function
|
---|
241 |
|
---|
242 | Function Sgn(number As Double) As Long
|
---|
243 | Sgn = Math.Sign(number)
|
---|
244 | End Function
|
---|
245 |
|
---|
246 | Function Sqr(number As Double) As Double
|
---|
247 | Sqr = Math.Sqrt(number)
|
---|
248 | End Function
|
---|
249 |
|
---|
250 | Function Atn(number As Double) As Double
|
---|
251 | Atn = Math.Atan(number)
|
---|
252 | End Function
|
---|
253 |
|
---|
254 | Function _Support_tan(x As Double, ByRef k As Long) As Double
|
---|
255 | Dim i As Long
|
---|
256 | Dim t As Double, x2 As Double
|
---|
257 |
|
---|
258 | If x>=0 Then
|
---|
259 | k=Fix(x/(_System_PI/2)+0.5)
|
---|
260 | Else
|
---|
261 | k=Fix(x/(_System_PI/2)-0.5)
|
---|
262 | End If
|
---|
263 |
|
---|
264 | x=(x-(CDbl(3217)/CDbl(2048))*k)+4.4544551033807686783083602485579e-6*k
|
---|
265 |
|
---|
266 | x2=x*x
|
---|
267 | t=0
|
---|
268 |
|
---|
269 | For i=19 To 3 Step -2
|
---|
270 | t=x2/(i-t)
|
---|
271 | Next
|
---|
272 |
|
---|
273 | _Support_tan=x/(1-t)
|
---|
274 | End Function
|
---|
275 |
|
---|
276 | Function Atn2(y As Double, x As Double) As Double
|
---|
277 | Atn2 = Math.Atan2(y, x)
|
---|
278 | End Function
|
---|
279 |
|
---|
280 | Function Sin(number As Double) As Double
|
---|
281 | Sin = Math.Sin(number)
|
---|
282 | End Function
|
---|
283 |
|
---|
284 | Function Cos(number As Double) As Double
|
---|
285 | Cos = Math.Cos(number)
|
---|
286 | End Function
|
---|
287 |
|
---|
288 | Function Tan(number As Double) As Double
|
---|
289 | Tan = Math.Tan(number)
|
---|
290 | End Function
|
---|
291 |
|
---|
292 | Function IsNaN(ByVal x As Double) As Boolean
|
---|
293 | Dim p As *DWord
|
---|
294 | p = VarPtr(x) As *DWord
|
---|
295 | IsNaN = FALSE
|
---|
296 | If (p[1] And &H7FF00000) = &H7FF00000 Then
|
---|
297 | If (p[0] <> 0) Or ((p[1] And &HFFFFF) <> 0) Then
|
---|
298 | IsNaN = True
|
---|
299 | End If
|
---|
300 | End If
|
---|
301 |
|
---|
302 | ' IsNaN=FALSE
|
---|
303 | End Function
|
---|
304 |
|
---|
305 | Function IsInf(x As Double) As Boolean
|
---|
306 | Dim p As *DWord, nan As Double
|
---|
307 | p = VarPtr(x) As *DWord
|
---|
308 | p[1] And= &h7fffffff
|
---|
309 | nan = _System_GetInf(FALSE)
|
---|
310 | IsInf = (memcmp(p As *Byte, VarPtr(nan), SizeOf (Double)) = 0)
|
---|
311 | End Function
|
---|
312 |
|
---|
313 | Function IsNaNOrInf(x As Double) As Boolean
|
---|
314 | IsNaNOrInf = IsFinite(x)
|
---|
315 | End Function
|
---|
316 |
|
---|
317 | Function IsFinite(x As Double) As Boolean
|
---|
318 | Dim p As *DWord, nan As Double
|
---|
319 | p = VarPtr(x) As *DWord
|
---|
320 | ' p[1] And= &h7ffe0000
|
---|
321 | p[1] And= &H7FF00000
|
---|
322 | p[0] = 0
|
---|
323 | nan = _System_GetInf(/*x,*/ FALSE)
|
---|
324 | IsFinite = (memcmp(p As BytePtr, VarPtr(nan), SizeOf (Double)) = 0)
|
---|
325 | End Function
|
---|
326 |
|
---|
327 | Const RAND_UNIT = (1.0 / (LONG_MAX + 1.0))
|
---|
328 | Function Rnd() As Double
|
---|
329 | Rnd = RAND_UNIT * rand()
|
---|
330 | End Function
|
---|
331 |
|
---|
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 |
|
---|
341 |
|
---|
342 | '------------
|
---|
343 | ' 文字列関数
|
---|
344 | '------------
|
---|
345 |
|
---|
346 | Function Asc(buf As *StrChar) As StrChar
|
---|
347 | Asc = buf[0]
|
---|
348 | End Function
|
---|
349 |
|
---|
350 | Function Chr$(code As StrChar) As String
|
---|
351 | Chr$ = ZeroString(1)
|
---|
352 | Chr$[0] = code
|
---|
353 | End Function
|
---|
354 |
|
---|
355 | #ifndef __STRING_IS_NOT_UNICODE
|
---|
356 | Function AscW(s As *WCHAR) As UCSCHAR
|
---|
357 | If s.Length = 0 Then
|
---|
358 | AscW = 0
|
---|
359 | Else
|
---|
360 | If _System_IsSurrogatePair(s[0], s[1]) Then
|
---|
361 | AscW = ((s[0] And &h3FF) As DWord << 10) Or (s[1] And &h3FF)
|
---|
362 | Else
|
---|
363 | AscW = s[0]
|
---|
364 | End If
|
---|
365 | End If
|
---|
366 | End Function
|
---|
367 |
|
---|
368 | Function ChrW(c As UCSCHAR) As String
|
---|
369 | If c <= &hFFFF Then
|
---|
370 | ChrW.ReSize(1)
|
---|
371 | ChrW[0] = c As WCHAR
|
---|
372 | ElseIf c < &h10FFFF Then
|
---|
373 | ChrW.ReSize(2)
|
---|
374 | ChrW[0] = &hD800 Or (c >> 10)
|
---|
375 | ChrW[1] = &hDC00 Or (c And &h3FF)
|
---|
376 | Else
|
---|
377 | ' OutOfRangeException
|
---|
378 | End If
|
---|
379 | End Function
|
---|
380 | #endif
|
---|
381 |
|
---|
382 | Function Date$() As String
|
---|
383 | Dim st As SYSTEMTIME
|
---|
384 | GetLocalTime(st)
|
---|
385 |
|
---|
386 | 'year
|
---|
387 | Date$=Str$(st.wYear)
|
---|
388 |
|
---|
389 | 'month
|
---|
390 | If st.wMonth<10 Then
|
---|
391 | Date$=Date$+"/0"
|
---|
392 | Else
|
---|
393 | Date$=Date$+"/"
|
---|
394 | End If
|
---|
395 | Date$=Date$+Str$(st.wMonth)
|
---|
396 |
|
---|
397 | 'day
|
---|
398 | If st.wDay<10 Then
|
---|
399 | Date$=Date$+"/0"
|
---|
400 | Else
|
---|
401 | Date$=Date$+"/"
|
---|
402 | End If
|
---|
403 | Date$=Date$+Str$(st.wDay)
|
---|
404 | End Function
|
---|
405 |
|
---|
406 | Dim _System_HexadecimalTable[&h10] = [&h30, &h31, &h32, &h33, &h34, &h35, &h36, &h37, &h38, &h39, &h41, &h42, &h43, &h44, &h45, &h46] As Byte
|
---|
407 |
|
---|
408 | Function 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)
|
---|
420 | End Function
|
---|
421 |
|
---|
422 | Function Hex$(x As QWord) As String
|
---|
423 | Hex$ = Hex$((x >> 32) As DWord) + Hex$((x And &hffffffff) As DWord)
|
---|
424 | End Function
|
---|
425 |
|
---|
426 | Function 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)
|
---|
431 |
|
---|
432 | If len2=0 Then
|
---|
433 | InStr=StartPos
|
---|
434 | Exit Function
|
---|
435 | End If
|
---|
436 |
|
---|
437 | StartPos--
|
---|
438 | If StartPos<0 Then
|
---|
439 | 'error
|
---|
440 | InStr=0
|
---|
441 | Exit Function
|
---|
442 | End If
|
---|
443 |
|
---|
444 | i=StartPos:InStr=0
|
---|
445 | While i<=len1-len2
|
---|
446 | i2=i:i3=0
|
---|
447 | Do
|
---|
448 | If i3=len2 Then
|
---|
449 | InStr=i+1
|
---|
450 | Exit Do
|
---|
451 | End If
|
---|
452 | If buf1[i2]<>buf2[i3] Then Exit Do
|
---|
453 |
|
---|
454 | i2++
|
---|
455 | i3++
|
---|
456 | Loop
|
---|
457 | If InStr Then Exit While
|
---|
458 | i++
|
---|
459 | Wend
|
---|
460 | End Function
|
---|
461 |
|
---|
462 | Function Left$(buf As String, length As Long) As String
|
---|
463 | Left$ = ZeroString(length)
|
---|
464 | memcpy(StrPtr(Left$), StrPtr(buf), SizeOf (Char) * length)
|
---|
465 | End Function
|
---|
466 |
|
---|
467 | Function Mid$(buf As String, StartPos As Long)(ReadLength As Long) As String
|
---|
468 | Dim length As Long
|
---|
469 |
|
---|
470 | StartPos--
|
---|
471 | If StartPos<0 Then
|
---|
472 | 'error
|
---|
473 | 'Debug
|
---|
474 | Exit Function
|
---|
475 | End If
|
---|
476 |
|
---|
477 | length=Len(buf)
|
---|
478 | If length<=StartPos Then Exit Function
|
---|
479 |
|
---|
480 | If ReadLength=0 Then
|
---|
481 | ReadLength=length-StartPos
|
---|
482 | End If
|
---|
483 |
|
---|
484 | If ReadLength>length-StartPos Then
|
---|
485 | ReadLength=length-StartPos
|
---|
486 | End If
|
---|
487 |
|
---|
488 | Mid$=ZeroString(ReadLength)
|
---|
489 | memcpy(StrPtr(Mid$), VarPtr(buf.Chars[StartPos]), SizeOf (Char) * ReadLength)
|
---|
490 | End Function
|
---|
491 |
|
---|
492 | Function Oct$(num As DWord) As String
|
---|
493 | Dim i As DWord, i2 As DWord
|
---|
494 |
|
---|
495 | For i=10 To 1 Step -1
|
---|
496 | If (num\CDWord(8^i)) And &H07 Then
|
---|
497 | Exit For
|
---|
498 | End If
|
---|
499 | Next
|
---|
500 |
|
---|
501 | Oct$=ZeroString(i+1)
|
---|
502 | i2=0
|
---|
503 | Do
|
---|
504 | Oct$[i2] = &h30 +((num \ CDWord(8 ^ i)) And &H07) ' &h30 = Asc("0")
|
---|
505 | If i=0 Then Exit Do
|
---|
506 | i--
|
---|
507 | i2++
|
---|
508 | Loop
|
---|
509 | End Function
|
---|
510 |
|
---|
511 | Function Right$(buf As String, length As Long) As String
|
---|
512 | Dim i As Long
|
---|
513 |
|
---|
514 | i=Len(buf)
|
---|
515 | If i>length Then
|
---|
516 | Right$=ZeroString(length)
|
---|
517 | memcpy(StrPtr(Right$), VarPtr(buf.Chars[i-length]), SizeOf (Char) * length)
|
---|
518 | Else
|
---|
519 | Right$=buf
|
---|
520 | End If
|
---|
521 | End Function
|
---|
522 |
|
---|
523 | Function 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
|
---|
528 | Sub _ecvt_support(count As Long)
|
---|
529 | Dim i As Long
|
---|
530 | If _System_ecvt_buffer[count]=9 Then
|
---|
531 | _System_ecvt_buffer[count]=0
|
---|
532 | If count=0 Then
|
---|
533 | For i=16 To 1 Step -1
|
---|
534 | _System_ecvt_buffer[i]=_System_ecvt_buffer[i-1]
|
---|
535 | Next
|
---|
536 | _System_ecvt_buffer[0]=1
|
---|
537 | Else
|
---|
538 | _ecvt_support(count-1)
|
---|
539 | End If
|
---|
540 | Else
|
---|
541 | _System_ecvt_buffer[count]++
|
---|
542 | End If
|
---|
543 | End 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
|
---|
546 | Dim i As Long, i2 As Long
|
---|
547 |
|
---|
548 | _ecvt=_System_ecvt_buffer
|
---|
549 |
|
---|
550 | '値が0の場合
|
---|
551 | If value=0 Then
|
---|
552 | _System_FillChar(_System_ecvt_buffer, count, &H30)
|
---|
553 | _System_ecvt_buffer[count] = 0
|
---|
554 | dec = 0
|
---|
555 | sign = 0
|
---|
556 | Exit Function
|
---|
557 | End If
|
---|
558 |
|
---|
559 | '符号の判断(同時に符号を取り除く)
|
---|
560 | If value<0 Then
|
---|
561 | sign=1
|
---|
562 | value=-value
|
---|
563 | Else
|
---|
564 | sign=0
|
---|
565 | End If
|
---|
566 |
|
---|
567 | '正規化
|
---|
568 | dec=1
|
---|
569 | While value<0.999999999999999 'value<1
|
---|
570 | value *= 10
|
---|
571 | dec--
|
---|
572 | Wend
|
---|
573 | While 9.99999999999999<=value '10<=value
|
---|
574 | value /= 10
|
---|
575 | dec++
|
---|
576 | Wend
|
---|
577 |
|
---|
578 | For i=0 To count-1
|
---|
579 | _System_ecvt_buffer[i]=Int(value) As Char
|
---|
580 |
|
---|
581 | value=(value-CDbl(Int(value)))*10
|
---|
582 | Next
|
---|
583 | _System_ecvt_buffer[i]=0
|
---|
584 |
|
---|
585 | i--
|
---|
586 | If value>=5 Then
|
---|
587 | '切り上げ処理
|
---|
588 | _ecvt_support(i)
|
---|
589 | End If
|
---|
590 |
|
---|
591 | For i=0 To count-1
|
---|
592 | _System_ecvt_buffer[i] += &H30
|
---|
593 | Next
|
---|
594 | _System_ecvt_buffer[i]=0
|
---|
595 | End Function
|
---|
596 |
|
---|
597 | Function Str$(dbl As Double) As String
|
---|
598 | If IsNaN(dbl) Then
|
---|
599 | Return "NaN"
|
---|
600 | ElseIf IsInf(dbl) Then
|
---|
601 | If dbl > 0 Then
|
---|
602 | Return "Infinity"
|
---|
603 | Else
|
---|
604 | Return "-Infinity"
|
---|
605 | End If
|
---|
606 | End If
|
---|
607 | Dim dec As Long, sign As Long
|
---|
608 | Dim buffer[32] As Char, temp As *Char
|
---|
609 | Dim i As Long, i2 As Long, i3 As Long
|
---|
610 |
|
---|
611 | '浮動小数点を文字列に変換
|
---|
612 | temp=_ecvt(dbl,15,dec,sign)
|
---|
613 |
|
---|
614 | i=0
|
---|
615 |
|
---|
616 | '符号の取り付け
|
---|
617 | If sign Then
|
---|
618 | buffer[i]=Asc("-")
|
---|
619 | i++
|
---|
620 | End If
|
---|
621 |
|
---|
622 | If dec>15 Then
|
---|
623 | '指数表示(桁が大きい場合)
|
---|
624 | buffer[i]=temp[0]
|
---|
625 | i++
|
---|
626 | buffer[i]=Asc(".")
|
---|
627 | i++
|
---|
628 | memcpy(VarPtr(buffer[i]), VarPtr(temp[1]), SizeOf (Char) * 14)
|
---|
629 | 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)
|
---|
648 |
|
---|
649 | Return MakeStr(buffer)
|
---|
650 | End If
|
---|
651 |
|
---|
652 | '整数部
|
---|
653 | i2=dec
|
---|
654 | i3=0
|
---|
655 | If i2>0 Then
|
---|
656 | While i2>0
|
---|
657 | buffer[i]=temp[i3]
|
---|
658 | i++
|
---|
659 | i3++
|
---|
660 | i2--
|
---|
661 | Wend
|
---|
662 | buffer[i]=Asc(".")
|
---|
663 | i++
|
---|
664 | Else
|
---|
665 | buffer[i]=&H30
|
---|
666 | i++
|
---|
667 | buffer[i]=Asc(".")
|
---|
668 | i++
|
---|
669 |
|
---|
670 | i2=dec
|
---|
671 | While i2<0
|
---|
672 | buffer[i]=&H30
|
---|
673 | i++
|
---|
674 | i2++
|
---|
675 | Wend
|
---|
676 | End If
|
---|
677 |
|
---|
678 | '小数部
|
---|
679 | While i3<15
|
---|
680 | buffer[i]=temp[i3]
|
---|
681 | i++
|
---|
682 | i3++
|
---|
683 | Wend
|
---|
684 |
|
---|
685 | While buffer[i-1]=&H30
|
---|
686 | i--
|
---|
687 | Wend
|
---|
688 | If buffer[i-1]=Asc(".") Then i--
|
---|
689 |
|
---|
690 | buffer[i]=0
|
---|
691 | Return MakeStr(buffer)
|
---|
692 | End Function
|
---|
693 | Function Str$(value As Int64) As String
|
---|
694 | Dim temp[255] As Char
|
---|
695 | _sntprintf(temp, Len (temp) \ SizeOf (Char), "%I64d", value)
|
---|
696 | Str$ = temp
|
---|
697 | End Function
|
---|
698 |
|
---|
699 | Function String$(num As Long, buf As String) As String
|
---|
700 | Dim dwStrPtr As DWord
|
---|
701 | Dim length As Long
|
---|
702 |
|
---|
703 | length=Len(buf)
|
---|
704 |
|
---|
705 | 'バッファ領域を確保
|
---|
706 | String$=ZeroString(length*num)
|
---|
707 |
|
---|
708 | '文字列をコピー
|
---|
709 | Dim i As Long
|
---|
710 | For i=0 To num-1
|
---|
711 | memcpy(VarPtr(String$[i*length]), StrPtr(buf), SizeOf (Char) * length)
|
---|
712 | Next
|
---|
713 | End Function
|
---|
714 |
|
---|
715 | Function Time$() As String
|
---|
716 | Dim st As SYSTEMTIME
|
---|
717 |
|
---|
718 | GetLocalTime(st)
|
---|
719 |
|
---|
720 | 'hour
|
---|
721 | If st.wHour<10 Then
|
---|
722 | Time$="0"
|
---|
723 | End If
|
---|
724 | Time$=Time$+Str$(st.wHour)
|
---|
725 |
|
---|
726 | 'minute
|
---|
727 | If st.wMinute<10 Then
|
---|
728 | Time$=Time$+":0"
|
---|
729 | Else
|
---|
730 | Time$=Time$+":"
|
---|
731 | End If
|
---|
732 | Time$=Time$+Str$(st.wMinute)
|
---|
733 |
|
---|
734 | 'second
|
---|
735 | If st.wSecond<10 Then
|
---|
736 | Time$=Time$+":0"
|
---|
737 | Else
|
---|
738 | Time$=Time$+":"
|
---|
739 | End If
|
---|
740 | Time$=Time$+Str$(st.wSecond)
|
---|
741 | End Function
|
---|
742 |
|
---|
743 | Function Val(buf As *Char) As Double
|
---|
744 | Dim i As Long, i2 As Long, i3 As Long, i4 As Long
|
---|
745 | Dim temporary As String
|
---|
746 | Dim TempPtr As *Char
|
---|
747 | Dim dbl As Double
|
---|
748 | Dim i64data As Int64
|
---|
749 |
|
---|
750 | Val=0
|
---|
751 |
|
---|
752 | While buf[0]=Asc(" ") or buf[0]=Asc(Ex"\t")
|
---|
753 | buf++
|
---|
754 | Wend
|
---|
755 |
|
---|
756 | If buf[0]=Asc("&") Then
|
---|
757 | temporary = buf
|
---|
758 | temporary.ToUpper()
|
---|
759 | TempPtr = StrPtr(temporary)
|
---|
760 | If TempPtr(1)=Asc("O") Then
|
---|
761 | '8進数
|
---|
762 | i=2
|
---|
763 | While 1
|
---|
764 | '数字以外の文字の場合は抜け出す
|
---|
765 | i3=TempPtr[i]-&H30
|
---|
766 | If Not (0<=i3 And i3<=7) Then Exit While
|
---|
767 |
|
---|
768 | TempPtr[i]=i3 As Char
|
---|
769 | i++
|
---|
770 | Wend
|
---|
771 | i--
|
---|
772 |
|
---|
773 | i64data=1
|
---|
774 | While i>=2
|
---|
775 | Val += i64data * TempPtr[i]
|
---|
776 |
|
---|
777 | i64data *= &O10
|
---|
778 | i--
|
---|
779 | Wend
|
---|
780 | ElseIf TempPtr(1)=Asc("H") Then
|
---|
781 | '16進数
|
---|
782 | i=2
|
---|
783 | While 1
|
---|
784 | '数字以外の文字の場合は抜け出す
|
---|
785 | i3=TempPtr[i]-&H30
|
---|
786 | If Not(0<=i3 and i3<=9) Then
|
---|
787 | i3=TempPtr[i]-&H41+10
|
---|
788 | If Not(&HA<=i3 and i3<=&HF) Then Exit While
|
---|
789 | End If
|
---|
790 |
|
---|
791 | TempPtr[i]=i3 As Char
|
---|
792 | i++
|
---|
793 | Wend
|
---|
794 | i--
|
---|
795 |
|
---|
796 | i64data=1
|
---|
797 | While i>=2
|
---|
798 | Val += (i64data*TempPtr[i]) As Double
|
---|
799 |
|
---|
800 | i64data *= &H10
|
---|
801 | i--
|
---|
802 | Wend
|
---|
803 | End If
|
---|
804 | Else
|
---|
805 | '10進数
|
---|
806 | If buf[0]=&H2D Then
|
---|
807 | 'マイナス値
|
---|
808 | i4=1
|
---|
809 | buf++
|
---|
810 | Else
|
---|
811 | 'プラス値
|
---|
812 | i4=0
|
---|
813 | If buf[0]=&H2B Then
|
---|
814 | buf++
|
---|
815 | End If
|
---|
816 | End If
|
---|
817 |
|
---|
818 | i=0
|
---|
819 |
|
---|
820 | While 1
|
---|
821 | '数字以外の文字の場合は抜け出す
|
---|
822 | i3=buf[i]-&H30
|
---|
823 | If Not (0<=i3 And i3<=9) Then Exit While
|
---|
824 |
|
---|
825 | i++
|
---|
826 | Wend
|
---|
827 |
|
---|
828 | '整数部
|
---|
829 | dbl=1
|
---|
830 | i3=i-1
|
---|
831 | While i3>=0
|
---|
832 | Val += dbl*(buf[i3]-&H30)
|
---|
833 |
|
---|
834 | dbl *= 10
|
---|
835 | i3--
|
---|
836 | Wend
|
---|
837 |
|
---|
838 | If buf[i]=Asc(".") Then
|
---|
839 | '小数部
|
---|
840 | i++
|
---|
841 | dbl=10
|
---|
842 | While 1
|
---|
843 | '数字以外の文字の場合は抜け出す
|
---|
844 | i3=buf[i]-&H30
|
---|
845 | If Not (0<=i3 And i3<=9) Then Exit While
|
---|
846 |
|
---|
847 | Val += (buf[i] - &H30) / dbl
|
---|
848 | dbl *= 10
|
---|
849 | i++
|
---|
850 | Wend
|
---|
851 | End If
|
---|
852 |
|
---|
853 | If i4 Then Val=-Val
|
---|
854 | End If
|
---|
855 | End Function
|
---|
856 |
|
---|
857 |
|
---|
858 | '--------------
|
---|
859 | ' ファイル関数
|
---|
860 | '--------------
|
---|
861 |
|
---|
862 | Function Eof(FileNum As Long) As Long
|
---|
863 | Dim dwCurrent As DWord, dwEnd As DWord
|
---|
864 |
|
---|
865 | FileNum--
|
---|
866 |
|
---|
867 | dwCurrent=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_CURRENT)
|
---|
868 | dwEnd=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_END)
|
---|
869 | SetFilePointer(_System_hFile(FileNum),dwCurrent,NULL,FILE_BEGIN)
|
---|
870 |
|
---|
871 | If dwCurrent>=dwEnd Then
|
---|
872 | Eof=-1
|
---|
873 | Else
|
---|
874 | Eof=0
|
---|
875 | End If
|
---|
876 | End Function
|
---|
877 |
|
---|
878 | Function Lof(FileNum As Long) As Long
|
---|
879 | Lof = GetFileSize(_System_hFile(FileNum-1), 0)
|
---|
880 | End Function
|
---|
881 |
|
---|
882 | Function Loc(FileNum As Long) As Long
|
---|
883 | Dim NowPos As Long, BeginPos As Long
|
---|
884 |
|
---|
885 | FileNum--
|
---|
886 |
|
---|
887 | NowPos=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_CURRENT)
|
---|
888 | BeginPos=SetFilePointer(_System_hFile(FileNum),0,NULL,FILE_BEGIN)
|
---|
889 | SetFilePointer(_System_hFile(FileNum),NowPos-BeginPos,NULL,FILE_BEGIN)
|
---|
890 |
|
---|
891 | Loc=NowPos-BeginPos
|
---|
892 | End Function
|
---|
893 |
|
---|
894 |
|
---|
895 | '------------------
|
---|
896 | ' メモリ関連の関数
|
---|
897 | '------------------
|
---|
898 |
|
---|
899 | Function malloc(stSize As SIZE_T) As VoidPtr
|
---|
900 | Return _System_GC.__malloc(stSize,_System_GC_FLAG_NEEDFREE)
|
---|
901 | End Function
|
---|
902 |
|
---|
903 | Function calloc(stSize As SIZE_T) As VoidPtr
|
---|
904 | Return _System_GC.__malloc(stSize,_System_GC_FLAG_NEEDFREE or _System_GC_FLAG_INITZERO)
|
---|
905 | End Function
|
---|
906 |
|
---|
907 | Function realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
908 | If lpMem = 0 Then
|
---|
909 | Return malloc(stSize)
|
---|
910 | Else
|
---|
911 | Return _System_GC.__realloc(lpMem,stSize)
|
---|
912 | End If
|
---|
913 | End Function
|
---|
914 |
|
---|
915 | Sub free(lpMem As VoidPtr)
|
---|
916 | _System_GC.__free(lpMem)
|
---|
917 | End Sub
|
---|
918 |
|
---|
919 |
|
---|
920 | Function _System_malloc(stSize As SIZE_T) As VoidPtr
|
---|
921 | Return HeapAlloc(_System_hProcessHeap,0,stSize)
|
---|
922 | End Function
|
---|
923 |
|
---|
924 | Function _System_calloc(stSize As SIZE_T) As VoidPtr
|
---|
925 | Return HeapAlloc(_System_hProcessHeap,HEAP_ZERO_MEMORY,stSize)
|
---|
926 | End Function
|
---|
927 |
|
---|
928 | Function _System_realloc(lpMem As VoidPtr, stSize As SIZE_T) As VoidPtr
|
---|
929 | If lpMem = 0 Then
|
---|
930 | Return HeapAlloc(_System_hProcessHeap, 0, stSize)
|
---|
931 | Else
|
---|
932 | Return HeapReAlloc(_System_hProcessHeap, 0, lpMem, stSize)
|
---|
933 | End If
|
---|
934 | End Function
|
---|
935 |
|
---|
936 | Sub _System_free(lpMem As VoidPtr)
|
---|
937 | HeapFree(_System_hProcessHeap,0,lpMem)
|
---|
938 | End Sub
|
---|
939 |
|
---|
940 |
|
---|
941 | '--------
|
---|
942 | ' その他
|
---|
943 | '--------
|
---|
944 |
|
---|
945 | Sub _splitpath(path As PCSTR, drive As PSTR, dir As PSTR, fname As PSTR, ext As PSTR)
|
---|
946 | Dim i As Long, i2 As Long, i3 As Long, length As Long
|
---|
947 | Dim buffer[MAX_PATH] As Char
|
---|
948 |
|
---|
949 | '":\"をチェック
|
---|
950 | If not(path[1]=&H3A and path[2]=&H5C) Then Exit Sub
|
---|
951 |
|
---|
952 | 'ドライブ名をコピー
|
---|
953 | If drive Then
|
---|
954 | drive[0]=path[0]
|
---|
955 | drive[1]=path[1]
|
---|
956 | drive[2]=0
|
---|
957 | End If
|
---|
958 |
|
---|
959 | 'ディレクトリ名をコピー
|
---|
960 | i=2
|
---|
961 | i2=0
|
---|
962 | Do
|
---|
963 | '#ifdef UNICODE
|
---|
964 | ' If _System_IsSurrogatePair(path[i], path[i + 1]) Then
|
---|
965 | '#else
|
---|
966 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
967 | '#endif
|
---|
968 | If dir Then
|
---|
969 | dir[i2]=path[i]
|
---|
970 | dir[i2+1]=path[i+1]
|
---|
971 | End If
|
---|
972 |
|
---|
973 | i += 2
|
---|
974 | i2 += 2
|
---|
975 | Continue
|
---|
976 | End If
|
---|
977 |
|
---|
978 | If path[i]=0 Then Exit Do
|
---|
979 |
|
---|
980 | If path[i]=&H5C Then '"\"記号であるかどうか
|
---|
981 | i3=i2+1
|
---|
982 | End If
|
---|
983 |
|
---|
984 | If dir Then dir[i2]=path[i]
|
---|
985 |
|
---|
986 | i++
|
---|
987 | i2++
|
---|
988 | Loop
|
---|
989 | If dir Then dir[i3]=0
|
---|
990 | i3 += i-i2
|
---|
991 |
|
---|
992 | 'ファイル名をコピー
|
---|
993 | i=i3
|
---|
994 | i2=0
|
---|
995 | i3=-1
|
---|
996 | Do
|
---|
997 | '#ifdef UNICODE
|
---|
998 | ' If _System_IsSurrogatePair(path[i], path[i + 1]) Then
|
---|
999 | '#else
|
---|
1000 | If IsDBCSLeadByte(path[i]) <> FALSE and path[i + 1] <> 0 Then
|
---|
1001 | '#endif
|
---|
1002 | If fname Then
|
---|
1003 | fname[i2]=path[i]
|
---|
1004 | fname[i2+1]=path[i+1]
|
---|
1005 | End If
|
---|
1006 |
|
---|
1007 | i += 2
|
---|
1008 | i2 += 2
|
---|
1009 | Continue
|
---|
1010 | End If
|
---|
1011 |
|
---|
1012 | If path[i]=0 Then Exit Do
|
---|
1013 |
|
---|
1014 | If path[i]=&H2E Then '.'記号であるかどうか
|
---|
1015 | i3=i2
|
---|
1016 | End If
|
---|
1017 |
|
---|
1018 | If fname Then fname[i2]=path[i]
|
---|
1019 |
|
---|
1020 | i++
|
---|
1021 | i2++
|
---|
1022 | Loop
|
---|
1023 | If i3=-1 Then i3=i2
|
---|
1024 | If fname Then fname[i3]=0
|
---|
1025 | i3 += i-i2
|
---|
1026 |
|
---|
1027 | '拡張子名をコピー
|
---|
1028 | If ext Then
|
---|
1029 | If i3 Then
|
---|
1030 | lstrcpy(ext,path+i3)
|
---|
1031 | End If
|
---|
1032 | else ext[0]=0
|
---|
1033 | End If
|
---|
1034 | End Sub
|
---|
1035 |
|
---|
1036 | Function GetBasicColor(ColorCode As Long) As Long
|
---|
1037 | Select Case ColorCode
|
---|
1038 | Case 0
|
---|
1039 | GetBasicColor=RGB(0,0,0)
|
---|
1040 | Case 1
|
---|
1041 | GetBasicColor=RGB(0,0,255)
|
---|
1042 | Case 2
|
---|
1043 | GetBasicColor=RGB(255,0,0)
|
---|
1044 | Case 3
|
---|
1045 | GetBasicColor=RGB(255,0,255)
|
---|
1046 | Case 4
|
---|
1047 | GetBasicColor=RGB(0,255,0)
|
---|
1048 | Case 5
|
---|
1049 | GetBasicColor=RGB(0,255,255)
|
---|
1050 | Case 6
|
---|
1051 | GetBasicColor=RGB(255,255,0)
|
---|
1052 | Case 7
|
---|
1053 | GetBasicColor=RGB(255,255,255)
|
---|
1054 | End Select
|
---|
1055 | End Function
|
---|
1056 |
|
---|
1057 | '--------
|
---|
1058 | ' 文字列関数その2
|
---|
1059 | '--------
|
---|
1060 | Function _System_IsSurrogatePair(wcHigh As WCHAR, wcLow As WCHAR) As Boolean
|
---|
1061 | If &hD800 <= wcHigh And wcHigh < &hDC00 Then
|
---|
1062 | If &hDC00 <= wcLow And wcLow < &hE000 Then
|
---|
1063 | Return True
|
---|
1064 | End If
|
---|
1065 | End If
|
---|
1066 | Return False
|
---|
1067 | End Function
|
---|
1068 |
|
---|
1069 | Function _System_IsDoubleUnitChar(lead As WCHAR, trail As WCHAR) As Boolean
|
---|
1070 | Return _System_IsSurrogatePair(lead, trail)
|
---|
1071 | End Function
|
---|
1072 |
|
---|
1073 | Function _System_IsDoubleUnitChar(lead As SByte, trail As SByte) As Boolean
|
---|
1074 | Return IsDBCSLeadByte(lead) <> FALSE
|
---|
1075 | End Function
|
---|
1076 |
|
---|
1077 | Sub _System_FillChar(p As PWSTR, n As SIZE_T, c As WCHAR)
|
---|
1078 | Dim i As SIZE_T
|
---|
1079 | For i = 0 To ELM(n)
|
---|
1080 | p[i] = c
|
---|
1081 | Next
|
---|
1082 | End Sub
|
---|
1083 |
|
---|
1084 | Sub _System_FillChar(p As PSTR, n As SIZE_T, c As SByte)
|
---|
1085 | Dim i As SIZE_T
|
---|
1086 | For i = 0 To ELM(n)
|
---|
1087 | p[i] = c
|
---|
1088 | Next
|
---|
1089 | End Sub
|
---|
1090 |
|
---|
1091 | Function _System_ASCII_IsUpper(c As WCHAR) As Boolean
|
---|
1092 | Return c As DWord - &h41 < 26 ' &h41 = Asc("A")
|
---|
1093 | End Function
|
---|
1094 |
|
---|
1095 | Function _System_ASCII_IsUpper(c As SByte) As Boolean
|
---|
1096 | Return _System_ASCII_IsUpper(c As Byte As WCHAR)
|
---|
1097 | End Function
|
---|
1098 |
|
---|
1099 | Function _System_ASCII_IsLower(c As WCHAR) As Boolean
|
---|
1100 | Return c As DWord - &h61 < 26 ' &h61 = Asc("a")
|
---|
1101 | End Function
|
---|
1102 |
|
---|
1103 | Function _System_ASCII_IsLower(c As Char) As Boolean
|
---|
1104 | Return _System_ASCII_IsLower(c As Byte As WCHAR)
|
---|
1105 | End Function
|
---|
1106 |
|
---|
1107 | Function _System_ASCII_ToLower(c As WCHAR) As WCHAR
|
---|
1108 | If _System_ASCII_IsUpper(c) Then
|
---|
1109 | Return c Or &h20
|
---|
1110 | Else
|
---|
1111 | Return c
|
---|
1112 | End If
|
---|
1113 | End Function
|
---|
1114 |
|
---|
1115 | Function _System_ASCII_ToLower(c As SByte) As SByte
|
---|
1116 | Return _System_ASCII_ToLower(c As Byte As WCHAR) As Byte As SByte
|
---|
1117 | End Function
|
---|
1118 |
|
---|
1119 | Function _System_ASCII_ToUpper(c As Char) As Char
|
---|
1120 | If _System_ASCII_IsLower(c) Then
|
---|
1121 | Return c And (Not &h20)
|
---|
1122 | Else
|
---|
1123 | Return c
|
---|
1124 | End If
|
---|
1125 | End Function
|
---|
1126 |
|
---|
1127 | Function _System_ASCII_ToUpper(c As SByte) As SByte
|
---|
1128 | Return _System_ASCII_ToUpper(c As Byte As WCHAR) As Byte As SByte
|
---|
1129 | End Function
|
---|
1130 |
|
---|
1131 |
|
---|
1132 | Function _System_StrCmp(s1 As PCSTR, s2 As PCSTR) As Long
|
---|
1133 | Dim i = 0 As SIZE_T
|
---|
1134 | While s1[i] = s2[i]
|
---|
1135 | If s1[i] = 0 Then
|
---|
1136 | Exit While
|
---|
1137 | End If
|
---|
1138 | i++
|
---|
1139 | Wend
|
---|
1140 | _System_StrCmp = s1[i] - s2[i]
|
---|
1141 | End Function
|
---|
1142 |
|
---|
1143 | Function _System_StrCmp(s1 As PCWSTR, s2 As PCWSTR) As Long
|
---|
1144 | Dim i = 0 As SIZE_T
|
---|
1145 | While s1[i] = s2[i]
|
---|
1146 | If s1[i] = 0 Then
|
---|
1147 | Exit While
|
---|
1148 | End If
|
---|
1149 | i++
|
---|
1150 | Wend
|
---|
1151 | _System_StrCmp = s1[i] - s2[i]
|
---|
1152 | End Function
|
---|
1153 |
|
---|
1154 | #endif '_INC_FUNCTION
|
---|