qb64-include/btoa.bm

22 lines
798 B
Text
Raw Normal View History

2022-09-19 01:27:48 +02:00
$if btoa = undefined then
$let btoa = defined
2022-05-09 12:36:52 +02:00
Function btoa$ (s As String)
Const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim c1 As _Byte
Dim c2 As _Byte
Dim c3 As _Byte
Dim c4 As _Byte
Dim i As Long
Dim As String Buffer
For i = 1 To Len(s) Step 4
c1 = InStr(B64, Mid$(s, i + 0, 1)) - 1
c2 = InStr(B64, Mid$(s, i + 1, 1)) - 1
c3 = InStr(B64, Mid$(s, i + 2, 1)) - 1
c4 = InStr(B64, Mid$(s, i + 3, 1)) - 1
If c2 > -1 Then Buffer = Buffer + Chr$(((c1 * 4 + c2 \ 16) And 255))
If c3 > -1 Then Buffer = Buffer + Chr$(((c2 * 16 + c3 \ 4) And 255))
If c4 > -1 Then Buffer = Buffer + Chr$(((c3 * 64 + c4) And 255))
Next i
btoa$ = Buffer
2022-09-19 01:27:48 +02:00
End Function
$end if