Ignore:
Timestamp:
Jul 25, 2002, 11:51:53 PM (23 years ago)
Author:
umoeller
Message:

misc fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/encodings.c

    r191 r192  
    33 *@@sourcefile encodings.c:
    44 *      character encoding support. Handles all kinds
    5  *      of legacy codepages (including most OS/2 codepage)
     5 *      of legacy codepages (including most OS/2 codepages)
    66 *      and Unicode in the form of UTF-8 and translations
    77 *      between then.
     
    1010 *
    1111 *      Be warned, compilation of this file takes a long
    12  *      file because this includes all the complex codepage
     12 *      file because this includes all the complex codepages
    1313 *      from include\encodings.
    1414 *
     
    163163            *ppMap = G_aEncodings[ul].pMap;
    164164            *pcEntries = G_aEncodings[ul].cEntries;
    165             return (1);
     165            return 1;
    166166        }
    167167    }
    168168
    169     return (0);
     169    return 0;
    170170}
    171171
     
    198198    }
    199199
    200     return (UNSUPPORTED);
     200    return UNSUPPORTED;
    201201}
    202202
     
    330330                    }
    331331
    332                     return (pTableNew);
     332                    return pTableNew;
    333333                }
    334334
     
    385385         && (c <= pTable->usHighestCP)
    386386       )
    387         return (pTable->ausEntriesUniFromCP[c]);
    388 
    389     return (0xFFFF);
     387        return pTable->ausEntriesUniFromCP[c];
     388
     389    return 0xFFFF;
    390390}
    391391
     
    410410         && (ulUni <= pTable->usHighestUni)
    411411       )
    412         return (pTable->ausEntriesCPFromUni[ulUni]);
    413 
    414     return (0xFFFF);
     412        return pTable->ausEntriesCPFromUni[ulUni];
     413
     414    return 0xFFFF;
    415415}
    416416
     
    445445{
    446446    unsigned long   ulChar;
     447    unsigned long   ulCount;
     448    int             fIllegal;
    447449
    448450    if (!(ulChar = **ppch))
     
    455457    {
    456458        (*ppch)++;
    457         return (ulChar);
     459        return ulChar;
     460    }
     461
     462    ulCount = 1;
     463    fIllegal = 0;
     464
     465    // note: 0xc0 and 0xc1 are reserved and
     466    // cannot appear as the first UTF-8 byte
     467
     468    if (    (ulChar >= 0xc2)
     469         && (ulChar < 0xe0)
     470       )
     471    {
     472        // that's two bytes
     473        ulCount = 2;
     474        ulChar &= 0x1f;
     475    }
     476    else if ((ulChar & 0xf0) == 0xe0)
     477    {
     478        // three bytes
     479        ulCount = 3;
     480        ulChar &= 0x0f;
     481    }
     482    else if ((ulChar & 0xf8) == 0xf0)
     483    {
     484        // four bytes
     485        ulCount = 4;
     486        ulChar &= 0x07;
     487    }
     488    else if ((ulChar & 0xfc) == 0xf8)
     489    {
     490        // five bytes
     491        ulCount = 5;
     492        ulChar &= 0x03;
     493    }
     494    else if ((ulChar & 0xfe) == 0xfc)
     495    {
     496        // six bytes
     497        ulCount = 6;
     498        ulChar &= 0x01;
    458499    }
    459500    else
    460     {
    461         unsigned long ulCount = 1;
    462         int fIllegal = 0;
    463 
    464         // note: 0xc0 and 0xc1 are reserved and
    465         // cannot appear as the first UTF-8 byte
    466 
    467         if (    (ulChar >= 0xc2)
    468              && (ulChar < 0xe0)
    469            )
     501        ++fIllegal;
     502
     503    if (!fIllegal)
     504    {
     505        // go for the second and more bytes then
     506        int ul2;
     507
     508        for (ul2 = 1;
     509             ul2 < ulCount;
     510             ++ul2)
    470511        {
    471             // that's two bytes
    472             ulCount = 2;
    473             ulChar &= 0x1f;
     512            unsigned long ulChar2 = *((*ppch) + ul2);
     513
     514            if (!(ulChar2 & 0xc0)) //  != 0x80)
     515            {
     516                ++fIllegal;
     517                break;
     518            }
     519
     520            ulChar <<= 6;
     521            ulChar |= ulChar2 & 0x3f;
    474522        }
    475         else if ((ulChar & 0xf0) == 0xe0)
     523    }
     524
     525    if (fIllegal)
     526    {
     527        // skip all the following characters
     528        // until we find something with bit 7 off
     529        do
    476530        {
    477             // three bytes
    478             ulCount = 3;
    479             ulChar &= 0x0f;
    480         }
    481         else if ((ulChar & 0xf8) == 0xf0)
    482         {
    483             // four bytes
    484             ulCount = 4;
    485             ulChar &= 0x07;
    486         }
    487         else if ((ulChar & 0xfc) == 0xf8)
    488         {
    489             // five bytes
    490             ulCount = 5;
    491             ulChar &= 0x03;
    492         }
    493         else if ((ulChar & 0xfe) == 0xfc)
    494         {
    495             // six bytes
    496             ulCount = 6;
    497             ulChar &= 0x01;
    498         }
    499         else
    500             ++fIllegal;
    501 
    502         if (!fIllegal)
    503         {
    504             // go for the second and more bytes then
    505             int ul2;
    506 
    507             for (ul2 = 1;
    508                  ul2 < ulCount;
    509                  ++ul2)
    510             {
    511                 unsigned long ulChar2 = *((*ppch) + ul2);
    512 
    513                 if (!(ulChar2 & 0xc0)) //  != 0x80)
    514                 {
    515                     ++fIllegal;
    516                     break;
    517                 }
    518 
    519                 ulChar <<= 6;
    520                 ulChar |= ulChar2 & 0x3f;
    521             }
    522         }
    523 
    524         if (fIllegal)
    525         {
    526             // skip all the following characters
    527             // until we find something with bit 7 off
    528             do
    529             {
    530                 ulChar = *(++(*ppch));
    531                 if (!ulChar)
    532                     break;
    533             } while (ulChar & 0x80);
    534         }
    535         else
    536             *ppch += ulCount;
    537     }
    538 
    539     return (ulChar);
     531            ulChar = *(++(*ppch));
     532            if (!ulChar)
     533                break;
     534        } while (ulChar & 0x80);
     535    }
     536    else
     537        *ppch += ulCount;
     538
     539    return ulChar;
    540540}
    541541
Note: See TracChangeset for help on using the changeset viewer.