Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter FiveGeneral Functions (continued)

UnicodeToUTF Function

Overview

The UnicodeToUTF function takes an 16-bit wstring in Unicode and converts it to Unicode Text Format (UTF).

Syntax/Parameters

Syntax

string = UnicodeToUTF ( wstring data );

Parameters

data

A wstring containing Unicode text to convert.

Return Value

Returns a string containing the converted string. Use the IsError, IsNotError and GetLastError functions to determine if an error occurred and to retrieve a formatted error code.

Remarks

The function moves through the source data and encodes 16-bit Unicode characters to 8-bit text.

Note that there is no way to explicitly tell an 8-bit string’s encoding. Further, if written to a file, a UTF header may need to be manually inserted, depending on the eventual use of the data. For example:

    string          src, dst;
    string          s1;
    wstring         w1;
    int             rc;

    src = "(insert source name)";
    dst = "(insert destination name)";

    w1 = FileToString(src);
    if (w1 == "") {
      MessageBox('x', "Error %08X loading source", GetLastError());
      exit;
      }

    s1 = UnicodeToUTF(w1);
    if (s1 == "") {
      MessageBox('x', "Error %08X converting", GetLastError());
      exit;
      }

    s1 = "\xEF\xBB\xBF" + s1;                       // Manually add header
    rc = StringToFile(s1, dst);
    if (IsError(rc)) {
      MessageBox('x', "Error %08X writing results", GetLastError());
      exit;
      }

 

Related Functions

Platform Support

Go13, Go16, GoFiler Complete, GoFiler Corporate, GoFiler, GoFiler Lite, GoXBRL

Legato IDE, Legato Basic