Ignore:
Timestamp:
Feb 8, 2003, 9:57:38 PM (23 years ago)
Author:
umoeller
Message:

Build updates, moved files from warpin.

File:
1 edited

Legend:

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

    r245 r249  
    12581258
    12591259// static encoding table for xstrEncode
    1260 STATIC PSZ apszEncoding[] =
     1260static PSZ apszEncoding[] =
    12611261{
    12621262    "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",
     
    13651365                        // use the static encoding table for speed
    13661366                        memcpy(pszDestCurr,
    1367                                apszEncoding[(unsigned char)pcszEncode[ulEncode]],
     1367                               apszEncoding[(UCHAR)pcszEncode[ulEncode]],
    13681368                               3);
    13691369                        pszDestCurr += 3;
     
    13851385            *pszDestCurr = 0;
    13861386
    1387             xstrcpy(pxstr, pszDest, pszDestCurr-pszDest);
     1387            xstrcpy(pxstr, pszDest, pszDestCurr - pszDest);
     1388        }
     1389
     1390        free(pszDest);
     1391    }
     1392
     1393    return ulrc;
     1394}
     1395
     1396/*
     1397 *@@ xstrEncodeASCII:
     1398 *      like xstrEncode, but instead of encoding characters
     1399 *      from an array given by the caller, this encodes all
     1400 *      non-ASCII characters (i.e. >= 128) plus the '%' char.
     1401 *
     1402 *@@added V1.0.2 (2003-02-07) [umoeller]
     1403 */
     1404
     1405ULONG xstrEncodeASCII(PXSTRING pxstr)     // in/out: string to convert
     1406{
     1407    ULONG ulrc = 0,
     1408          ul,
     1409          ulEncodeLength;
     1410
     1411    if (    (pxstr)
     1412         && (pxstr->ulLength)
     1413       )
     1414    {
     1415        PSZ pszDest = (PSZ)malloc(pxstr->ulLength * 3
     1416                                  + 1),
     1417            pszDestCurr = pszDest;
     1418
     1419        if (pszDest)
     1420        {
     1421            for (ul = 0;
     1422                 ul < pxstr->ulLength;
     1423                 ul++)
     1424            {
     1425                if (    ((UCHAR)pxstr->psz[ul] >= 128)
     1426                     || (pxstr->psz[ul] == '%')
     1427                   )
     1428                {
     1429                    memcpy(pszDestCurr,
     1430                           apszEncoding[(UCHAR)pxstr->psz[ul]],
     1431                           3);
     1432                    pszDestCurr += 3;
     1433                    ulrc++;
     1434                    goto iterate;
     1435                }
     1436
     1437                *pszDestCurr++ = pxstr->psz[ul];
     1438
     1439                iterate:
     1440                    ;
     1441            }
     1442        }
     1443
     1444        // something was encoded; update pxstr
     1445        if (ulrc)
     1446        {
     1447            *pszDestCurr = 0;
     1448
     1449            xstrcpy(pxstr, pszDest, pszDestCurr - pszDest);
    13881450        }
    13891451
Note: See TracChangeset for help on using the changeset viewer.