#pragma once

//#include <Shlwapi.h>
#include <stdio.h>

#define STRBASEBUFFERLEN 64

class XString
{
	char	*buffer;
	int		len;
	int		bufferlen;

public:
	XString(const char* txt);
	XString(wchar_t*txt);
	XString(void);
	XString(int val);
	XString(float val);
	~XString(void);
	XString(const XString &str);
	
	void clear(void){if(buffer)	buffer[0] = '\0';len=0;}
	int	getlen(void) const {return len;}
	char* getbuffer(void) const {return buffer;}
	void SetLength(const unsigned nchars);
	
	void operator =(const XString&);
	void operator =(char*);
	void operator =(wchar_t*);
	void operator =(int val);
	void operator =(float val);

	bool operator ==(const XString&) const;
	bool operator ==(char*) const;
	bool operator ==(wchar_t*) const;
	bool operator ==(int) const;
	bool operator ==(float) const;

	XString operator +(const XString&) const;
	XString operator +(char*);
	XString operator +(wchar_t*);
	XString operator +(int);
	XString operator +(float);

	bool isnumber(void) const;
	int toint (void) const;
	float tofloat(void) const;

	int cmp(const XString&) const;

	XString Left(int n) const;
	XString Right(int n) const;
	XString SubStr(int start,int n) const;
	XString Filter(char c) const;

	void ToLower(void);
	void ToUpper(void);

	//static XString Space(unsigned n);

	int instr(const XString& str, const int offset) const;
	int instrrev(const XString& str,const int offset) const;

	void insertat(unsigned pos,XString str);
	
	void replace(XString torplc,XString rplc);

	void appand(const XString&str);
	void appand(char c);
	void appand(char*str);
	void appand(wchar_t*str);
	void appand(int);
	void appand(float);

	void Read(FILE* const f);
	void Write(FILE* const f) const;

	static XString BuildRelativePath(const XString &to, const XString &from);
};