Ignore:
Timestamp:
Feb 20, 2019, 8:00:49 AM (6 years ago)
Author:
rlwalsh
Message:

nls: rewrite nlschr()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/src/helpers/nls.c

    r437 r444  
    243243 *      replacement for strchr with DBCS support.
    244244 *
     245 *      This finds single-byte characters in strings
     246 *      that may contain DBCS characters. Both DBCS
     247 *      leading and trailing bytes are ignored, even
     248 *      if one of them matches the search character.
     249 *
    245250 *      If the system is not running with DBCS,
    246251 *      this calls plain strchr automatically.
    247252 *
    248  *@@added V0.9.19 (2002-06-13) [umoeller]
    249  *@@changed V0.9.20 (2002-07-22) [umoeller]: optimized
    250  *@@changed V0.9.20 (2002-07-22) [lafaix]: optimized
    251253 */
    252254
     
    254256{
    255257    PCSZ    p2;
    256     ULONG   ulDBCSType = TYPE_SBCS;
    257 
     258
     259    // if not DBCS, do standard strchr()
    258260    if (!nlsDBCS())
    259         // not DBCS:
    260261        return strchr(p, c);
    261 
    262     // we're on DBCS:
    263262
    264263    // we can't find c if it is a DBCS lead byte
     
    266265        return NULL;
    267266
    268     for (p2 = p;
    269          *p2;
    270          ++p2)
    271     {
    272         // Set current DBCS scan state based of _previous_ DBCS scan state
    273         switch (ulDBCSType)
    274         {
    275             case TYPE_DBCS_1ST :
    276                 ulDBCSType = TYPE_DBCS_2ND;
    277             break;
    278             case TYPE_SBCS:
    279                 if (G_afLeadByte[*p2])
    280                     ulDBCSType = TYPE_DBCS_1ST;
    281                 break;
    282         }
    283 
    284         if (ulDBCSType != TYPE_DBCS_1ST) {
     267    for (p2 = p; *p2; p2++)
     268    {
     269        // skip over DBCS leading bytes and their trailing bytes
     270        if (G_afLeadByte[*p2]) {
     271
     272            // exit if the trailing byte is zero (shouldn't be)
     273            if (!*(++p2))
     274                return NULL;
     275
     276            continue;
     277        }
     278
     279        // test the SBCS char at p2
    285280        if (*p2 == c)
    286                     return (PSZ)p2;
    287             ulDBCSType = TYPE_SBCS;     // Ensure next char checked for DBCS lead
    288             }
    289 
    290     } // for
     281            return (PSZ)p2;
     282    }
    291283
    292284    return NULL;
Note: See TracChangeset for help on using the changeset viewer.