Changeset 144


Ignore:
Timestamp:
Feb 26, 2002, 9:28:01 PM (23 years ago)
Author:
umoeller
Message:

Misc minor fixes.

Location:
trunk/src/helpers
Files:
2 edited

Legend:

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

    r143 r144  
    873873 *
    874874 *@@added V0.9.6 (2000-11-12) [umoeller]
     875 *@@changed V0.9.18 (2002-02-23) [umoeller]: fixed end char check
    875876 */
    876877
    877878BOOL strhIsWord(PCSZ pcszBuf,
    878879                PCSZ p,                 // in: start of word
    879                 ULONG cbSearch,                // in: length of word
     880                ULONG cbSearch,         // in: length of word
    880881                PCSZ pcszBeginChars,    // suggestion: "\x0d\x0a ()/\\-,."
    881882                PCSZ pcszEndChars)      // suggestion: "\x0d\x0a ()/\\-,.:;"
    882883{
    883     BOOL    fEndOK = FALSE;
    884 
    885884    // check previous char
    886885    if (    (p == pcszBuf)
     
    890889        // OK, valid begin char:
    891890        // check end char
    892         CHAR    cNextChar = *(p + cbSearch);
    893         if (cNextChar == 0)
    894             fEndOK = TRUE;
     891        CHAR    cNextChar;
     892        if (!(cNextChar = p[cbSearch]))
     893            // null terminator:
     894            return TRUE;
    895895        else
    896896        {
    897             char *pc = strchr(pcszEndChars, cNextChar);
    898             if (pc)
     897            // not null terminator: check if char is
     898            // in the list of valid end chars
     899            if (strchr(pcszEndChars, cNextChar))
     900            {
    899901                // OK, is end char: avoid doubles of that char,
    900902                // but allow spaces
    901                 if (    (cNextChar+1 != *pc)
    902                      || (cNextChar+1 == ' ')
    903                      || (cNextChar+1 == 0)
     903                // fixed V0.9.18 (2002-02-23) [umoeller]
     904                CHAR cNextNext = p[cbSearch + 1];
     905                if (    (cNextNext != cNextChar)
     906                     || (cNextNext == ' ')
     907                     || (cNextNext == 0)
    904908                   )
    905                     fEndOK = TRUE;
    906         }
    907     }
    908 
    909     return (fEndOK);
     909                    return TRUE;
     910            }
     911        }
     912    }
     913
     914    return FALSE;
    910915}
    911916
  • trunk/src/helpers/xstring.c

    r141 r144  
    1515 *      a char* pointer pointing to heap memory, which is managed
    1616 *      automatically.
     17 *
     18 *      Besides being convenient, these functions are highly
     19 *      optimized to use as few strlen's and memcpy's as
     20 *      possible.
    1721 *
    1822 *      Using these functions has the following advantages:
     
    8589
    8690/*
    87  *      Copyright (C) 1999-2001 Ulrich M”ller.
     91 *      Copyright (C) 1999-2002 Ulrich M”ller.
    8892 *      This file is part of the "XWorkplace helpers" source package.
    8993 *      This is free software; you can redistribute it and/or modify
     
    210214 *
    211215 +          XSTRING str;
    212  +          xstrInitSet(&str, strdup("blah"));
     216 +          xstrInitSet(&str, strdup("blah"), 0);
    213217 *
    214218 *@@added V0.9.16 (2002-01-13) [umoeller]
    215219 */
    216220
    217 void xstrInitSet2(PXSTRING pxstr,
    218                   PSZ pszNew,
    219                   ULONG ulNewLength)
     221void xstrInitSet2(PXSTRING pxstr,           // in/out: string
     222                  PSZ pszNew,               // in: malloc'd string to load pxstr with
     223                  ULONG ulNewLength)        // in: length of pszNew or 0 to run strlen()
    220224{
    221225    if (!pszNew)
     
    326330        if (pcszSource)
    327331        {
    328             pxstr->ulLength = strlen(pcszSource);
    329 
    330             if (pxstr->ulLength)
     332            if (pxstr->ulLength = strlen(pcszSource))
    331333            {
    332334                // we do have a source string:
     
    542544
    543545    xstrClear(pxstr);
    544     pxstr->psz = pszNew;
    545     if (pszNew)
     546    if (pxstr->psz = pszNew)
    546547    {
    547548        if (!ulNewLength)
     
    576577 *      as necessary.
    577578 *
    578  *      If pxstr contains something, its contents are destroyed.
     579 *      If pxstr contains something, its contents are overwritten.
    579580 *
    580581 *      With ulSourceLength, specify the length of pcszSource
     
    10101011            // now overwrite "found" in the middle
    10111012            if (cReplaceWithLen)
    1012             {
    10131013                memcpy(pFound,
    10141014                       pcszReplaceWith,
    10151015                       cReplaceWithLen);        // no null terminator
    1016             }
    10171016
    10181017            // that's it; adjust the string length now
Note: See TracChangeset for help on using the changeset viewer.