/*	File		:	F1String.h
**	Author		:	drclue@drclue.net (A.K.A. Ian A. Storms)
**	Description	:	At one time in ancient history, the F1_STRING
**		existed without the benefit of std::string to leverage , but times
**		have changed , and since it is now available pretty much accross the board
**		things have been re-arranged to exploit the std:string.
**
*/
#ifndef _F1STRING_H
#define _F1STRING_H


#include "F1types.h"		// Shared by all F1xxxx code , typically in ../F1All_c
#include <stdarg.h>		// Used in variable parameters list.
#include <stdio.h>		// Used to define FILE structure and such.

#include <string>
using namespace std;

//http://www.sgi.com/tech/stl/basic_string.html
#define iNEWLIMIT 13000


/* A major activity in string parsing is the splitting of strings.
** It has become apparent during my coding that these splits
** are patternistic , so the following modes have been defined 
** for the ::splitTo() functionality
*/
enum F1_SPLITMODE	{	F1_SPLITEAT	=1	,	//indicates that the splitstring
								//should disappear in the course
								//of the string splitting activity
				F1_SPLITKEEP	=2	,	//indicates that the split string will
								//remain part of the resulting split.
				F1_SPLITLEFT	=4	,	//indicates that the split should occur
								//based on the first occurance of the
								//split string.
				F1_SPLITEATLEFT	=5	,

				F1_SPLITRIGHT	=8	,	//indicates that the split should occur
								//based on the last occurance of the
								//split string.
				F1_SPLITEATRIGHT=9		//Combines F1_SPLITEAT and F1_SPLITRIGHT
			};	// END enum F1_SPLITMODE
/* I guess in perl , it is called "chomp", as opposed to "chop",
** but unless I miss-interpreted, the purpose is basically the same.
** The chopped characters can be removed from the left, the right, or
** from both ends of the string.
*/
enum	F1_CHOPMODE	{	F1_CHOPALL	=1,//	Remove specified characters from beginning and end
				F1_CHOPLEFT	=2,//	Remove specified charactersfrom left end of string
				F1_CHOPRIGHT	=4,//	Remove specified charactersfrom right end of string
				F1_CHOPENDS	=8 //	I don't remember what this one is
			};	// END enum F1_CHOPMODE

/*	CLASS		:	F1_STRING
**	Description	:	Derived from std::string so as to add a few things of my own
**				and to wrap some of the odd behaviors in the standard string class.
*/

