/** @file  psString.h
 *
 * -*- mode: C; c-basic-indent: 4; tab-width: 8; indent-tabs-mode: nil -*-
 * vim: set cindent ts=8 sw=4 expandtab:
 *
 *  @brief Contains the declarations of string utility functions
 *
 *  @ingroup SysUtils
 *
 *  String utility functions defined shall provide basic string copying
 *  capabilities.
 *
 *  @author Eric Van Alst, MHPCC
 *
 *  @version $Revision: 1.16.18.2 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2006-01-21 23:44:37 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 */

#ifndef PS_STRING_H
#define PS_STRING_H

#include <sys/types.h>
#include "psType.h"

/** This macro will convert the argument to a quoted string */
#define PS_STRING(S)  #S

// Doxygen group tags

/** @addtogroup SysUtils
 *  @{
 */

/** Copies the input string
 *
 *  This function shall allocate memory to the length of the input string plus
 *  one and copy the input string to the newly allocated memory.  If 'string'
 *  is 'NULL' then 'NULL' is returned.
 *
 *  @return psString:      Copy of input string
 *
 */
psString psStringCopy(
    const char *string                 ///< Input string of characters to copy
);

/** Copies the input string up to the specified number of characters
 *
 *  This function shall allocate memory to the length specified by nChar
 *  plus one and copy the input string to the newly allocated memory.
 *  This function will only copy nChar bytes from the input to new string,
 *  so if the input string is larger than nChar characters the copied
 *  string will be a substring of the input string.  If the input string
 *  is smaller than nChar bytes then the remaining bytes allocated will
 *  be set to NULL.  If 'string' is 'NULL' then 'NULL' is returned.
 *
 *  @return  psString:   Copy of input string
 *
 */

/*@null@*/

psString psStringNCopy(
    const char *string,                ///< Input string of characters to copy
    unsigned int nChar                 ///< Number of bytes to allocate for string copy
);

/** Appends a format onto a string
 *
 * This function shall allocate a new string if dest is NULL.  dest shall be
 * automatically extended to the size of the new string.
 *
 * @return The length of the new string (excluding '\0')
 */

ssize_t psStringAppend(
    char **dest,                        ///< existing string
    const char *format,                 ///< format to append
    ...                                 ///< format arguments
);

/** Prepends a format onto a string
 *
 * This function shall allocate a new string if dest is NULL.  dest shall be
 * automatically extended to the size of the new string.
 *
 * @return The length of the new string (excluding '\0')
 */

ssize_t psStringPrepend(
    char **dest,                        ///< existing string
    const char *format,                 ///< format to append
    ...                                 ///< format arguments
);

/** @} */// Doxygen - End of SystemGroup Functions


/* psLine not yet released */
# if (0)
    // structure to carry a dynamic string
    typedef struct
    {
        int NLINE;
        int Nline;
        char *line;
    }
psLine;

// psLine functions -- keep out for now?
psLine      *psLineAlloc (int Nline);
bool      psLineInit (psLine *line);
bool      psLineAdd (psLine *line, char *format, ...);
# endif

#endif // #ifndef PS_STRING_H

