libtconv-0.1 manual
unsigned int tconv_convert(tconv *tcP, char *const outP, const char *const inP, const unsigned int max);
declared in tconv.h, include tconv.h

tcP handle of an existing tconv instance,
outP output buffer handle,
inP source text buffer handle,
max count of characters to convert.

This is a main tool to be used. It quickly converts a block of text from one character set to another. Function returns tconvError when it fails or number of bytes (not characters) converted, in case of success.

When max is set to 0 (zero), function assumes the input source is NULL-terminated and converts every character, until the final NULL-byte. When max is provided as positive integer, function attempts to convert exactly that number of characters but also stops when it finds the NULL-byte, before reaching max.

The output location needs to be wide enough to store entire set of converted characters.

/* C source */

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

void main(){
  tconv *tcP;
  tcP = tconv_init(NULL, NULL);

  static const char utf[]={"pl_PL.UTF8"};
  static const char iso[]={"pl_PL.iso_8859-2"};

  // a+tail; c+tail
  const char inUTF[]={ 0xc4, 0x85, 0xc4, 0x87, 0 };
  const char inISO[]={ 0xb1, 0xe6, 0 };
  char out[8];

  tconv_set_ienc(tcP, utf);
  tconv_set_oenc(tcP, iso);
  printf("%i\n", tconv_convert(tcP, out, inUTF, 0));
  // 2, out holds 2 bytes

  tconv_set_ienc(tcP, iso);
  tconv_set_oenc(tcP, utf);
  printf("%i\n", tconv_convert(tcP, out, inISO, 0));
  // 4, out holds 4 bytes (but 2 characters)

Copyright 2015 TinyIT All rights reserved
Last modified 2015-06-04