Changeset 329 for branches


Ignore:
Timestamp:
Aug 31, 2006, 11:23:54 PM (19 years ago)
Author:
pr
Message:

Fixes bug 718

File:
1 edited

Legend:

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

    r263 r329  
    2323
    2424/*
    25  *      Copyright (C) 1997-2002 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.
     
    11461146 *@@changed V0.9.3 (2000-05-19) [umoeller]: some speed optimizations
    11471147 *@@changed V0.9.12 (2001-05-22) [umoeller]: fixed space bug, thanks Yuri Dario
     1148 *@@changed WarpIN V1.0.11 (2006-08-29) [pr]: handle attrib names in quoted strings @@fixes 718
    11481149 */
    11491150
    11501151PSZ strhFindAttribValue(const char *pszSearchIn, const char *pszAttrib)
    11511152{
    1152    PSZ    prc = 0;
    1153    PSZ    pszSearchIn2, p;
    1154    ULONG  cbAttrib = strlen(pszAttrib),
    1155           ulLength = strlen(pszSearchIn);
    1156 
    1157    // use alloca(), so memory is freed on function exit
    1158    pszSearchIn2 = (PSZ)alloca(ulLength + 1);
    1159    memcpy(pszSearchIn2, pszSearchIn, ulLength + 1);
    1160 
    1161    // 1) find token, (space char, \n, \r, \t)
    1162    p = strtok(pszSearchIn2, " \n\r\t");
    1163    while (p)
    1164    {
    1165         CHAR c2;
    1166         PSZ pOrig;
    1167 
    1168         // check tag name
    1169         if (!strnicmp(p, pszAttrib, cbAttrib))
    1170         {
    1171             // position in original string
    1172             pOrig = (PSZ)pszSearchIn + (p - pszSearchIn2);
    1173 
    1174             // yes:
    1175             prc = pOrig + cbAttrib;
    1176             c2 = *prc;
    1177             while (   (   (c2 == ' ')
    1178                        || (c2 == '=')
    1179                        || (c2 == '\n')
    1180                        || (c2 == '\r')
    1181                       )
    1182                     && (c2 != 0)
    1183                   )
    1184                 c2 = *++prc;
    1185 
    1186             break;
    1187         }
    1188 
    1189         p = strtok(NULL, " \n\r\t");
    1190    }
    1191 
    1192    return prc;
    1193 }
    1194 
    1195 /* PSZ strhFindAttribValue(const char *pszSearchIn, const char *pszAttrib)
    1196 {
    1197     PSZ     prc = 0;
    1198     PSZ     pszSearchIn2 = (PSZ)pszSearchIn,
    1199             p,
    1200             p2;
    1201     ULONG   cbAttrib = strlen(pszAttrib);
    1202 
    1203     // 1) find space char
    1204     while ((p = strchr(pszSearchIn2, ' ')))
    1205     {
    1206         CHAR c;
    1207         p++;
    1208         if (strlen(p) >= cbAttrib)      // V0.9.9 (2001-03-27) [umoeller]
    1209         {
    1210             c = *(p+cbAttrib);     // V0.9.3 (2000-05-19) [umoeller]
    1211             // now check whether the p+strlen(pszAttrib)
    1212             // is a valid end-of-tag character
    1213             if (    (memicmp(p, (PVOID)pszAttrib, cbAttrib) == 0)
    1214                  && (   (c == ' ')
    1215                      || (c == '>')
    1216                      || (c == '=')
    1217                      || (c == '\r')
    1218                      || (c == '\n')
    1219                      || (c == 0)
    1220                     )
    1221                )
     1153    PSZ    prc = 0;
     1154    PSZ    pszSearchIn2, p, pszStart, pszName, pszValue;
     1155    ULONG  cbAttrib = strlen(pszAttrib),
     1156           ulLength = strlen(pszSearchIn);
     1157    BOOL   fInQuote = FALSE;
     1158
     1159    // use alloca(), so memory is freed on function exit
     1160    pszSearchIn2 = (PSZ)alloca(ulLength + 1);
     1161    memcpy(pszSearchIn2, pszSearchIn, ulLength + 1);
     1162
     1163    for (p = pszSearchIn2; *p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'; p++);
     1164    for (pszStart = p; *p; p++)
     1165    {
     1166        if (fInQuote)
     1167        {
     1168            if (*p == '"')
     1169                fInQuote = FALSE;
     1170        }
     1171        else
     1172        {
     1173            if (*p == '"')
     1174                fInQuote = TRUE;
     1175            else
    12221176            {
    1223                 // yes:
    1224                 CHAR c2;
    1225                 p2 = p + cbAttrib;
    1226                 c2 = *p2;
    1227                 while (     (   (c2 == ' ')
    1228                              || (c2 == '=')
    1229                              || (c2 == '\n')
    1230                              || (c2 == '\r')
    1231                             )
    1232                         &&  (c2 != 0)
    1233                       )
    1234                     c2 = *++p2;
    1235 
    1236                 prc = p2;
    1237                 break; // first while
     1177                if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
     1178                {
     1179                    *p = '\0';
     1180                    pszName = strtok(pszStart, "=>");
     1181                    pszStart = p + 1;
     1182                    if (pszName && !stricmp(pszName, pszAttrib))
     1183                    {
     1184                        pszValue = strtok(NULL, "");
     1185                        if (pszValue)
     1186                            prc = (PSZ)pszSearchIn + (pszValue - pszSearchIn2);
     1187                        else
     1188                            prc = (PSZ)pszSearchIn + (pszName - pszSearchIn2) + cbAttrib;
     1189
     1190                        return(prc);
     1191                    }
     1192                }
    12381193            }
    12391194        }
    1240         else
    1241             break;
    1242 
    1243         pszSearchIn2++;
    1244     }
     1195    }
     1196
     1197    if (pszStart != p)
     1198    {
     1199        pszName = strtok(pszStart, "=>");
     1200        if (pszName && !stricmp(pszName, pszAttrib))
     1201        {
     1202            pszValue = strtok(NULL, "");
     1203            if (pszValue)
     1204                prc = (PSZ)pszSearchIn + (pszValue - pszSearchIn2);
     1205            else
     1206                prc = (PSZ)pszSearchIn + (pszName - pszSearchIn2) + cbAttrib;
     1207        }
     1208    }
     1209
    12451210    return prc;
    1246 } */
     1211}
    12471212
    12481213/*
Note: See TracChangeset for help on using the changeset viewer.