bit_utf8_to_TU (char *restrict str)
{
  BITCODE_TU wstr;
  int i = 0;
  int len = strlen (str);
  unsigned char c;

  wstr = malloc (2 * (len + 1));
  while ((c = *str++))
    {
      if (c < 128)
        {
          wstr[i++] = c;
        }
      else if ((c & 0xe0) == 0xc0)
        {
          /* ignore invalid utf8 for now */
          wstr[i++] = ((c & 0x1f) << 6) | (str[1] & 0x3f);
          str++;
        }
      else if ((c & 0xf0) == 0xe0)
        {
          /* ignore invalid utf8? */
          if ((unsigned char)str[1] < 0x80 || (unsigned char)str[1] > 0xBF
              || (unsigned char)str[2] < 0x80 || (unsigned char)str[2] > 0xBF)
            {
              LOG_WARN ("utf-8: BAD_CONTINUATION_BYTE %s", str);
            }
          if (c == 0xe0 && (unsigned char)str[1] < 0xa0)
            {
              LOG_WARN ("utf-8: NON_SHORTEST %s", str);
            }
          wstr[i++]
              = ((c & 0x0f) << 12) | ((str[1] & 0x3f) << 6) | (str[2] & 0x3f);
          str++;
          str++;
        }
      /* everything above 0xf0 exceeds ucs-2, 4-6 byte seqs */
    }
  wstr[i] = '\0';
  return wstr;
}
bit_utf8_to_TU (char *restrict str)
{
  BITCODE_TU wstr;
  int i = 0;
  int len = strlen (str);
  unsigned char c;

  wstr = malloc (2 * (len + 1));
  while ((c = *str++))
    {
      if (c < 128)
        {
          wstr[i++] = c;
        }
      else if ((c & 0xe0) == 0xc0)
        {
           
          wstr[i++] = ((c & 0x1f) << 6) | (str[1] & 0x3f);
          str++;
        }
      else if ((c & 0xf0) == 0xe0)
        {
           
          if ((unsigned char)str[1] < 0x80 || (unsigned char)str[1] > 0xBF
              || (unsigned char)str[2] < 0x80 || (unsigned char)str[2] > 0xBF)
            {
              LOG_WARN ("utf-8: BAD_CONTINUATION_BYTE %s", str);
            }
          if (c == 0xe0 && (unsigned char)str[1] < 0xa0)
            {
              LOG_WARN ("utf-8: NON_SHORTEST %s", str);
            }
          wstr[i++]
              = ((c & 0x0f) << 12) | ((str[1] & 0x3f) << 6) | (str[2] & 0x3f);
          str++;
          str++;
        }
       
    }
  wstr[i] = '\0';
  return wstr;
}