ASCIItoUnicode & UnicodeToASCII conversions
Posted: Sat Aug 09, 2014 3:53 pm
Given the current announcement, can we get these commands expedited, so we can begin our transitions?
Thanks.
Thanks.
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
Procedure.i UnicodeToAscii(*UnicodeIn, *AsciiOut)
; *UnicodeIn : zero terminated unicode input buffer
; *AsciiOut : zero terminated ascii output buffer
; Result : number of converted characters (zero character not included)
!mov eax, -1
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!mov [esp - 4], ebx
!mov ebx, [p.p_UnicodeIn]
!mov edx, [p.p_AsciiOut]
!ua_loop:
!inc eax
!mov cx, [ebx + eax * 2]
!mov [edx + eax], cl
CompilerElse
!mov r8, [p.p_UnicodeIn]
!mov r9, [p.p_AsciiOut]
!ua_loop:
!inc eax
!mov cx, [r8 + rax * 2]
!mov [r9 + rax], cl
CompilerEndIf
!and cx, cx
!jnz ua_loop
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!mov ebx, [esp - 4]
CompilerEndIf
ProcedureReturn
EndProcedure
Procedure.i AsciiToUnicode(*AsciiIn, *UnicodeOut)
; *AsciiIn : zero terminated ascii input buffer
; *UnicodeOut : zero terminated unicode output buffer
; Result : number of converted characters (zero character not included)
!mov eax, -1
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!mov [esp - 4], ebx
!mov ebx, [p.p_AsciiIn]
!mov edx, [p.p_UnicodeOut]
!au_loop:
!inc eax
!movzx cx, byte [ebx + eax]
!mov [edx + eax * 2], cx
CompilerElse
!mov r8, [p.p_AsciiIn]
!mov r9, [p.p_UnicodeOut]
!au_loop:
!inc eax
!movzx cx, byte [r8 + rax]
!mov [r9 + rax * 2], cx
CompilerEndIf
!and cx, cx
!jnz au_loop
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
!mov ebx, [esp - 4]
CompilerEndIf
ProcedureReturn
EndProcedure
MemSize = 1024 * 1024; Reserve 1 MB
*In = AllocateMemory(MemSize)
*Out = AllocateMemory(MemSize)
PokeS(*In, "Test", -1, #PB_Ascii)
Debug AsciiToUnicode(*In, *Out)
Debug PeekS(*Out, -1, #PB_Unicode)