Search code examples
openedgeprogress-4gl

Progress 4GL - How to convert data from UTF-8 to UTF-8 BOM?


Just to know from UTF-8 to UTF-8 BOM conversion. Below query I use and its not giving results as expected. correct me if I am wrong.

define stream m_str.
output stream m_str to value("C:\inetpub\file.txt") convert target "UTF-8".
/*Data goes here*/
output stream m_str close.

Solution

  • google site:progress.com output utf-8 bom

    https://community.progress.com/s/article/P110483

    UTF-8 encoding in most cases does not require a byte-order mark (and in a number of cases forbids it), therefore it is not written to the file. This does cause issues with the few use cases where the BOM is required.

    Workaround The BOM can be added manually using the PUT CONTROL statement:

    OUTPUT TO c:\temp\js.html CONVERT TARGET "UTF-8".
    PUT CONTROL "~357~273~277". /* BOM for UTF-8 */
    
    /* actual output goes here */
    
    OUTPUT CLOSE.
    

    For clarification, ~nnn is an octal character, so:

    • 357 -> 0xEF
    • 273 -> 0xBB
    • 277 -> 0xBF

    Which corresponds with the Byte Order Mark byte sequence EF BB BF.

    Combining the above two links, you can also provide the less archaic Unicode character U+FEFF BYTE ORDER MARK:

    output to file.txt convert target 'utf-8'.
    put control '~ufeff'. // BOM
    
    // actual output goes here
    
    output close.