libtconv-0.1 manual
tconv_mbslen
unsigned int tconv_mbslen(tconv *tcP, const wchar_t *wcP, unsigned char errBrk);
declared in tconv.h, include tconv.h

tcP handle of an existing tconv instance,
wcP location of wide-character string,
errBrk error state decision flag.

Function tells the length in bytes (not characters) for provided wide-character string. This value increased by one, can further be used to allocate HEAP memory for NULL-terminated, multi-byte representation of that string.

For proper calculation, internal output character encoding needs to be set.

The errBrk property tells whether the string length calculation should be stopped in case of an error or not. If this value is greater than 0 (zero) and internal character conversion fails, the function detects this and returns with tconvError value.

Example
/* C source */

#include <stdio.h>
#include "tconv.h"

void main(){
  tconv *tcP;
  unsigned int mbLen;
  // 0x105 - 'a+tail'
  // 0x107 - 'c+tail'
  const wchar_t wcS[]= { 0x105, 'b', 0x107,
    'd', 'e', 0 };

  const wchar_t *wcP = wcS;
  char mbB[16];

#ifndef WIN32
  tcP = tconv_init(NULL, "pl_PL.utf8");
#else
  tcP = tconv_init(NULL, "UTF8");
#endif

  mbLen = tconv_mbslen(tcP,wcS,0); // 7
  printf("mbLen is %i bytes long\n", mbLen);
  tconv_free(tcP); 
}
Copyright 2015 TinyIT All rights reserved
Last modified 2015-06-04