C$UTF16-UFT8 using utf-16-item, itemlen [, destination [, destinationlen]]
The return value is the number of characters moved to the destination data item, or the number that would be needed (when the destination item is missing or NULL).
If fewer characters are placed in the destination than there is room for, the routine will pad the destination with spaces.
Using the following data definitions:
01 my-string-1 pic x(100). 01 my-string-2 pic x(100). 01 my-pointer pointer. 01 my-len signed-int. 01 alloc-len signed-int.
In the following example, although the source (my-string-1) is 26 characters, the CALL translates only the first 10 characters into UTF-8. The amount of space required for translation is calculated, allocated, and then translated into that buffer, which is then freed upon completion of the translation.
MOVE "abcdefghijklmnopqrstuvwxyz" to my-string-1. CALL "C$UTF16-UTF8" using my-string-1, 10. MOVE return-code to my-len. DIVIDE my-len by 2 GIVING alloc-len. *> UTF-16 uses 2 bytes per character CALL "M$ALLOC" using alloc-len my-pointer. CALL "C$UTF16-UTF8" using my-string-1, 10, my-pointer, my-len. CALL "M$FREE" using my-pointer.