Changeset 7251 for trunk/psLib/src/sys/psString.c
- Timestamp:
- May 31, 2006, 10:56:37 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r7115 r7251 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1. 29$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-05- 13 08:56:48$15 * @version $Revision: 1.30 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-05-31 20:56:37 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 173 173 } 174 174 175 # if 0176 // XXX: This should probably be implemented using strpbrk177 // XXX : add a boolean "repeats significant"178 // XXX : NULL input string returns empty (not NULL) list179 // XXX : NULL splitters is an error180 psList *psStringSplit(const char *string,181 const char *splitters)182 {183 PS_ASSERT_PTR_NON_NULL(splitters, NULL);184 185 psList *values = psListAlloc(NULL); // The list of values to return186 PS_ASSERT_PTR_NON_NULL(string, values);187 188 unsigned int length = strlen(string); // The length of the string189 unsigned int numSplitters = strlen(splitters); // Number of characters that might split190 unsigned int start = 0; // The position of the start of a word191 for (int i = 1; i < length; i++) {192 bool split = false; // Is this character a splitter?193 for (int j = 0; j < numSplitters && ! split; j++) {194 if (string[i] == splitters[j]) {195 split = true;196 }197 }198 if (split) {199 if (i == start) {200 // Some idiot put in two spaces, or two commas or something201 start++;202 } else {203 // We're at the end of the word204 psString word = psStringNCopy(&string[start], i - start);205 (void)psListAdd(values, PS_LIST_TAIL, word);206 start = i + 1;207 psFree(word);208 }209 }210 }211 if (start < length) {212 // Copy the last word213 psString word = psStringNCopy(&string[start], length - start);214 (void)psListAdd(values, PS_LIST_TAIL, word);215 psFree(word);216 }217 218 return values;219 }220 # endif221 222 175 // split the string by the given splitters 223 176 // NULL input string returns empty (not NULL) list … … 230 183 231 184 psList *values = psListAlloc(NULL); // The list of values to return 232 if (string == NULL) 185 // An input NULL string should not generate an error: it is a valid case 186 if (string == NULL) { 233 187 return values; 234 // XXX this should not generate an error : it is a valid case 235 // PS_ASSERT_PTR_NON_NULL(string, values); 188 } 236 189 237 190 char *next = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
