Changeset 442


Ignore:
Timestamp:
Jan 17, 2019, 7:12:23 PM (7 years ago)
Author:
pr
Message:

Revert previous attempt at fixing the quoting mess.

Files:
2 edited

Legend:

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

    r427 r442  
    2323
    2424/*
    25  *      Copyright (C) 1997-2016 Ulrich M”ller.
     25 *      Copyright (C) 1997-2006 Ulrich M”ller.
    2626 *      Parts Copyright (C) 1991-1999 iMatix Corporation.
    2727 *      This file is part of the "XWorkplace helpers" source package.
     
    13221322 *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: handle attrib names in quoted strings @@fixes 718
    13231323 *@@changed WarpIN V1.0.12 (2006-09-07) [pr]: fix attrib handling again @@fixes 718 @@fixes 836
    1324  *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: fix single quote handling and allow escaping @@fixes 1244
    13251324 */
    13261325
     
    13321331           ulLength = strlen(pszSearchIn);
    13331332    BOOL   fInQuote = FALSE;
    1334     CHAR   cQuote = '\0', cPrev = '\0';
    13351333
    13361334    // use alloca(), so memory is freed on function exit
     
    13411339    for (p = pszSearchIn2;   *p == '\'' || *p == '"'  || *p == ' '
    13421340                          || *p == '\n' || *p == '\r' || *p == '\t'; p++);
    1343     for (pszStart = p; *p; cPrev = *(p++))
     1341    for (pszStart = p; *p; p++)
    13441342    {
    13451343        if (fInQuote)
    13461344        {
    13471345            // V1.0.12 (2006-09-07) [pr]: allow end of line to terminate a (broken) quote
    1348             if ((*p == cQuote && cPrev != '\\') || *p == '\n' || *p == '\r')
     1346            if (*p == '"' || *p == '\n' || *p == '\r')
    13491347                fInQuote = FALSE;
    13501348        }
    13511349        else
    13521350        {
    1353             if (*p == '"' || *p == '\'')
    1354             {
     1351            if (*p == '"')
    13551352                fInQuote = TRUE;
    1356                 cQuote = *p;
    1357             }
    13581353            else
    13591354            {
     
    14531448 *@@added V0.9.0 [umoeller]
    14541449 *@@changed V1.0.13 (2006-09-10) [pr]: improved parsing
    1455  *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: allow escaping @@fixes 1244
    14561450 */
    14571451
     
    14691463    {
    14701464        // determine end character to search for: a space
    1471         CHAR cEnd = ' ', cPrev = '\0';
     1465        CHAR cEnd = ' ';
    14721466        // V1.0.3 (2004-11-10) [pr]: @@fixes 461
    14731467        // V1.0.13 (2006-09-10) [pr]: optimized
    1474         if ((*pParam == '"') || (*pParam == '\''))
     1468        if ((*pParam == '\"') || (*pParam == '\''))
    14751469        {
    14761470            // or, if the data is enclosed in quotes, a quote or single quote
     
    14901484            if (   (   (cEnd == ' ')
    14911485                    && ((*pParam == ' ') || (*pParam == '\r') || (*pParam == '\n')))
    1492                 || ((*pParam == cEnd) && (cPrev != '\\'))
     1486                || (*pParam == cEnd)
    14931487               )
    14941488                // end character found
     
    15051499                    break;
    15061500            }
    1507 
    15081501            ulCount++;
    1509             cPrev = *(pParam++);
    1510         }
    1511 
    1512         // copy attribute to new buffer, de-escaping if necessary
    1513         if (ulCount && (prc = (PSZ) malloc(ulCount+1)))
    1514         {
    1515             ULONG i = 0, j = 0;
    1516 
    1517             for(cPrev = '\0'; i < ulCount; ++i, ++j)
    1518             {
    1519                 if (cEnd != ' ' && pParam2[i] == cEnd && cPrev == '\\')
    1520                     --j;
    1521 
    1522                 cPrev = prc[j] = pParam2[i];
    1523             }
    1524 
    1525             prc[j] = '\0';
     1502            pParam++;
     1503        }
     1504
     1505        // copy attribute to new buffer
     1506        if (ulCount)
     1507        {
     1508            prc = (PSZ)malloc(ulCount+1);
     1509            memcpy(prc, pParam2, ulCount);
     1510            *(prc+ulCount) = 0;
    15261511        }
    15271512    }
  • trunk/src/helpers/stringh.c

    r426 r442  
    2323
    2424/*
    25  *      Copyright (C) 1997-2016 Ulrich M”ller.
     25 *      Copyright (C) 1997-2006 Ulrich M”ller.
    2626 *      Parts Copyright (C) 1991-1999 iMatix Corporation.
    2727 *      This file is part of the "XWorkplace helpers" source package.
     
    13221322 *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: handle attrib names in quoted strings @@fixes 718
    13231323 *@@changed WarpIN V1.0.12 (2006-09-07) [pr]: fix attrib handling again @@fixes 718 @@fixes 836
    1324  *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: fix single quote handling and allow escaping @@fixes 1244
    13251324 */
    13261325
     
    13321331           ulLength = strlen(pszSearchIn);
    13331332    BOOL   fInQuote = FALSE;
    1334     CHAR   cQuote = '\0', cPrev = '\0';
    13351333
    13361334    // use alloca(), so memory is freed on function exit
     
    13411339    for (p = pszSearchIn2;   *p == '\'' || *p == '"'  || *p == ' '
    13421340                          || *p == '\n' || *p == '\r' || *p == '\t'; p++);
    1343     for (pszStart = p; *p; cPrev = *(p++))
     1341    for (pszStart = p; *p; p++)
    13441342    {
    13451343        if (fInQuote)
    13461344        {
    13471345            // V1.0.12 (2006-09-07) [pr]: allow end of line to terminate a (broken) quote
    1348             if ((*p == cQuote && cPrev != '\\') || *p == '\n' || *p == '\r')
     1346            if (*p == '"' || *p == '\n' || *p == '\r')
    13491347                fInQuote = FALSE;
    13501348        }
    13511349        else
    13521350        {
    1353             if (*p == '"' || *p == '\'')
    1354             {
     1351            if (*p == '"')
    13551352                fInQuote = TRUE;
    1356                 cQuote = *p;
    1357             }
    13581353            else
    13591354            {
     
    14531448 *@@added V0.9.0 [umoeller]
    14541449 *@@changed V1.0.13 (2006-09-10) [pr]: improved parsing
    1455  *@@changed WarpIN V1.0.23 (2016-09-23) [pr]: allow escaping @@fixes 1244
    14561450 */
    14571451
     
    14691463    {
    14701464        // determine end character to search for: a space
    1471         CHAR cEnd = ' ', cPrev = '\0';
     1465        CHAR cEnd = ' ';
    14721466        // V1.0.3 (2004-11-10) [pr]: @@fixes 461
    14731467        // V1.0.13 (2006-09-10) [pr]: optimized
    1474         if ((*pParam == '"') || (*pParam == '\''))
     1468        if ((*pParam == '\"') || (*pParam == '\''))
    14751469        {
    14761470            // or, if the data is enclosed in quotes, a quote or single quote
     
    14901484            if (   (   (cEnd == ' ')
    14911485                    && ((*pParam == ' ') || (*pParam == '\r') || (*pParam == '\n')))
    1492                 || ((*pParam == cEnd) && (cPrev != '\\'))
     1486                || (*pParam == cEnd)
    14931487               )
    14941488                // end character found
     
    15051499                    break;
    15061500            }
    1507 
    15081501            ulCount++;
    1509             cPrev = *(pParam++);
    1510         }
    1511 
    1512         // copy attribute to new buffer, de-escaping if necessary
    1513         if (ulCount && (prc = (PSZ) malloc(ulCount+1)))
    1514         {
    1515             ULONG i = 0, j = 0;
    1516 
    1517             for(cPrev = '\0'; i < ulCount; ++i, ++j)
    1518             {
    1519                 if (cEnd != ' ' && pParam2[i] == cEnd && cPrev == '\\')
    1520                     --j;
    1521 
    1522                 cPrev = prc[j] = pParam2[i];
    1523             }
    1524 
    1525             prc[j] = '\0';
     1502            pParam++;
     1503        }
     1504
     1505        // copy attribute to new buffer
     1506        if (ulCount)
     1507        {
     1508            prc = (PSZ)malloc(ulCount+1);
     1509            memcpy(prc, pParam2, ulCount);
     1510            *(prc+ulCount) = 0;
    15261511        }
    15271512    }
Note: See TracChangeset for help on using the changeset viewer.