
#ifndef _JL_STRING_H_
#define _JL_STRING_H_

#include <stdlib.h>
#include <string.h>
#include <iostream.h>

class JLString {

	private:
		char	*_str;		 // pointer to string
		int		_len;		 // length of string
		int		_referenced; // did someone else allocate the memory?

	public:
		JLString();
		JLString(const JLString&);
		JLString(const char*);
		JLString(int argc_num, char **argv);
		~JLString();

		char* GetString() const { return _str; }
		int Len() const { return _len; }
		int Length() const { return _len; }
		int GetLength() const { return _len; }
		float Val() const { return (_str ? atof(_str) : 0); }

		char operator[](int i) const;

		JLString& SetString(const char*);
		JLString& operator=(const char *c) { return SetString(c); }
		JLString& operator=(const JLString &s) { return SetString(s._str); }

		int operator==(const JLString&) const;
		int operator!=(const JLString&) const;
		int operator==(const char*) const;
		int operator!=(const char*) const;
		int operator<(const JLString&) const;
		int operator>(const JLString&) const;

		JLString& operator+=(const char);
		JLString& operator+=(const char*);
		JLString& operator+=(const JLString&);
		JLString& operator+=(const int i) { *this = *this + i; return *this; }

		JLString operator+(const JLString&);
		friend JLString operator+(const char*, JLString&);

		friend JLString operator+(char c, JLString &S) {
				JLString tmp;
				tmp += c;
				return tmp + S;
			}
		friend JLString operator+(JLString &S, char c) {
				JLString tmp(S);
				tmp += c;
				return tmp;
			}
				

		friend JLString operator+(int, JLString&);
		friend JLString operator+(JLString&, int);

		JLString SubString(int, int) const;
		int IsAlpha();
		int IsInt();
		int IsFloat();
		int TryToEat(char);
		void EatUpTo(char);

		friend ostream& operator<<(ostream&, const JLString&);
		friend istream& operator>>(istream&, JLString&);
};

#endif
