#ifndef STRING_HXX
# define STRING_HXX
# ifndef GPK_STD_H
#  include <gpk_std.h>
# endif

struct String	{
	private:
	int l;
	BOOL invariant() C	{return l==0 ? name==0
									: (name && l>0 && name[l]=='\0');}
	BOOL compare_text(C char *p) C;

	public:
	char *name;
	String() : name(0), l(0) {}
	String(char *n, int ll)	: name(n), l(ll) {}
			/* Assumes space is allocated with new.  It will be free()d. */
	String(C char *n, int l=(-1));
	String(C String&);
	~String();
	String& operator=(C String& a);
	String& operator=(C char *s);
	BOOL operator==(C char *p) C;
	BOOL operator==(C String& p) C {return l==p.l && compare_text(p.name);}
	BOOL operator!=(C char *p)	C {return ! ( (*this)==p ); }
	BOOL operator!=(C String& p)	C {return ! ( (*this)==p ); }
	BOOL begins_with(C char *p) C;
	BOOL begins_with(C String& ps) C;
	BOOL operator!() C	{return !name;}
	operator C char *() C	{return name;}
	char *array() C;
	String& operator+=(C String& s);
	String& operator+=(C char *s);
	int length() C	{return l;}
	int hash(int n) C;
	};

String operator+(C String& a, C String& b);
String operator+(C String& a, C char * b);
String operator+(C char *a, C String& b);
#endif
