Changeset 6201 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Jan 25, 2006, 7:31:54 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (5 diffs)
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
Note:
See TracChangeset
for help on using the changeset viewer.
