Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

Converting from Unicode UTF-16 to UTF-8

FairCom DB provides conversion routines between UTF‑8 and UTF‑16. The input strings are assumed to be terminated by a NULL character. All output buffer sizes are specified in bytes. The conversion routines return CTDBRET_OK (0) on success, error VBSZ_ERR (153) if the output buffer is too small, or error BMOD_ERR (446) if there is a problem with the input string.

ctdb_u8TOu16() converts an ASCII or UTF-8 encoded string to a UTF-16 Unicode string:

NINT ctdb_u8TOu16(pTEXT u8str, pWCHAR u16str, NINT u16size);

c-treeDB C API Example

WCHAR buffer[256];

switch (ctdb_u8TOu16("tablename", buffer, sizeof(buffer))

{

case CTDBRET_OK:

{

printf("UTF-8 to UTF-16 conversion ok\n");

break;

}

case VBSZ_ERR:

{

printf("Conversion buffer is too small\n");

break;

}

case BMOD_ERR:

{

printf("Problem occurred during conversion\n");

break;

}

default:

{

printf("Unknown error code\n");

break;

}

}

ctdb_u16TOu8() converts a UTF-16 encoded string to a UTF-8 Unicode string:

NINT ctu16TOu8(pWCHAR u16str, pTEXT u8str, NINT u8size);

c-treeDB C API Example

TEXT buffer[512];

switch (ctdb_u16TOu8(tableName, buffer, sizeof(buffer))

{
case CTDBRET_OK:

{

printf("UTF-16 to UTF-8 conversion ok\n");

break;

}

case VBSZ_ERR:

{

printf("Conversion buffer is too small\n");

break;

}

case BMOD_ERR:

{

printf("Problem occurred during conversion\n");

break;

}

default:

{

printf("Unknown error code\n");

break;

}

}

TOCIndex