libtconv-0.1 manual
tconv::mbs_len
unsigned int tconv::mbs_len(const wchar_t *wcP, unsigned char errBrk=0);
declared in tconv.h, include tconv.h

wcP location of wide-character string.
errBrk error state decision flag, optional, default is 0 (zero).

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 tconv::error value.

Example
// C++ source

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

using namespace std;

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

#ifndef WIN32
  tc.set_oenc("pl_PL.UTF8");
#else
  tc.set_oenc("UTF8");
#endif

  mbLen = tc.mbs_len(wcS); // 7
  cout << "mbLen is " << mbLen
    << " bytes long." << endl;

  return 0;
}
Copyright 2015 TinyIT All rights reserved
Last modified 2015-06-04