Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

psString.h

Go to the documentation of this file.
00001 /** @file  psString.h
00002  *
00003  * -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
00004  * vim: set cindent ts=8 sw=4 expandtab:
00005  *
00006  *  @brief Contains the declarations of string utility functions
00007  *
00008  *  @ingroup SysUtils
00009  *
00010  *  String utility functions defined shall provide basic string copying
00011  *  capabilities.
00012  *
00013  *  @author Eric Van Alst, MHPCC
00014  *  @author David Robbins, MHPCC
00015  *
00016  *  @version $Revision: 1.24 $ $Name: rel12 $
00017  *  @date $Date: 2006/06/27 20:33:22 $
00018  *
00019  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
00020  */
00021 
00022 #ifndef PS_STRING_H
00023 #define PS_STRING_H
00024 
00025 #include <sys/types.h>
00026 #include "psType.h"
00027 #include "psList.h"
00028 
00029 /** This macro will convert the argument to a quoted string */
00030 #define PS_STRING(S)  #S
00031 
00032 /** This macro returns a (static buffer containing) "file:line" */
00033 const char *p_psFileLine(const char *file, int line);
00034 #define PS_FILE_LINE p_psFileLine(__FILE__,__LINE__)
00035 
00036 // Doxygen group tags
00037 
00038 /** @addtogroup SysUtils
00039  *  @{
00040  */
00041 
00042 /** Copies the input string
00043  *
00044  *  This function shall allocate memory to the length of the input string plus
00045  *  one and copy the input string to the newly allocated memory.  If 'string'
00046  *  is 'NULL' then 'NULL' is returned.
00047  *
00048  *  @return psString:      Copy of input string
00049  */
00050 psString psStringCopy(
00051     const char *string                 ///< Input string of characters to copy
00052 );
00053 
00054 /** Copies the input string up to the specified number of characters
00055  *
00056  *  This function shall allocate memory to the length specified by nChar
00057  *  plus one and copy the input string to the newly allocated memory.
00058  *  This function will only copy nChar bytes from the input to new string,
00059  *  so if the input string is larger than nChar characters the copied
00060  *  string will be a substring of the input string.  If the input string
00061  *  is smaller than nChar bytes then the remaining bytes allocated will
00062  *  be set to NULL.  If 'string' is 'NULL' then 'NULL' is returned.
00063  *
00064  *  @return  psString:   Copy of input string
00065  */
00066 psString psStringNCopy(
00067     const char *string,                ///< Input string of characters to copy
00068     unsigned int nChar                 ///< Number of bytes to allocate for string copy
00069 );
00070 
00071 /** Appends a format onto a string
00072  *
00073  * This function shall allocate a new string if dest is NULL.  dest shall be
00074  * automatically extended to the size of the new string.
00075  *
00076  * @return ssize_t:     The length of the new string (excluding '\0')
00077  */
00078 ssize_t psStringAppend(
00079     char **dest,                        ///< existing string
00080     const char *format,                 ///< format to append
00081     ...                                 ///< format arguments
00082 );
00083 
00084 /** Prepends a format onto a string
00085  *
00086  * This function shall allocate a new string if dest is NULL.  dest shall be
00087  * automatically extended to the size of the new string.
00088  *
00089  * @return ssize_t:     The length of the new string (excluding '\0')
00090  */
00091 ssize_t psStringPrepend(
00092     char **dest,                        ///< existing string
00093     const char *format,                 ///< format to append
00094     ...                                 ///< format arguments
00095 );
00096 
00097 /** Procedure to split the input string into a psList of psStrings.
00098  *
00099  *  The string is split at any one of the characters in splitters.  Split
00100  *  strings of zero length should not be included in the output list.
00101  *
00102  *  @return psList*:    The list of (split) psStrings.
00103  */
00104 psList *psStringSplit(
00105     const char *string,                ///< String to split
00106     const char *splitters,             ///< Characters on which to split
00107     bool multipleAreSignificant        ///< Are multiple occurences significant?
00108 );
00109 
00110 /** Procedure to split the input string into a psArray of psStrings.
00111  *
00112  *  The string is split at any one of the characters in splitters.  Split
00113  *  strings of zero length should not be included in the output list.
00114  *
00115  *  @return psArray*:       The array of (split) psStrings.
00116  */
00117 psArray *psStringSplitArray(
00118     const char *string,                ///< String to split
00119     const char *splitters,             ///< Characters on which to split
00120     bool multipleAreSignificant        ///< Are multiple occurences significant?
00121 );
00122 
00123 // Given the input string, search for all copies of the key, and replace with the replacement value
00124 // the input string may be freed if not needed
00125 /** Procedure to search an input string and substitute strings where desired.
00126  *
00127  *  The input string is searched for all instances of the key, which is then replaced with
00128  *  the replacement value wherever found.  The input string may be freed if not needed.
00129  *
00130  *  @return char*:      the modified input string.
00131  */
00132 char *psStringSubstitute (
00133     char *input,                       ///< input string to be modified
00134     const char *replace,               ///< replacement value
00135     const char *key                    ///< string to be replaced in input
00136 );
00137 
00138 // strip whitespace from head and tail of string
00139 /** Procedure to strip the whitespace from the head and tail of a string.
00140  *
00141  *  @return size_t:         Number of whitespaces removed.
00142  */
00143 size_t psStringStrip(
00144     char *string                       ///< input string to be stripped.
00145 );
00146 
00147 
00148 /** @} */// Doxygen - End of SystemGroup Functions
00149 
00150 #endif // #ifndef PS_STRING_H

Generated on Mon Jul 3 14:13:44 2006 for Pan-STARRS Foundation Library by  doxygen 1.4.4