Changeset 7380 for trunk/psLib/src/sys
- Timestamp:
- Jun 6, 2006, 5:22:07 PM (20 years ago)
- Location:
- trunk/psLib/src/sys
- Files:
-
- 2 added
- 3 edited
-
Makefile.am (modified) (2 diffs)
-
psLine.c (added)
-
psLine.h (added)
-
psString.c (modified) (5 diffs)
-
psString.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/Makefile.am
r7210 r7380 9 9 psError.c \ 10 10 psErrorCodes.c \ 11 psLine.c \ 11 12 psLogMsg.c \ 12 13 psMemory.c \ … … 32 33 psError.h \ 33 34 psErrorCodes.h \ 35 psLine.h \ 34 36 psLogMsg.h \ 35 37 psMemory.h \ -
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 } -
trunk/psLib/src/sys/psString.h
r7300 r7380 14 14 * @author David Robbins, MHPCC 15 15 * 16 * @version $Revision: 1.2 1$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-06-0 2 21:33:34$16 * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-06-07 03:22:06 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 107 107 ); 108 108 109 // given the input string, search for all copies of the key, and replace with the replacement value 109 // Same as psStringSplit, but return result as an array 110 psArray *psStringSplitArray(const char *string, // String to split 111 const char *splitters, // Characters on which to split 112 bool multipleAreSignificant // Are multiple occurences significant? 113 ); 114 115 // Given the input string, search for all copies of the key, and replace with the replacement value 110 116 // the input string may be freed if not needed 111 char *psStringSubstitute ( 112 char *input, ///< input string to be modified 113 char *replace, ///< replacement value 114 char *key ///< string to be replaced in input 115 ); 117 char *psStringSubstitute (char *input, ///< input string to be modified 118 const char *replace, ///< replacement value 119 const char *key ///< string to be replaced in input 120 ); 121 122 // strip whitespace from head and tail of string 123 size_t psStringStrip(char *string); 124 116 125 117 126 /** @} */// Doxygen - End of SystemGroup Functions
Note:
See TracChangeset
for help on using the changeset viewer.
