IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2006, 5:22:07 PM (20 years ago)
Author:
Paul Price
Message:

Merging the pslib "additional" functions from the modules into psLib proper.

Added jpeg directory for psImageJpeg.
Changes to build system (configure.ac, and various Makefile.am)

psVectorSmooth: changed API to allow optional output vector
psSparse: changed sizes to type "long"; added "const"
psRegionIsBad: Renamed psRegionIsNaN
psImageBicubeFit: changed sizes to "long"; added a "const"
psLine: changed sizes to "long"
psImageUnbin: description required in SDRS
psImageClippedStats: renaming to psImageBackground; removing static structures; API changed!
psImageFlipX, psImageFlipY merged to psImageFlip
psStringSubstitute: added "const"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psString.c

    r7251 r7380  
    1313 *  @author David Robbins, MHPCC
    1414 *
    15  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2006-05-31 20:56:37 $
     15 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-06-07 03:22:06 $
    1717 *
    1818 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3131psString psStringCopy(const char *string)
    3232{
    33     PS_ASSERT_PTR_NON_NULL(string, NULL);
     33    // Pass through NULL values!
     34
    3435    // Allocate memory using psAlloc function
    3536    // Copy input string to memory just allocated
    3637    // Return the copy
    37     // Pass through NULL values
    3838    return string ? strcpy(psAlloc(strlen(string) + 1), string) : NULL;
    3939}
     
    218218// given the input string, search for all copies of the key, and replace with the replacement value
    219219// the input string may be freed if not needed
    220 char *psStringSubstitute (char *input, char *replace, char *key)
    221 {
    222 
    223     char *p;
    224 
    225     if (key == NULL)
     220char *psStringSubstitute(char *input, const char *replace, const char *key)
     221{
     222    if (key == NULL || strlen(key) == 0) {
    226223        return input;
    227     if (strlen(key) == 0)
    228         return input;
     224    }
    229225
    230226    while (true) {
    231         p = strstr (input, key);
    232         if (p == NULL)
     227        char *p = strstr (input, key);
     228        if (!p) {
    233229            return input;
     230        }
    234231
    235232        // we have input = xxxkeyxxx
     
    241238
    242239        // copy the first segement into 'output'
    243         strncpy (output, input, Nc);
     240        strncpy(output, input, Nc);
    244241
    245242        // copy the key replacement to the start of the key
    246 
    247         strcpy (&output[Nc], replace);
     243        strcpy(&output[Nc], replace);
    248244        Nc += strlen (replace);
    249245
    250246        // copy the remainder to the end of the replacement
    251         strcpy (&output[Nc], p + strlen(key));
    252 
    253         psFree (input);
     247        strcpy(&output[Nc], p + strlen(key));
     248
     249        psFree(input);
    254250        input = output;
    255251    }
     
    257253}
    258254
     255psArray *psStringSplitArray(const char *string, const char *splitters, bool multi)
     256{
     257
     258    psList *list = psStringSplit(string, splitters, multi);
     259    psArray *array = psListToArray(list);
     260    psFree (list);
     261    return array;
     262}
     263
     264#ifndef whitespace
     265#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
     266#endif
     267
     268/* Strip whitespace from the start and end of STRING. */
     269size_t psStringStrip(char *string)
     270{
     271    long i;
     272
     273    if (!string || strlen(string) == 0) {
     274        return 0;
     275    }
     276
     277    for (i = 0; i < strlen(string) && whitespace(string[i]); i++)
     278        ; // No action
     279    if (i) {
     280        memmove (string, string + i, strlen(string+i)+1);
     281    }
     282    for (i = strlen (string) - 1; (i > 0) && whitespace(string[i]); i--)
     283        ; // No action
     284    string[++i] = 0;
     285
     286    return i;
     287}
Note: See TracChangeset for help on using the changeset viewer.