Changeset 9509 for trunk/psLib/src/sys/psString.c
- Timestamp:
- Oct 12, 2006, 11:31:47 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
r8607 r9509 13 13 * @author David Robbins, MHPCC 14 14 * 15 * @version $Revision: 1.4 3$ $Name: not supported by cvs2svn $16 * @date $Date: 2006- 08-25 22:42:37 $15 * @version $Revision: 1.44 $ $Name: not supported by cvs2svn $ 16 * @date $Date: 2006-10-12 21:31:47 $ 17 17 * 18 18 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 304 304 } 305 305 306 char *search = input; // Search this string 306 307 while (true) { 307 char * p = strstr(input, key);308 if (! p) {308 char *found = strstr(search, key); // Found occurence of the key 309 if (!found) { 309 310 return input; 310 311 } … … 315 316 // this is safe since we will subtract strlen(key) elements from input 316 317 psString output = psStringAlloc(strlen(input) + replaceLength + 1); // Output string 317 int Nc = p - input;// Number of characters to copy318 int numChar = found - input; // Number of characters to copy 318 319 319 320 // copy the first segement into 'output' 320 strncpy(output, input, Nc);321 strncpy(output, input, numChar); 321 322 322 323 // copy the key replacement to the start of the key 323 324 if (replace && replaceLength > 0) { 324 strcpy( &output[Nc], replace);325 Nc+= replaceLength;325 strcpy(output + numChar, replace); 326 numChar += replaceLength; 326 327 } 327 328 328 329 // copy the remainder to the end of the replacement 329 strcpy( &output[Nc], p+ strlen(key));330 strcpy(output + numChar, found + strlen(key)); 330 331 331 332 psFree(input); 332 333 input = output; 334 search = output + numChar; 333 335 } 334 336
Note:
See TracChangeset
for help on using the changeset viewer.
