Ignore:
Timestamp:
Jan 19, 2002, 11:50:39 AM (24 years ago)
Author:
umoeller
Message:

Misc changes.

File:
1 edited

Legend:

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

    r129 r132  
    129129void XWPENTRY xstrInitDebug(PXSTRING pxstr,
    130130                            ULONG ulPreAllocate,
    131                             const char *file,
     131                            PCSZ file,
    132132                            unsigned long line,
    133                             const char *function)
     133                            PCSZ function)
    134134{
    135135    memset(pxstr, 0, sizeof(XSTRING));
     
    194194
    195195/*
    196  *@@ xstrInitSet:
     196 *@@ xstrInitSet2:
    197197 *      this can be used instead of xstrInit if you
    198198 *      have a free()'able string you want to initialize
     
    212212 +          xstrInitSet(&str, strdup("blah"));
    213213 *
    214  *@@added V0.9.6 (2000-11-01) [umoeller]
    215  *@@changed V0.9.9 (2001-03-09) [umoeller]: added ulDelta
    216  */
    217 
    218 void xstrInitSet(PXSTRING pxstr,
    219                  PSZ pszNew)
     214 *@@added V0.9.16 (2002-01-13) [umoeller]
     215 */
     216
     217void xstrInitSet2(PXSTRING pxstr,
     218                  PSZ pszNew,
     219                  ULONG ulNewLength)
    220220{
    221221    if (!pszNew)
     
    223223    else
    224224    {
     225        if (!ulNewLength)
     226            ulNewLength = strlen(pszNew);
    225227        pxstr->psz = pszNew;
    226         pxstr->ulLength = strlen(pszNew);
    227         pxstr->cbAllocated = pxstr->ulLength + 1;
    228         pxstr->ulDelta = pxstr->ulLength  * 10 / 100;
    229     }
     228        pxstr->ulLength = ulNewLength;
     229        pxstr->cbAllocated = ulNewLength + 1;
     230        pxstr->ulDelta = ulNewLength * 10 / 100;
     231    }
     232}
     233
     234/*
     235 *@@ xstrInitSet:
     236 *      shortcut to xstrInitSet2 to retain compatibility.
     237 *
     238 *@@added V0.9.6 (2000-11-01) [umoeller]
     239 *@@changed V0.9.9 (2001-03-09) [umoeller]: added ulDelta
     240 */
     241
     242void xstrInitSet(PXSTRING pxstr,
     243                 PSZ pszNew)
     244{
     245    xstrInitSet2(pxstr, pszNew, 0);
    230246}
    231247
     
    239255
    240256void XWPENTRY xstrInitCopyDebug(PXSTRING pxstr,
    241                                 const char *pcszSource,
     257                                PCSZ pcszSource,
    242258                                ULONG ulExtraAllocate,
    243                                 const char *file,
     259                                PCSZ file,
    244260                                unsigned long line,
    245                                 const char *function)
     261                                PCSZ function)
    246262{
    247263    if (pxstr)
     
    301317
    302318void xstrInitCopy(PXSTRING pxstr,
    303                   const char *pcszSource,
     319                  PCSZ pcszSource,
    304320                  ULONG ulExtraAllocate)          // in: if > 0, extra memory to allocate
    305321{
     
    497513
    498514/*
    499  *@@ xstrset:
     515 *@@ xstrset2:
    500516 *      sets the specified XSTRING to a new string
    501517 *      without copying it.
     
    511527 *      is true if pszNew comes from strdup().
    512528 *
    513  *@@added V0.9.6 (2000-11-01) [umoeller]
    514  *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash
    515  */
    516 
    517 ULONG xstrset(PXSTRING pxstr,               // in/out: string
    518               PSZ pszNew)                   // in: heap PSZ to use
     529 *      With this function, you can pass in the
     530 *      length of the string in ulNewLength.
     531 *      Otherwise use xstrset.
     532 *
     533 *@@added V0.9.16 (2002-01-13) [umoeller]
     534 */
     535
     536ULONG xstrset2(PXSTRING pxstr,              // in/out: string
     537               PSZ pszNew,                  // in: heap PSZ to use
     538               ULONG ulNewLength)           // in: length of string or 0 to run strlen here
    519539{
    520540    if (!pxstr)
     
    525545    if (pszNew)
    526546    {
    527         pxstr->ulLength = strlen(pszNew);
    528         pxstr->cbAllocated = pxstr->ulLength + 1;
    529 
    530         pxstr->ulDelta = pxstr->cbAllocated * 10 / 100;
     547        if (!ulNewLength)
     548            ulNewLength = strlen(pszNew);
     549        pxstr->ulLength = ulNewLength;
     550        pxstr->cbAllocated = ulNewLength + 1;
     551
     552        pxstr->ulDelta = ulNewLength * 10 / 100;
    531553    }
    532554    // else null string: cbAllocated and ulLength are 0 already
    533555
    534556    return (pxstr->ulLength);
     557}
     558
     559/*
     560 *@@ xstrset:
     561 *      shortcut for xstrset2 for retaining compatibility.
     562 *
     563 *@@added V0.9.6 (2000-11-01) [umoeller]
     564 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash
     565 */
     566
     567ULONG xstrset(PXSTRING pxstr,               // in/out: string
     568              PSZ pszNew)                   // in: heap PSZ to use
     569{
     570    return (xstrset2(pxstr, pszNew, 0));
    535571}
    536572
     
    583619
    584620ULONG xstrcpy(PXSTRING pxstr,               // in/out: string
    585               const char *pcszSource,       // in: source, can be NULL
     621              PCSZ pcszSource,       // in: source, can be NULL
    586622              ULONG ulSourceLength)         // in: length of pcszSource or 0
    587623{
     
    694730
    695731ULONG xstrcat(PXSTRING pxstr,               // in/out: string
    696               const char *pcszSource,       // in: source, can be NULL
     732              PCSZ pcszSource,       // in: source, can be NULL
    697733              ULONG ulSourceLength)         // in: length of pcszSource or 0
    698734{
     
    863899              ULONG ulFirstReplOfs,             // in: ofs of first char to replace
    864900              ULONG cReplLen,                   // in: no. of chars to replace
    865               const char *pcszReplaceWith,      // in: string to replace chars with
     901              PCSZ pcszReplaceWith,      // in: string to replace chars with
    866902              ULONG cReplaceWithLen)            // in: length of replacement string
    867903                                                // (this MUST be specified; if 0, chars are removed only)
     
    10141050                 size_t *pShiftTable,         // in: shift table (see strhmemfind)
    10151051                 PBOOL pfRepeatFind,          // in: repeat find? (see strhmemfind)
    1016                  const char *pcszBeginChars,  // suggestion: "\x0d\x0a ()/\\-,."
    1017                  const char *pcszEndChars)    // suggestion: "\x0d\x0a ()/\\-,.:;"
     1052                 PCSZ pcszBeginChars,  // suggestion: "\x0d\x0a ()/\\-,."
     1053                 PCSZ pcszEndChars)    // suggestion: "\x0d\x0a ()/\\-,.:;"
    10181054{
    10191055    PSZ     pReturn = 0;
     
    10251061        if ((pxstr->ulLength) && (ulFoundLen))
    10261062        {
    1027             const char *p = pxstr->psz + ulOfs;
     1063            PCSZ p = pxstr->psz + ulOfs;
    10281064
    10291065            do  // while p
     
    11521188            // yes:
    11531189            ULONG   ulOfs = *pulOfs;
    1154             const char *pFound
    1155                 = (const char *)strhmemfind(pxstr->psz + ulOfs, // in: haystack
     1190            PCSZ pFound
     1191                = (PCSZ)strhmemfind(pxstr->psz + ulOfs, // in: haystack
    11561192                                            pxstr->ulLength - ulOfs,
    11571193                                            pstrSearch->psz,
     
    11991235                       PULONG pulOfs,               // in: where to begin search (0 = start);
    12001236                                                    // out: ofs of first char after replacement string
    1201                        const char *pcszSearch,      // in: search string; cannot be NULL
    1202                        const char *pcszReplace)     // in: replacement string; cannot be NULL
     1237                       PCSZ pcszSearch,      // in: search string; cannot be NULL
     1238                       PCSZ pcszReplace)     // in: replacement string; cannot be NULL
    12031239{
    12041240    XSTRING xstrFind,
     
    12921328
    12931329ULONG xstrEncode(PXSTRING pxstr,            // in/out: string to convert
    1294                  const char *pcszEncode)    // in: characters to encode (e.g. "%,();=")
     1330                 PCSZ pcszEncode)    // in: characters to encode (e.g. "%,();=")
    12951331{
    12961332    ULONG ulrc = 0,
Note: See TracChangeset for help on using the changeset viewer.