Changeset 6567 for branches/rel10_ifa/psLib/src/sys/psString.c
- Timestamp:
- Mar 9, 2006, 9:37:28 AM (20 years ago)
- File:
-
- 1 edited
-
branches/rel10_ifa/psLib/src/sys/psString.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psLib/src/sys/psString.c
r6278 r6567 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.24 $ $Name: not supported by cvs2svn $16 * @date $Date: 2006-0 2-01 20:40:56$15 * @version $Revision: 1.24.4.1 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-03-09 19:37:28 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 214 214 } 215 215 216 // given the input string, search for all copies of the key, and replace with the replacement value 217 // the input string may be freed if not needed 218 char *psStringSubstitute (char *input, char *replace, char *key) 219 { 220 221 char *p; 222 223 if (key == NULL) 224 return input; 225 if (strlen(key) == 0) 226 return input; 227 228 while (true) { 229 p = strstr (input, key); 230 if (p == NULL) 231 return input; 232 233 // we have input = xxxkeyxxx 234 // we want output = xxxreplacexxx 235 236 // this is safe since we will subtract strlen(key) elements from input 237 char *output = psAlloc(strlen(input) + strlen(replace) + 1); 238 int Nc = p - input; 239 240 // copy the first segement into 'output' 241 strncpy (output, input, Nc); 242 243 // copy the key replacement to the start of the key 244 245 strcpy (&output[Nc], replace); 246 Nc += strlen (replace); 247 248 // copy the remainder to the end of the replacement 249 strcpy (&output[Nc], p + strlen(key)); 250 251 psFree (input); 252 input = output; 253 } 254 return input; 255 } 256
Note:
See TracChangeset
for help on using the changeset viewer.
