I am doing some cross platform coding, and I am getting stuck with these 2 functions
StringByteLength()
CopyMemory()
How can I replicate these 2 functons with SpiderBasic?
How to make StringByteLengthand Copymemory with SB?
-
- Posts: 21
- Joined: Wed May 01, 2019 10:14 am
Re: How to make StringByteLengthand Copymemory with SB?
Both should be doable with Peek/Poke combination, could you post your sample code to see if it can be done otherwise ?
Re: How to make StringByteLengthand Copymemory with SB?
StringByteLength(): Perhaps this one?
Code: Select all
Procedure StringByteLength(String$, Format = #PB_Unicode)
Protected sbl
Select Format
Case #PB_Ascii
sbl = Len(String$)
Case #PB_UTF8, #PB_Unicode
! v_sbl = new Blob([v_string$]).size;
EndSelect
ProcedureReturn sbl
EndProcedure
Debug StringByteLength("a", #PB_Ascii)
Debug StringByteLength("a", #PB_UTF8)
Debug StringByteLength("a", #PB_Unicode)
Debug StringByteLength("ä", #PB_Ascii)
Debug StringByteLength("ä", #PB_UTF8)
Debug StringByteLength("ä", #PB_Unicode)
-
- Posts: 21
- Joined: Wed May 01, 2019 10:14 am
Re: How to make StringByteLengthand Copymemory with SB?
Code: Select all
Structure _membersMemoryFileClass
eof.w
flags.w
fileBase.i
fileSize.i
initialSize.i
initialPageSize.i
usedFile.i ;Lof.
filePointer.i ;Loc.
EndStructure
Global Dim *Handle._membersMemoryFileClass(1)
memPTR() = *handle(0)\FilePointer;
CompilerIf Defined(SB_Compiler_SpiderBasic, #PB_Constant)
For i = 0 To lengthToRead - 1
PokeB( memoryBuffer, i, PeekB(memPTR(), i + memPTR()\filePointer) )
Next
CompilerElse
CopyMemory(memPTR()\FileBase + memPTR()\filePointer, memoryBuffer, lengthToRead)
CompilerEndIf
-
- Posts: 21
- Joined: Wed May 01, 2019 10:14 am
Re: How to make StringByteLengthand Copymemory with SB?
Peter wrote:StringByteLength(): Perhaps this one?
Code: Select all
Procedure StringByteLength(String$, Format = #PB_Unicode) Protected sbl Select Format Case #PB_Ascii sbl = Len(String$) Case #PB_UTF8, #PB_Unicode ! v_sbl = new Blob([v_string$]).size; EndSelect ProcedureReturn sbl EndProcedure Debug StringByteLength("a", #PB_Ascii) Debug StringByteLength("a", #PB_UTF8) Debug StringByteLength("a", #PB_Unicode) Debug StringByteLength("ä", #PB_Ascii) Debug StringByteLength("ä", #PB_UTF8) Debug StringByteLength("ä", #PB_Unicode)
Thats pretty cool, thanks
Re: How to make StringByteLengthand Copymemory with SB?
Note that the procedure has not been sufficiently tested. It may therefore return incorrect values.kingwolf71 wrote:Thats pretty cool, thanks