Back to index

im-sdk  12.3.91
Defines | Typedefs | Enumerations | Functions
utfchar.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define Bool   Boolean

Typedefs

typedef unsigned short UTFCHAR

Enumerations

enum  Boolean {
  True = 1, False = 0, True = 1, False = 0,
  True = 1, False = 0, True = 1, False = 0,
  True = 1, False = 0
}

Functions

int _utfchar_concat (UTFCHAR *dest, UTFCHAR *str1, UTFCHAR *str2)
int _utfchar_copy (UTFCHAR *dest, UTFCHAR *original)
int _utfchar_length (UTFCHAR *p)
int _utfchar_comp (UTFCHAR *s1, UTFCHAR *s2)
UTFCHAR_utfchar_convert_u8_to_u16 (unsigned char *u8str)
unsigned char * _utfchar_convert_u16_to_u8 (UTFCHAR *u16str)
UTFCHAR_utfchar_dup (UTFCHAR *src)

Define Documentation

#define Bool   Boolean

Definition at line 11 of file utfchar.h.


Typedef Documentation

typedef unsigned short UTFCHAR

Definition at line 5 of file utfchar.h.


Enumeration Type Documentation

enum Boolean
Enumerator:
True 
False 
True 
False 
True 
False 
True 
False 
True 
False 

Definition at line 8 of file utfchar.h.

             {
  True=1, False=0
} Boolean;

Function Documentation

int _utfchar_comp ( UTFCHAR s1,
UTFCHAR s2 
)

Definition at line 61 of file utfchar.c.

{
  UTFCHAR *p1, *p2;
  
  p1 = s1, p2 = s2;
  
  while (*p1 && *p2){
    if (*p1 > *p2)
      return 1;
    else if (*p1 < *p2)
      return -1;
    p1++, p2++;
  }
  if (!*p1 && *p2)
    return -1;
  if (!*p2 && *p1)
    return 1;
  return 0;
}
int _utfchar_concat ( UTFCHAR dest,
UTFCHAR str1,
UTFCHAR str2 
)

Definition at line 9 of file utfchar.c.

{
      int i;
      for (i = 0; *str1; i++) {
         *dest++ = *str1++;
      }
      for (i = 0; *str2; i++) {
         *dest++ = *str2++;
      }
      *dest = 0;
      return i;
}
unsigned char* _utfchar_convert_u16_to_u8 ( UTFCHAR u16str)

Definition at line 201 of file utfchar.c.

{
  char inbuf[1024], outbuf[1024];
#if 0  
  char *inbuf, *outbuf;
#endif
  int inlen, outlen, outlen2;
  char *inptr, *outptr;
  unsigned char *p8char;
  iconv_t cd;
  size_t iconv_ret;

  assert (u16str != NULL);
  if (!u16str || _utfchar_length (u16str) == 0){
    fprintf (stdout, "_dictionary_convert_u16_to_u8 error: "
            "u16str is null or zero length\n");
    return NULL;

  }
#if 0
  inlen = (_utfchar_length (u16str) + 1) * sizeof (UTFCHAR);
  inbuf =
    (char *) calloc (_utfchar_length (u16str) + 1, sizeof (UTFCHAR));
  memcpy (inbuf, u16str, sizeof (UTFCHAR) * inlen);
  inptr = inbuf;
#endif
  inlen = sizeof (inbuf);
  memset (inbuf, 0, inlen);
  memcpy (inbuf, u16str, _utfchar_length (u16str) * sizeof (UTFCHAR ));
  inptr = inbuf;
  
#if 0
  /* just to be safe enough to hold converted string */
  outbuf =
    (unsigned char *) calloc (2 * inlen, sizeof (unsigned char));
  outlen2 = outlen = inlen * 2;
  outptr = outbuf;
#endif
  
  outlen2 = outlen = sizeof (outbuf);
  memset (outbuf, 0, outlen);
  outptr = outbuf;

  cd = iconv_open ("UTF-8", "UTF-16");
  if (cd == (iconv_t) -1){
    fprintf (stdout, "_dictionary_convert_u16_to_u8 error: "
            "iconv_open failed\n");
    return NULL;
  }
  
  iconv_ret = iconv (cd, &inptr, &inlen, &outptr, &outlen);
  
  if (iconv_ret == (size_t) -1){
    fprintf (stdout, "_dictionary_convert_u16_to_u8 error: "
            "iconv failed\n");
    if (cd != (iconv_t) -1)
      iconv_close (cd);
    return NULL;
  }
  
  p8char =
    (unsigned char *)calloc (outlen2 - outlen + 1, sizeof (unsigned char));
  if(!p8char){
    fprintf (stdout, "_dictionary_convert_u16_to_u8 error: "
            "memory allocation error\n");
    return NULL;
  }
  memcpy (p8char, outbuf, outlen2 - outlen);
#if 0
  free (inbuf);
  free (outbuf);
#endif
  iconv_close (cd);
  return p8char;

}

