IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6201


Ignore:
Timestamp:
Jan 25, 2006, 7:31:54 PM (20 years ago)
Author:
drobbin
Message:

added psStringSplit from bug 657.

Location:
trunk/psLib
Files:
3 edited

Legend:

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

    r5569 r6201  
    1111 *
    1212 *  @author Eric Van Alst, MHPCC
    13  *
    14  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    15  *  @date $Date: 2005-11-22 19:11:07 $
     13 *  @author David Robbins, MHPCC
     14 *
     15 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     16 *  @date $Date: 2006-01-26 05:31:54 $
    1617 *
    1718 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3536}
    3637
    37 psString psStringNCopy(const char *string, unsigned int nChar)
     38psString psStringNCopy(const char *string,
     39                       unsigned int nChar)
    3840{
    3941    char *returnValue = NULL;
     
    5961}
    6062
    61 ssize_t psStringAppend(char **dest, const char *format, ...)
     63ssize_t psStringAppend(char **dest,
     64                       const char *format,
     65                       ...)
    6266{
    6367    va_list         args;
     
    104108}
    105109
    106 ssize_t psStringPrepend(char **dest, const char *format, ...)
     110ssize_t psStringPrepend(char **dest,
     111                        const char *format,
     112                        ...)
    107113{
    108114    va_list         args;
     
    157163    return length;
    158164}
     165
     166// XXX: This should probably be implemented using strpbrk
     167psList *psStringSplit(const char *string,
     168                      const char *splitters)
     169{
     170    psList *values = psListAlloc(NULL); // The list of values to return
     171    unsigned int length = strlen(string); // The length of the string
     172    unsigned int numSplitters = strlen(splitters); // Number of characters that might split
     173    unsigned int start = 0;             // The position of the start of a word
     174    for (int i = 1; i < length; i++) {
     175        bool split = false;             // Is this character a splitter?
     176        for (int j = 0; j < numSplitters && ! split; j++) {
     177            if (string[i] == splitters[j]) {
     178                split = true;
     179            }
     180        }
     181        if (split) {
     182            if (i == start) {
     183                // Some idiot put in two spaces, or two commas or something
     184                start++;
     185            } else {
     186                // We're at the end of the word
     187                psString word = psStringNCopy(&string[start], i - start);
     188                (void)psListAdd(values, PS_LIST_TAIL, word);
     189                start = i + 1;
     190                psFree(word);
     191            }
     192        }
     193    }
     194    if (start < length) {
     195        // Copy the last word
     196        psString word = psStringNCopy(&string[start], length - start);
     197        (void)psListAdd(values, PS_LIST_TAIL, word);
     198        psFree(word);
     199    }
     200
     201    return values;
     202}
     203
  • trunk/psLib/src/sys/psString.h

    r5015 r6201  
    1212 *
    1313 *  @author Eric Van Alst, MHPCC
     14 *  @author David Robbins, MHPCC
    1415 *
    15  *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2005-09-13 01:09:58 $
     16 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-01-26 05:31:54 $
    1718 *
    1819 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2425#include <sys/types.h>
    2526#include "psType.h"
     27#include "psList.h"
    2628
    2729/** This macro will convert the argument to a quoted string */
     
    4042 *
    4143 *  @return psString:      Copy of input string
    42  *
    4344 */
    4445psString psStringCopy(
     
    5758 *
    5859 *  @return  psString:   Copy of input string
    59  *
    6060 */
    61 
    62 /*@null@*/
    63 
    6461psString psStringNCopy(
    6562    const char *string,                ///< Input string of characters to copy
     
    7269 * automatically extended to the size of the new string.
    7370 *
    74  * @return The length of the new string (excluding '\0')
     71 * @return ssize_t:     The length of the new string (excluding '\0')
    7572 */
    76 
    7773ssize_t psStringAppend(
    7874    char **dest,                        ///< existing string
     
    8682 * automatically extended to the size of the new string.
    8783 *
    88  * @return The length of the new string (excluding '\0')
     84 * @return ssize_t:     The length of the new string (excluding '\0')
    8985 */
    90 
    9186ssize_t psStringPrepend(
    9287    char **dest,                        ///< existing string
     
    9590);
    9691
     92/** Procedure to split the input string into a psList of psStrings.
     93 *
     94 *  The string is split at any one of the characters in splitters.  Split
     95 *  strings of zero length should not be included in the output list.
     96 *
     97 *  @return psList*:    The list of (split) psStrings.
     98 */
     99psList *psStringSplit(
     100    const char *string,
     101    const char *splitters
     102);
     103
    97104/** @} */// Doxygen - End of SystemGroup Functions
    98105
  • trunk/psLib/test/types/verified/tst_psMetadata_07.stderr

    r6190 r6201  
    5757\**********************************************************************************/
    5858
     59<DATE><TIME>|<HOST>|I|testMetaCopy
     60    Following should generate error message
    5961<DATE><TIME>|<HOST>|E|psMetadataCopy (FILE:LINENO)
    6062    Unallowable operation: in is NULL.
Note: See TracChangeset for help on using the changeset viewer.