#ifndef _BUFFER_
#define _BUFFER_

#include "../error/error"

class Buffer {
public:
    Buffer();
    Buffer(Buffer const &other);
    ~Buffer();

    Buffer &operator= (Buffer const &other);
    Buffer &operator= (char const *b);

    void set (char const *b, unsigned len);
    void add (char const *b, unsigned len);
    char const *data() const;
    int strfind (char const *s) const;
    char &operator[] (unsigned index);
    string stringat (unsigned index, unsigned len) const;
    void removeat (unsigned index, unsigned len = 1);
    void insertat (unsigned index, char const *s, unsigned len);
    void insertat (unsigned index, string s);

    // This ones are called often so let's inline them.
    unsigned size() const {
	return (buf_len);
    }
    char charat (unsigned index) const {
	if (index >= buf_len)
	    return (0);
	return (buf_data[index]);
    }
	
private:
    void copy (Buffer const &other);
    void destroy();
    
    char *buf_data;
    unsigned buf_len;
};

#endif
