#ifndef	ESTRING_H
#define	ESTRING_H

/* -------------------------------------------------------------------- *\
                     Helper routines for 'string' type
\* -------------------------------------------------------------------- */

#define	ET_BOGUS_CHARS	4

typedef struct estr_s
{
	u32_t	len;		/* length (_not_ including trailing zero) */
	u32_t	datalen;	/* size of 'data' in bytes */
	char	*data;		/* zero-terminated */
}	estr_t, *estr_p;

#define	C_STR(es)		((es) ? (es)->data : NULL)

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/* creates new estr_t and copies chars from 'strz' */
	estr_p	V_GLOBAL	esNewString(char *strz);
	/* replaces chars in 'str' with ones from 'strz'; reallocates it, if necessary */
	estr_p	V_GLOBAL	esAssignString(estr_p str,char *strz);
	/* catenates string 'str2' to string 'str1'; reallocates the later, if necessary */
	estr_p	V_GLOBAL	esCatenateString(estr_p str1,estr_p str2);
	/* same as above, but second argument is a zero-terminated string */
	estr_p	V_GLOBAL	esCatenateStringZ(estr_p str1,char *strz);
	/* converts floating-point to string (with '%g' format) */
	estr_p	V_GLOBAL	esRealToString(vec_t val);
	/* converts integer to string (with '%i' format) */
	estr_p	V_GLOBAL	esIntToString(int val);
	/* converts floating-point to string using provided format */
	estr_p	V_GLOBAL	esRealToStringEx(char *fmt,vec_t val);
	/* converts integer to string using provided format */
	estr_p	V_GLOBAL	esIntToStringEx(char *fmt,int val);
#ifdef	__cplusplus
}
#endif	/* __cplusplus */

#define	esDuplicateString(str)			esNewString(C_STR(str))
#define	esCopyString(str1,str2)			esAssignString(str1,C_STR(str2))

#define	esStringToFloat(str,ret_val)	strToFloat(C_STR(str),ret_val)
#define	esStringToInt(str,ret_val)		strToInt(C_STR(str),ret_val)

#endif	/* ESTRING_H */
