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

mbP location of multi-byte string.
errBrk error state decision flag, optional, default is 0 (zero).

Function tells the length of provided multi-byte string in wide-characters, the same way that strlen() does for standard ASCII strings. This value increased by one, can further be used to allocate HEAP memory for NULL-terminated, 'wide-character representation of that string.

To perform proper calculation, internal input 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 wcLen;
  // UTF8 0xc485 = 'a' with a tail below
  static const char utf8S[] = { 0xc4, 0x85, 'b',
    'c', 'd', 'e', 0 };

  tc.set_ienc("pl_PL.UTF8");
  wcLen = tc.wcs_len(utf8S); // 5

  cout << "wcLen is " << wcLen
    << " wide-chars long" << endl;
  
  return 0;
}
Copyright 2015 TinyIT All rights reserved
Last modified 2015-06-04