Here is the call graph for this function:

Here is the caller graph for this function:

UTFCHAR* _utfchar_convert_u8_to_u16 ( unsigned char *  u8str)

Definition at line 117 of file utfchar.c.

{
  char *inbuf, *outbuf;
  int inlen, outlen, outlen2;
  char *inptr, *outptr;
  UTFCHAR *p16char;
  iconv_t cd;
  size_t iconv_ret;

  assert (u8str != NULL);
  if (!u8str || strlen (u8str) == 0){
    fprintf (stdout, "_dictionary_convert_u8_to_u16 error: "
            "u8str is null or zero length");
    return NULL;
  }
  inlen = strlen (u8str);
  inbuf = (unsigned char *) calloc (inlen + 1, sizeof (unsigned char));
  strcpy (inbuf, u8str);
  /* just to be safe enough to hold converted string */
  outbuf =
    (unsigned char *) calloc (2 * (inlen + 1), sizeof (unsigned char));
  inptr = inbuf;
  outptr = outbuf;
  inlen = strlen (u8str);
  outlen2 = outlen = inlen * 2;

  cd = iconv_open ("UTF-16", "UTF-8");
  if (cd == (iconv_t) -1){
    fprintf (stdout, "_utfchar_convert_u8_to_u16 error :"
            "iconv_open failed\n");
    return NULL;
  }
  
  iconv_ret = iconv (cd, &inptr, &inlen, &outptr, &outlen);
  if (iconv_ret == (size_t) -1){
    fprintf (stdout, "_utfchar_convert_u8_to_u16 error :"
            "iconv failed\n");
    iconv_close (cd);
    free (inbuf);
    free (outbuf);
    
    return NULL;
  }
  
  if ((outbuf[0] == (char) 0xff) &&
      (outbuf[1] == (char) 0xff || outbuf[1] == (char) 0xfe)) {
    p16char =
      (UTFCHAR *) calloc ((outlen2 - outlen - 1) / 2 +1, sizeof (UTFCHAR));
    if(!p16char){
      fprintf (stdout, "_dictionary_convert_u8_to_u16 error: "
              "memory allocation error\n");
      iconv_close (cd);
      free (inbuf);
      free (outbuf);
    
      return NULL;
    }
    memcpy (p16char, outbuf + 2, outlen2 - outlen - 2);
    
  } else {
    
    p16char =
      (UTFCHAR *) calloc ((outlen2 - outlen)/2 + 1, sizeof (UTFCHAR));
    if(!p16char){
      fprintf (stdout, "_dictionary_convert_u8_to_u16 error: "
              "memory allocation error\n");
      iconv_close (cd);
      free (inbuf);
      free (outbuf);
    
      return NULL;
    }

    memcpy (p16char, outbuf, outlen2 - outlen);
  }

  free (inbuf);
  free (outbuf);
  iconv_close (cd);
  
  return p16char;
}

Here is the caller graph for this function:

int _utfchar_copy ( UTFCHAR dest,
UTFCHAR original 
)

Definition at line 36 of file utfchar.c.

{
       int i;
       if (dest == NULL || original == NULL)
              return -1;
       for (i = 0; *original; i++) {
              *dest++ = *original++;
       }
       *dest = 0;
       return i;
}

Here is the caller graph for this function:

Definition at line 23 of file utfchar.c.

{
  UTFCHAR *new_utfchar;
  int n_len;
  n_len = _utfchar_length (src);
  if (n_len == 0)
    return NULL;
  new_utfchar = (UTFCHAR *) calloc (n_len + 1, sizeof (UTFCHAR ));
  _utfchar_copy (new_utfchar, src);
  return new_utfchar;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int _utfchar_length ( UTFCHAR p)

Definition at line 49 of file utfchar.c.

{
      int i;
              assert (p != NULL);
              if (p == NULL)
                     return 0;
      for (i = 0; *p; i++)
         p++;
      return i;
}

Here is the caller graph for this function: