2.3 Standard Conversion Tasks

The following are some common tasks you need to perform when using a standard converter:

2.3.1 Converting Bytes to Unicode with a Standard Converter

NOTE:If the minimum size of the output buffer for the Unicode string is important to your application but is not known, see Performing a Standard Conversion on a String of Unknown Size.

  1. If you have not already done so, call NWUSStandardUnicodeInit.

  2. Supply an output buffer of sufficient size to hold the output Unicode string.

  3. Call NWUSByteToUnicode or NWUSLenByteToUnicode unless the string is a path. For path strings, call NWUSByteToUnicodePath or NWUSLenByteToUnicodePath.

    • For the unicodeOutput parameter, pass a pointer to the output buffer.
    • For outputBufferLen, pass the length of the output buffer in bytes.
    • For byteInput, pass a pointer to the input buffer.
    • For inLength of the *Len* functions, pass the length of the input string in bytes (might not include a NULL terminator).
  4. Use the Unicode string pointed to by unicodeOutput as needed when the function returns.

  5. After all standard Unicode conversion operations are completed, call NWUSStandardUnicodeRelease.

2.3.2 Converting Unicode to Bytes with a Standard Converter

NOTE:If the required size for the output byte string buffer is not known, see Performing a Standard Conversion on a String of Unknown Size.

  1. If you have not already done so, call NWUSStandardUnicodeInit.

  2. Supply an output buffer of sufficient size to hold the output byte string.

  3. Call NWUSUnicodeToByte or NWUSUnicodeToUntermByte unless the string is a path. For path strings, call NWUSUnicodeToBytePath or NWUSUnicodeToUntermBytePath.

    • For byteOutput, pass a pointer to the output buffer.
    • For outputBufferLen, pass the length of the output buffer in bytes.
    • For unicodeInput, pass a pointer to the input buffer.
  4. When the function returns, use the Unicode string pointed to by unicodeOutput as needed.

  5. After all standard Unicode conversion operations are completed, call NWUSStandardUnicodeRelease.

For related information, see Converting Bytes to Unicode with a Standard Converter

2.3.3 Converting Path Strings with a Standard Converter

  1. If you have not done so already, call NWUSStandardUnicodeInit.

  2. Convert as explained in Converting Bytes to Unicode with a Standard Converter or Converting Unicode to Bytes with a Standard Converter, but call one of the following path-specific functions:

2.3.4 Performing a Standard Conversion on a String of Unknown Size

  1. If you have not already done so, call NWUSStandardUnicodeInit.

  2. Call the appropriate conversion function, but set the output buffer to NULL. The outputBufferLen parameter is then ignored.

    NWUSByteToUnicode(NULL, 0, byteInput, &actualLength);

  3. Add one to the returned actualLength for the NULL terminator. If the output is to be a Unicode string, multiply actualLength by sizeof(unicode) to get the required number of bytes. Then allocate memory.

    bufsiz=actualLength+1;

    outbuf=(punicode)malloc(bufsize*sizeof(unicode));

  4. Do the real conversion.

    NWUSByteToUnicode(outbuf, bufsize, byteInput, NULL);

  5. After all standard Unicode conversion operations are completed, call NWUSStandardUnicodeRelease.

2.3.5 Finding Out Which Code Page a Standard Converter Uses

  1. Call NWUSGetCodePage. On return, the pCodePage parameter points to the code page and the pCountry parameter points to the country code used by the standard converter currently loaded. If a standard converter is not currently loaded, NWUSGetCodePage returns the code page and country code that will be used when NWUXStandardUnicodeInit is called.

For related information, see: