strutils.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "libdali.h"

Include dependency graph for strutils.c:


Functions

int dl_strparse (const char *string, const char *delim, DLstrlist **list)
 Parse/split a string on a specified delimiter.
int dl_strncpclean (char *dest, const char *source, int length)
 Copy a string while removing space charaters.
int dl_addtostring (char **string, char *add, char *delim, int maxlen)
 Concatinate one string to another growing the destination as needed.

Detailed Description

Generic routines for string manipulation

Author:
Chad Trabant, IRIS Data Management Center
modified: 2008.193

Function Documentation

int dl_addtostring ( char **  string,
char *  add,
char *  delim,
int  maxlen 
)

Concatinate one string to another growing the destination as needed.

Concatinate one string to another with a delimiter in-between growing the destination string as needed up to a maximum length.

Parameters:
string Destination string to be added to
add String to add to string
delim Optional delimiter between added strings (cannot be NULL, but can be an empty string)
maxlen Maximum number of bytes to grow string
Returns:
0 on success, -1 on memory allocation error and -2 when string would grow beyond maximum length.

int dl_strncpclean ( char *  dest,
const char *  source,
int  length 
)

Copy a string while removing space charaters.

Copy length characters from source to dest while removing all spaces. The result is left justified and always null terminated. The source string must have at least length characters and the destination string must have enough room needed for the non-space characters within length and the null terminator.

Parameters:
dest Destination string
source String to copy
length Copy up to a maximum of this many characters to dest
Returns:
The number of characters (not including the null terminator) in the destination string.

int dl_strparse ( const char *  string,
const char *  delim,
DLstrlist **  list 
)

Parse/split a string on a specified delimiter.

Splits a 'string' on 'delim' and puts each part into a linked list pointed to by 'list' (a pointer to a pointer). The last entry has it's 'next' set to 0. All elements are NULL terminated strings.

It is up to the caller to free the memory associated with the returned list. To facilitate freeing this special string list dl_strparse() can be called with both 'string' and 'delim' set to NULL and then the linked list is traversed and the memory used is free'd and the list pointer is set to NULL.

Parameters:
string String to parse/split
delim Delimiter to split string on
list Returned list of sub-strings.
Returns:
The number of elements added to the list, or 0 when freeing the linked list.


Generated on Fri Sep 12 15:38:54 2008 for libdali by  doxygen 1.5.6