Re: DOS or Windows ASCII->Unicode converter

From: Doug Ewell (dewell@compuserve.com)
Date: Mon Jun 29 1998 - 01:30:49 EDT


Vik,

The following will do what you need, IF, as Longman pointed out, all
of the original text is pure 7-bit ASCII. Where it is not, the
conversions will very likely come out wrong.

If you are converting C libraries, you should be able to understand
and compile the code which follows.

This is quick and dirty, and certainly not fully Unicode-compliant,
so please don't anybody write to tell me so.

Assumptions:
- UINT is a 16-bit unsigned integer.
- Sufficient space has been allocated for both source and
  destination strings in the calling routine.

-----8<-----cut here-----8<-----cut here-----8<-----

/* converts a null-terminated ASCII string to Unicode */
void ascii_to_unicode(char *pSource, UINT *pDest)
{
    *pDest++ = 0xFEFF; /* insert byte-order mark */
    for ( ;; )
    {
        *pDest = (UINT) *pSource;

        if (*pDest == 0)
            break;

        pSource++;
        pDest++;
    }
}

/* converts a null-terminated Unicode string to ASCII */
void unicode_to_ascii(UINT *pSource, char *pDest)
{
    *pDest++ = 0xFEFF;
    for ( ;; )
    {
        if (*pSource != 0xFEFF) /* skip byte-order mark */
        {
            *pDest = (char) *pSource;
            pSource++;
        }

        if (*pDest == 0)
            break;

        pDest++;
    }
}



This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:40 EDT