ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

FF_T_SINT32 FF_Utf16ctoUtf8c ( FF_T_UINT8 utf8Dest,
const FF_T_UINT16 utf16Source,
FF_T_UINT32  ulSize 
)

Definition at line 142 of file ff_unicode.c.

Referenced by FF_FindEntryInDir(), FF_PopulateLongDirent(), and FF_Utf32stoUtf8s().

                                                                                                       {
    FF_T_UINT32 ulUtf32char;
    FF_T_UINT16 ulUtf16char;

    if(!ulSize) {
        return FF_ERR_UNICODE_DEST_TOO_SMALL;
    }

        memcpy(&ulUtf16char, utf16Source, sizeof(FF_T_UINT16));
    if((/*bobtntfullfat *utf16Source*/ulUtf16char & 0xF800) == 0xD800) {    // A surrogate sequence was encountered. Must transform to UTF32 first.
                ulUtf32char  = ((FF_T_UINT32) (ulUtf16char & 0x003FF) << 10) + 0x10000;
        //bobtntfullfat ulUtf32char  = ((FF_T_UINT32) (*(utf16Source + 0) & 0x003FF) << 10) + 0x10000;

                memcpy(&ulUtf16char, utf16Source + 1, sizeof(FF_T_UINT16));                
        if((/*bobtntfullfat *(utf16Source + 1)*/ulUtf16char & 0xFC00) != 0xDC00) {
            return FF_ERR_UNICODE_INVALID_SEQUENCE; // Invalid UTF-16 sequence.
        }
        ulUtf32char |= ((FF_T_UINT32) (/*bobtntfullfat *(utf16Source + 1)*/ulUtf16char & 0x003FF));

    } else {
        ulUtf32char = (FF_T_UINT32) /*bobtntfullfat *utf16Source*/ulUtf16char;
    }

    // Now convert to the UTF-8 sequence.
    if(ulUtf32char < 0x00000080) {  // Single byte UTF-8 sequence.
        *(utf8Dest + 0) = (FF_T_UINT8) ulUtf32char;
        return 1;
    }

    if(ulUtf32char < 0x00000800) {  // Double byte UTF-8 sequence.
        if(ulSize < 2) {
            return FF_ERR_UNICODE_DEST_TOO_SMALL;
        }
        *(utf8Dest + 0) = (FF_T_UINT8) (0xC0 | ((ulUtf32char >> 6) & 0x1F));
        *(utf8Dest + 1) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 0) & 0x3F));
        return 2;
    }

    if(ulUtf32char < 0x00010000) {  // Triple byte UTF-8 sequence.
        if(ulSize < 3) {
            return FF_ERR_UNICODE_DEST_TOO_SMALL;
        }
        *(utf8Dest + 0) = (FF_T_UINT8) (0xE0 | ((ulUtf32char >> 12) & 0x0F));
        *(utf8Dest + 1) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 6 ) & 0x3F));
        *(utf8Dest + 2) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 0 ) & 0x3F));
        return 3;
    }

    if(ulUtf32char < 0x00200000) {  // Quadruple byte UTF-8 sequence.
        if(ulSize < 4) {
            return FF_ERR_UNICODE_DEST_TOO_SMALL;
        }
        *(utf8Dest + 0) = (FF_T_UINT8) (0xF0 | ((ulUtf32char >> 18) & 0x07));
        *(utf8Dest + 1) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 12) & 0x3F));
        *(utf8Dest + 2) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 6 ) & 0x3F));
        *(utf8Dest + 3) = (FF_T_UINT8) (0x80 | ((ulUtf32char >> 0 ) & 0x3F));
        return 4;
    }

    return FF_ERR_UNICODE_INVALID_CODE; // Invalid Charachter
}

Generated on Sun May 27 2012 06:00:52 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.