Changeset 7015
- Timestamp:
- Apr 30, 2006, 2:57:07 PM (20 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 edited
-
psString.c (modified) (3 diffs)
-
psString.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r6989 r7015 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.2 7$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 4-26 02:19:23$15 * @version $Revision: 1.28 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-05-01 00:57:07 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 173 173 } 174 174 175 # if 0 175 176 // XXX: This should probably be implemented using strpbrk 177 // XXX : add a boolean "repeats significant" 178 // XXX : NULL input string returns empty (not NULL) list 179 // XXX : NULL splitters is an error 176 180 psList *psStringSplit(const char *string, 177 181 const char *splitters) 178 182 { 183 PS_ASSERT_PTR_NON_NULL(splitters, NULL); 184 179 185 psList *values = psListAlloc(NULL); // The list of values to return 180 186 PS_ASSERT_PTR_NON_NULL(string, values); 181 PS_ASSERT_PTR_NON_NULL(splitters, values);182 // if (string == NULL)183 // return values;184 187 185 188 unsigned int length = strlen(string); // The length of the string … … 215 218 return values; 216 219 } 220 # endif 221 222 // split the string by the given splitters 223 // NULL input string returns empty (not NULL) list 224 // NULL splitters is an error 225 psList *psStringSplit(const char *string, 226 const char *splitters, 227 bool multipleAreSignificant) 228 { 229 PS_ASSERT_PTR_NON_NULL(splitters, NULL); 230 231 psList *values = psListAlloc(NULL); // The list of values to return 232 PS_ASSERT_PTR_NON_NULL(string, values); 233 234 char *next = NULL; 235 char *current = (char *) string; 236 while ((next = strpbrk (current, splitters)) != NULL) { 237 238 // are multiple splitters in-a-row significant? 239 if ((next == current) && !multipleAreSignificant) { 240 current ++; 241 continue; 242 } 243 244 // Copy the current word 245 psString word = psStringNCopy(current, next - current); 246 psListAdd(values, PS_LIST_TAIL, word); 247 psFree(word); 248 249 current = next + 1; 250 } 251 252 if (strlen(current) > 0) { 253 // Copy the last word 254 psString word = psStringCopy(current); 255 (void)psListAdd(values, PS_LIST_TAIL, word); 256 psFree(word); 257 } 258 259 return values; 260 } 217 261 218 262 // given the input string, search for all copies of the key, and replace with the replacement value -
trunk/psLib/src/sys/psString.h
r6874 r7015 14 14 * @author David Robbins, MHPCC 15 15 * 16 * @version $Revision: 1. 19$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-0 4-17 22:00:03$16 * @version $Revision: 1.20 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-05-01 00:57:07 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 100 100 psList *psStringSplit( 101 101 const char *string, 102 const char *splitters 102 const char *splitters, 103 bool multipleAreSignificant 103 104 ); 104 105
Note:
See TracChangeset
for help on using the changeset viewer.
