Changeset 6201
- Timestamp:
- Jan 25, 2006, 7:31:54 PM (20 years ago)
- Location:
- trunk/psLib
- Files:
-
- 3 edited
-
src/sys/psString.c (modified) (5 diffs)
-
src/sys/psString.h (modified) (7 diffs)
-
test/types/verified/tst_psMetadata_07.stderr (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r5569 r6201 11 11 * 12 12 * @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 $ 16 17 * 17 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 35 36 } 36 37 37 psString psStringNCopy(const char *string, unsigned int nChar) 38 psString psStringNCopy(const char *string, 39 unsigned int nChar) 38 40 { 39 41 char *returnValue = NULL; … … 59 61 } 60 62 61 ssize_t psStringAppend(char **dest, const char *format, ...) 63 ssize_t psStringAppend(char **dest, 64 const char *format, 65 ...) 62 66 { 63 67 va_list args; … … 104 108 } 105 109 106 ssize_t psStringPrepend(char **dest, const char *format, ...) 110 ssize_t psStringPrepend(char **dest, 111 const char *format, 112 ...) 107 113 { 108 114 va_list args; … … 157 163 return length; 158 164 } 165 166 // XXX: This should probably be implemented using strpbrk 167 psList *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 12 12 * 13 13 * @author Eric Van Alst, MHPCC 14 * @author David Robbins, MHPCC 14 15 * 15 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $16 * @date $Date: 200 5-09-13 01:09:58$16 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-01-26 05:31:54 $ 17 18 * 18 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 24 25 #include <sys/types.h> 25 26 #include "psType.h" 27 #include "psList.h" 26 28 27 29 /** This macro will convert the argument to a quoted string */ … … 40 42 * 41 43 * @return psString: Copy of input string 42 *43 44 */ 44 45 psString psStringCopy( … … 57 58 * 58 59 * @return psString: Copy of input string 59 *60 60 */ 61 62 /*@null@*/63 64 61 psString psStringNCopy( 65 62 const char *string, ///< Input string of characters to copy … … 72 69 * automatically extended to the size of the new string. 73 70 * 74 * @return The length of the new string (excluding '\0')71 * @return ssize_t: The length of the new string (excluding '\0') 75 72 */ 76 77 73 ssize_t psStringAppend( 78 74 char **dest, ///< existing string … … 86 82 * automatically extended to the size of the new string. 87 83 * 88 * @return The length of the new string (excluding '\0')84 * @return ssize_t: The length of the new string (excluding '\0') 89 85 */ 90 91 86 ssize_t psStringPrepend( 92 87 char **dest, ///< existing string … … 95 90 ); 96 91 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 */ 99 psList *psStringSplit( 100 const char *string, 101 const char *splitters 102 ); 103 97 104 /** @} */// Doxygen - End of SystemGroup Functions 98 105 -
trunk/psLib/test/types/verified/tst_psMetadata_07.stderr
r6190 r6201 57 57 \**********************************************************************************/ 58 58 59 <DATE><TIME>|<HOST>|I|testMetaCopy 60 Following should generate error message 59 61 <DATE><TIME>|<HOST>|E|psMetadataCopy (FILE:LINENO) 60 62 Unallowable operation: in is NULL.
Note:
See TracChangeset
for help on using the changeset viewer.
