Ignore:
Timestamp:
Jul 22, 2002, 10:08:02 PM (23 years ago)
Author:
umoeller
Message:

DBCS fixes.

File:
1 edited

Legend:

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

    r185 r190  
    198198 *
    199199 *@@added V0.9.19 (2002-06-13) [umoeller]
     200 *@@changed V0.9.20 (2002-07-22) [umoeller]: optimized
     201 *@@changed V0.9.20 (2002-07-22) [lafaix]: optimized
    200202 */
    201203
     
    203205{
    204206    PCSZ    p2;
    205     ULONG   ulDBCS;
     207    ULONG   ulDBCSType = TYPE_SBCS;
    206208
    207209    if (!nlsDBCS())
     
    209211        return strchr(p, c);
    210212
     213    // we're on DBCS:
     214
     215    // we can't find c if it is a leading byte
     216    if (G_afLeadByte[c] != TYPE_SBCS)
     217        return NULL;
     218
     219    for (p2 = p;
     220         *p2;
     221         ++p2)
     222    {
     223        // check _previous_ DBCS type and refresh
     224        // DBCS type accordingly
     225        switch (ulDBCSType)
     226        {
     227            case TYPE_SBCS:
     228            case TYPE_DBCS_2ND:
     229                ulDBCSType = G_afLeadByte[*p2];
     230                // we can safely do the test here (and skip rechecking
     231                // the type) because c can't possibly be a leading byte
     232                // V0.9.20 (2002-07-22) [lafaix]
     233                if (*p2 == c)
     234                    return (PSZ)p2;
     235            break;
     236
     237            case TYPE_DBCS_1ST :
     238                ulDBCSType = TYPE_DBCS_2ND;
     239            break;
     240        }
     241    }
     242
     243    /*  old code V0.9.20 (2002-07-22) [umoeller]
    211244    // we're on DBCS:
    212245    for (p2 = p;
     
    228261        }
    229262    }
     263    */
    230264
    231265    return NULL;
     
    240274 *
    241275 *@@added V0.9.19 (2002-06-13) [umoeller]
     276 *@@changed V0.9.20 (2002-07-22) [lafaix]: optimized
    242277 */
    243278
    244279PSZ nlsrchr(PCSZ p, char c)
    245280{
    246     PCSZ    p2;
    247     ULONG   ulDBCS,
    248             ulLength;
     281    PCSZ    p2,
     282            pLast = NULL;
     283    ULONG   ulDBCSType = TYPE_SBCS;
    249284
    250285    if (!nlsDBCS())
     
    253288
    254289    // we're on DBCS:
     290
     291    // we can't find c if it is a leading byte
     292    if (G_afLeadByte[c] != TYPE_SBCS)
     293        return NULL;
     294
     295    for (p2 = p;
     296         *p2;
     297         ++p2)
     298    {
     299        // check _previous_ DBCS type and refresh
     300        // DBCS type accordingly
     301        switch (ulDBCSType)
     302        {
     303            case TYPE_SBCS:
     304            case TYPE_DBCS_2ND:
     305                ulDBCSType = G_afLeadByte[*p2];
     306                if (*p2 == c)
     307                    pLast = p2;
     308            break;
     309
     310            case TYPE_DBCS_1ST :
     311                ulDBCSType = TYPE_DBCS_2ND;
     312            break;
     313        }
     314    }
     315
     316    return (PSZ)pLast;
     317
     318    // old code V0.9.20 (2002-07-22) [lafaix]
     319    /*
    255320    ulLength = strlen(p);
    256321    for (p2 = p + ulLength - 1;
     
    274339
    275340    return NULL;
     341    */
    276342}
    277343
Note: See TracChangeset for help on using the changeset viewer.