Changeset 7831 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Jul 6, 2006, 12:26:13 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/sys/psString.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psString.c
r7766 r7831 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 6-30 02:20:06$15 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-07-06 22:26:13 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 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, const char *replace, const char *key) 221 { 222 if (key == NULL || strlen(key) == 0) { 223 return input; 224 } 225 220 char *psStringSubstitute(char *input, 221 const char *replace, 222 const char *key) 223 { 224 if (input == NULL ) { 225 psError(PS_ERR_BAD_PARAMETER_NULL, true, 226 "Invalid string in psStringSubstitute. Input cannot be NULL or empty.\n"); 227 return NULL; 228 } else if (strlen(input) == 0) { 229 psError(PS_ERR_BAD_PARAMETER_NULL, true, 230 "Invalid string in psStringSubstitute. Input cannot be NULL or empty.\n"); 231 return NULL; 232 } 233 if (replace == NULL) { 234 return NULL; 235 } 236 if (key == NULL ) { 237 return NULL; 238 } else if (strlen(key) == 0) { 239 return NULL; 240 } 241 242 psString in = psStringCopy(input); 226 243 while (true) { 227 char *p = strstr (input, key); 244 // char *p = strstr (input, key); 245 char *p = strstr (in, key); 228 246 if (!p) { 229 return input; 247 // return input; 248 // strcpy(input, in); 249 // psFree(in); 250 return in; 230 251 } 231 252 … … 234 255 235 256 // this is safe since we will subtract strlen(key) elements from input 236 char *output = psAlloc(strlen(input) + strlen(replace) + 1); 237 int Nc = p - input; 257 // char *output = psAlloc(strlen(input) + strlen(replace) + 1); 258 // int Nc = p - input; 259 int Nc = p - in; 238 260 239 261 // copy the first segement into 'output' 240 strncpy(output, input, Nc); 262 psString output = psStringNCopy(in, strlen(in)+strlen(replace)+1); 263 264 // strncpy(output, input, Nc); 241 265 242 266 // copy the key replacement to the start of the key … … 247 271 strcpy(&output[Nc], p + strlen(key)); 248 272 249 psFree(input); 250 input = output; 251 } 252 return input; 273 // psFree(input); 274 // input = output; 275 // psFree(in); 276 // strcpy(in, "\0"); 277 //in = psStringCopy("\0"); 278 psFree(in); 279 // input = output; 280 // strcpy(in, output); 281 in = psStringCopy(output); 282 psFree(output); 283 } 284 // strcpy(input, in); 285 // psFree(in); 286 return in; 253 287 } 254 288
Note:
See TracChangeset
for help on using the changeset viewer.
