VirtualBox

Changeset 64814 in vbox


Ignore:
Timestamp:
Dec 8, 2016 9:37:21 PM (8 years ago)
Author:
vboxsync
Message:

bldprog-strtab-template.cpp.h: Fix bug in the compressor where it omits spaces and separators between words.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/bldprog-strtab-template.cpp.h

    r62450 r64814  
    116116
    117117
    118 
    119118/** String table data. */
    120119typedef struct BLDPROGSTRTAB
     
    227226#endif
    228227
    229 
    230 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION
     228#ifdef BLDPROG_STRTAB_WITH_COMPRESSION
     229
    231230DECLINLINE(size_t) bldProgStrTab_compressorFindNextWord(const char *pszSrc, char ch, const char **ppszSrc)
    232231{
     
    275274}
    276275
     276
    277277/**
    278278 * Analyzes a string.
     
    342342    }
    343343}
     344
    344345#endif /* BLDPROG_STRTAB_WITH_COMPRESSION */
    345 
    346346
    347347/**
     
    392392    pThis->cchUniqueStrings += pStr->cchString;
    393393}
    394 
    395394
    396395
     
    414413}
    415414
    416 
    417 
    418 #ifdef BLDPROG_STRTAB_WITH_COMPRESSION
     415#ifdef BLDPROG_STRTAB_WITH_COMPRESSION
     416
     417/**
     418 * Copies @a cchSrc chars from @a pchSrc to @a pszDst, escaping special
     419 * sequences.
     420 *
     421 * @returns New @a pszDst position, NULL if invalid source encoding.
     422 * @param   pszDst              The destination buffer.
     423 * @param   pszSrc              The source buffer.
     424 * @param   cchSrc              How much to copy.
     425 */
     426static char *bldProgStrTab_compressorCopyAndEscape(char *pszDst, const char *pszSrc, size_t cchSrc)
     427{
     428    while (cchSrc-- > 0)
     429    {
     430        char ch = *pszSrc;
     431        if (!((unsigned char)ch & 0x80))
     432        {
     433            *pszDst++ = ch;
     434            pszSrc++;
     435        }
     436        else
     437        {
     438# ifdef BLDPROG_STRTAB_PURE_ASCII
     439            fprintf(stderr, "error: unexpected char value %#x\n", ch);
     440            return NULL;
     441# else
     442            RTUNICP uc;
     443            int rc = RTStrGetCpEx(&pszSrc, &uc);
     444            if (RT_SUCCESS(rc))
     445            {
     446                *pszDst++ = (unsigned char)0xff; /* escape single code point. */
     447                pszDst = RTStrPutCp(pszDst, uc);
     448            }
     449            else
     450            {
     451                fprintf(stderr, "Error: RTStrGetCpEx failed with rc=%d\n", rc);
     452                return NULL;
     453            }
     454# endif
     455        }
     456    }
     457    return pszDst;
     458}
     459
    419460
    420461/**
     
    434475    while ((ch = *pszSrc) != '\0')
    435476    {
     477        const char * const pszSrcUncompressed = pszSrc;
    436478        size_t cchWord = bldProgStrTab_compressorFindNextWord(pszSrc, ch, &pszSrc);
     479        size_t cchSrcUncompressed = pszSrc - pszSrcUncompressed;
     480        if (cchSrcUncompressed > 0)
     481        {
     482            pszDst = bldProgStrTab_compressorCopyAndEscape(pszDst, pszSrcUncompressed, cchSrcUncompressed);
     483            if (!pszDst)
     484                return false;
     485        }
    437486        if (!cchWord)
    438487            break;
     
    457506        {
    458507            /* Copy the current word. */
    459             ch = *pszSrc;
    460             do
    461             {
    462                 if (!((unsigned char)ch & 0x80))
    463                 {
    464                     *pszDst++ = ch;
    465                     pszSrc++;
    466                 }
    467                 else
    468                 {
    469 #ifdef BLDPROG_STRTAB_PURE_ASCII
    470                     fprintf(stderr, "error: unexpected char value %#x\n", ch);
    471                     return false;
    472 #else
    473                     RTUNICP uc;
    474                     int rc = RTStrGetCpEx(&pszSrc, &uc);
    475                     if (RT_SUCCESS(rc))
    476                     {
    477                         *pszDst++ = (unsigned char)0xff; /* escape single code point. */
    478                         pszDst = RTStrPutCp(pszDst, uc);
    479                     }
    480                     else
    481                     {
    482                         fprintf(stderr, "Error: RTStrGetCpEx failed with rc=%d\n", rc);
    483                         return false;
    484                     }
    485 #endif
    486                 }
    487             } while ((ch = *pszSrc) != '\0' && ch != ' ');
     508            pszDst = bldProgStrTab_compressorCopyAndEscape(pszDst, pszSrc, cchWord);
     509            if (!pszDst)
     510                return false;
     511            pszSrc += cchWord;
    488512        }
    489513    }
     
    630654
    631655#endif /* BLDPROG_STRTAB_WITH_COMPRESSION */
    632 
    633656
    634657/**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette