Ignore:
Timestamp:
May 2, 2002, 5:17:26 PM (23 years ago)
Author:
umoeller
Message:

Misc fixes.

File:
1 edited

Legend:

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

    r159 r161  
    550550 *
    551551 *      Example:
     552 *
    552553 +          PSZ pszBuf = "KEYWORD { --blah-- } next",
    553554 +              pEnd;
     
    555556 +                      '{', '}',
    556557 +                      &pEnd)
     558 *
    557559 *      would return a new buffer containing " --blah-- ",
    558560 *      and ppEnd would afterwards point to the space
     
    562564 */
    563565
    564 PSZ strhExtract(PSZ pszBuf,     // in: search buffer
     566PSZ strhExtract(PCSZ pszBuf,    // in: search buffer
    565567                CHAR cOpen,     // in: opening char
    566568                CHAR cClose,    // in: closing char
    567                 PSZ *ppEnd)     // out: if != NULL, receives first character after closing char
     569                PCSZ *ppEnd)    // out: if != NULL, receives first character after closing char
    568570{
    569571    PSZ pszReturn = NULL;
    570 
    571     if (pszBuf)
    572     {
    573         PSZ pOpen;
    574         if (pOpen = strchr(pszBuf, cOpen))
    575         {
    576             // opening char found:
    577             // now go thru the whole rest of the buffer
    578             PSZ     p = pOpen+1;
    579             LONG    lLevel = 1;        // if this goes 0, we're done
    580             while (*p)
     572    PCSZ pOpen;
     573    if (    (pszBuf)
     574         && (pOpen = strchr(pszBuf, cOpen))
     575       )
     576    {
     577        // opening char found:
     578        // now go thru the whole rest of the buffer
     579        PCSZ     p = pOpen + 1;
     580        LONG    lLevel = 1;        // if this goes 0, we're done
     581        while (*p)
     582        {
     583            if (*p == cOpen)
     584                lLevel++;
     585            else if (*p == cClose)
    581586            {
    582                 if (*p == cOpen)
    583                     lLevel++;
    584                 else if (*p == cClose)
     587                lLevel--;
     588                if (lLevel <= 0)
    585589                {
    586                     lLevel--;
    587                     if (lLevel <= 0)
    588                     {
    589                         // matching closing bracket found:
    590                         // extract string
    591                         pszReturn = strhSubstr(pOpen+1,  // after cOpen
    592                                                p);          // excluding cClose
    593                         if (ppEnd)
    594                             *ppEnd = p+1;
    595                         break;      // while (*p)
    596                     }
     590                    // matching closing bracket found:
     591                    // extract string
     592                    pszReturn = strhSubstr(pOpen + 1,   // after cOpen
     593                                           p);          // excluding cClose
     594                    if (ppEnd)
     595                        *ppEnd = p + 1;
     596                    break;      // while (*p)
    597597                }
    598                 else if (*p == '\"')
    599                 {
    600                     // beginning of string:
    601                     PSZ p2 = p+1;
    602                     // find end of string
    603                     while ((*p2) && (*p2 != '\"'))
    604                         p2++;
    605 
    606                     if (*p2 == '\"')
    607                         // closing quote found:
    608                         // search on after that
    609                         p = p2;     // raised below
    610                     else
    611                         break;      // while (*p)
    612                 }
    613 
    614                 p++;
    615598            }
     599            else if (*p == '\"')
     600            {
     601                // beginning of string:
     602                PCSZ p2 = p+1;
     603                // find end of string
     604                while ((*p2) && (*p2 != '\"'))
     605                    p2++;
     606
     607                if (*p2 == '\"')
     608                    // closing quote found:
     609                    // search on after that
     610                    p = p2;     // raised below
     611                else
     612                    break;      // while (*p)
     613            }
     614
     615            p++;
    616616        }
    617617    }
Note: See TracChangeset for help on using the changeset viewer.