typedef class	f1_string		F1_STRING			;
typedef					F1_STRING	*F1_pSTRING	;
class		f1_string : public	std::string
	{
public:
		string		osSubString;
static	const	F1_pChar	EMPTYOBJECT		;
		F1_pChar	operator()	(void)	;//		{return toString();	}
		F1_void		clear		(void)	;
		F1_int32	setString(		F1_pChar	sz		);

		F1_int32	indexOf		(	F1_char		C		,
							F1_int32	iOffset=0	)	,
				indexOf		(	F1_pChar	szC		,
							F1_int32	iOffset=0	)	,
				indexOfExcluding(	F1_char		C		,
							F1_pChar	szExcludes	,
							F1_int32	iOffset=0	)	,
				indexOfExcluding(	F1_pChar	szC		,
							F1_pChar	szExcludes	,
							F1_int32	iOffset=0	)	,
				nearestOf	(	F1_pChar	szC		,
							F1_int32	iOffset=0	);
		F1_pChar	strcat		(	F1_pChar	sz		);
		F1_STRING&	stringf		(	const	F1_pChar	szFormat	,
							...					);
		F1_STRING&	stringf		(	F1_bool			Append		,
							const	F1_pChar	szFormat	,
							...					);
		F1_STRING&	operator<<( const F1_pChar szAdd);

	// Constructor
		f1_string	(F1_pChar szP	);
		f1_string	(F1_void	);
		f1_string	(F1_char	);
		F1_int32	charAt	(F1_int32 iC);
		F1_bool		cmp		(	F1_pChar	szString	,
							F1_int32	iLen=-1		);

		F1_pChar	insert		(F1_pChar	szValue			,
						 F1_int32	iStartat=0		,
						 F1_int32	iLen=-1			);
		F1_int32	lastIndexOf	(F1_pChar sz				,
						 F1_int		iOffset	=0		);
		F1_int32	nearestOfExcluding(F1_pChar     Bytes			,
						 F1_pChar       szExcludes		,
						 F1_int		iOffset =0		);
		F1_pChar	replace		(F1_pChar	szTarget		,
						 F1_pChar	szWith			,
						 F1_int32	Count=1			);
		F1_char		setChar		(F1_int		iOffset			,
						 F1_char	cChar			);
		F1_pChar	splitIndexTo    (F1_pSTRING				,
						 F1_pChar				,
						 F1_SPLITMODE	cMode	=F1_SPLITLEFT	,
						 F1_int		iOffset	=0		);
		F1_pChar	substring	(F1_int32	StartAt			,
						 F1_int32	EndAt=-1		);
		F1_uint32	suck		(F1_uint32	ilength	=0		,
						 F1_uint32	iOffset	=0		);
		F1_float	toFloat		(F1_void				);
		F1_int		toInt		(F1_void				);
		F1_pChar	toUpper		(F1_void				),
				toLower		(F1_void				),
				toProper	(F1_void				); 
		F1_pChar	toString	(F1_void				);
		F1_int32	toLong		(F1_void				);
		F1_pChar	Encode		(F1_char	C			);
		F1_pChar	Encode		(F1_pChar	szBuff			,
						 F1_bool	bCLEARBUFF	=FALSE	);
		F1_pChar	Encode		(F1_pChar	szName			,
						 F1_pChar	szValue			,
						 F1_bool	bCLEARBUFF	=FALSE	);
		F1_int		GetEnvVar	(F1_pChar	szValue			,
						 F1_pChar	szDefault	=""	,
						 F1_int		iOffset		=0	);
		F1_pChar	GETS		(FILE		*fHandle=stdin		);
		F1_pChar	chop		(F1_pChar	CHARS="\n\r"		 ,
						 F1_CHOPMODE	iMode=F1_CHOPALL	);

		F1_pSTRING	Trim		(F1_pChar	CHARS="\n\r"		);
		F1_pSTRING	TrimStart	(F1_pChar	CHARS="\n\r"		);
		F1_pSTRING	TrimEnd		(F1_pChar	CHARS="\n\r"		);

		F1_pChar	InList		(F1_STRING	obItem			,
						 F1_char	Delimiter	=':'	,
						 F1_bool	exact		=TRUE	);
	};


extern	F1_int		LIST_ITEM	(	F1_STRING	obTarget		,
						F1_STRING	obLIST			,
						F1_int		iIndex			,
						F1_char		DELIMITER=':'		);

extern	F1_pChar	ExtractOption	(	F1_pChar	OptionName		,
						F1_pChar	tag			);

extern	F1_pChar	AT		(	F1_pChar	value			,
						F1_pChar	string			,
						F1_bool		bWholeWord	=false  );



extern	F1_int		Encode		(	F1_pChar	BUFF			,
						F1_char		C			);
extern	F1_int		Encode		(	F1_pChar	BUFF			,
						F1_pChar	string			,
						F1_int		Clearbuf=0		);
extern	F1_int		Encode		(	F1_pChar	szBUFF			,
						F1_pChar	szNAME			,
						F1_int	 	iVALUE			,
						F1_int	 	iCLEARBUFF		);
extern	F1_int		Encode		(	F1_pChar	szBUFF			,
						F1_pChar	szNAME			,
						F1_pChar	szVALUE			,
						F1_int		iCLEARBUFF		);

//***	Is the szItem contained within the szList which has cDelimiter as the separator
extern	F1_pChar	INLIST		(	F1_pChar	szItem			,
						F1_pChar	szList			,
						F1_char		cDelimiter=':'		,
						F1_bool		bExact=TRUE		);


#endif

