ReadProgramString() to support Unicode

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

ReadProgramString() to support Unicode

Post by IdeasVacuum »

Currently ReadProgramString() does not support Unicode, yet many apps output Unicode.

Propose that ReadProgramString() syntax is enhanced to be similar to ReadString()
ReadProgramString(Program, #PB_UTF8)

For those that need to read output in unicode, the method below works, though it's not satisfactory if you want your app to give the User line-by-line progress:

Code: Select all

iSize.i = (1024 * SizeOf(character))
*Buffer = AllocateMemory(iSize)

iApp = RunProgram(sApp, sArgs, sWorkFolder, #PB_Program_Open | #PB_Program_Hide | #PB_Program_Read)

If iApp
         While ProgramRunning(iApp)
         
                   If AvailableProgramOutput(iApp)
         
                          ReadProgramData(iApp, *Buffer, iSize)
                              ;you can set the PeekS text into a ListView/EditorGadget etc
                              Debug PeekS(*Buffer, iSize, #PB_UTF8)
                               FillMemory(*Buffer, iSize, '0', #PB_Character)
                   EndIf
         Wend

         CloseProgram(iApp)
EndIf

FreeMemory(*Buffer)
Edit: Though on WinXP x86 the above code does not update chunk-by-chunk, it does so on Win7

Nevertheless, it would be far better to add unicode support to ReadProgramString(). In the meantime, the Help should be updated to inform that unicode is not supported.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.