Changeset 7380 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Jun 6, 2006, 5:22:07 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
r7251 r7380 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.3 0$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 5-31 20:56:37$15 * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-06-07 03:22:06 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 31 31 psString psStringCopy(const char *string) 32 32 { 33 PS_ASSERT_PTR_NON_NULL(string, NULL); 33 // Pass through NULL values! 34 34 35 // Allocate memory using psAlloc function 35 36 // Copy input string to memory just allocated 36 37 // Return the copy 37 // Pass through NULL values38 38 return string ? strcpy(psAlloc(strlen(string) + 1), string) : NULL; 39 39 } … … 218 218 // given the input string, search for all copies of the key, and replace with the replacement value 219 219 // the input string may be freed if not needed 220 char *psStringSubstitute (char *input, char *replace, char *key) 221 { 222 223 char *p; 224 225 if (key == NULL) 220 char *psStringSubstitute(char *input, const char *replace, const char *key) 221 { 222 if (key == NULL || strlen(key) == 0) { 226 223 return input; 227 if (strlen(key) == 0) 228 return input; 224 } 229 225 230 226 while (true) { 231 p = strstr (input, key);232 if ( p == NULL)227 char *p = strstr (input, key); 228 if (!p) { 233 229 return input; 230 } 234 231 235 232 // we have input = xxxkeyxxx … … 241 238 242 239 // copy the first segement into 'output' 243 strncpy (output, input, Nc);240 strncpy(output, input, Nc); 244 241 245 242 // copy the key replacement to the start of the key 246 247 strcpy (&output[Nc], replace); 243 strcpy(&output[Nc], replace); 248 244 Nc += strlen (replace); 249 245 250 246 // copy the remainder to the end of the replacement 251 strcpy (&output[Nc], p + strlen(key));252 253 psFree (input);247 strcpy(&output[Nc], p + strlen(key)); 248 249 psFree(input); 254 250 input = output; 255 251 } … … 257 253 } 258 254 255 psArray *psStringSplitArray(const char *string, const char *splitters, bool multi) 256 { 257 258 psList *list = psStringSplit(string, splitters, multi); 259 psArray *array = psListToArray(list); 260 psFree (list); 261 return array; 262 } 263 264 #ifndef whitespace 265 #define whitespace(c) (((c) == ' ') || ((c) == '\t')) 266 #endif 267 268 /* Strip whitespace from the start and end of STRING. */ 269 size_t psStringStrip(char *string) 270 { 271 long i; 272 273 if (!string || strlen(string) == 0) { 274 return 0; 275 } 276 277 for (i = 0; i < strlen(string) && whitespace(string[i]); i++) 278 ; // No action 279 if (i) { 280 memmove (string, string + i, strlen(string+i)+1); 281 } 282 for (i = strlen (string) - 1; (i > 0) && whitespace(string[i]); i--) 283 ; // No action 284 string[++i] = 0; 285 286 return i; 287 }
Note:
See TracChangeset
for help on using the changeset viewer.
