#ifndef STRINGBUFFER_H
#define STRINGBUFFER_H

/*
 * @(#)StringBuffer.h
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 2002 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDWserver.cpp for details.
 */

class StringBuffer {
	static int no, existing, existingTop;
	int *buf;
	int len;
	int size;
public:
	StringBuffer(int size = 16);
	StringBuffer(const StringBuffer &buffer);
	StringBuffer(StringBuffer *buffer);
	StringBuffer(const char *str);
	~StringBuffer();
	StringBuffer &operator=(StringBuffer *buffer);
	StringBuffer &operator+(char c) { return append(c); }
	StringBuffer &operator+(int i) { return append(i); }
	StringBuffer &operator+(const char *str) { return append(str); }
	StringBuffer &append(char c) { return insert(len, c); }
	StringBuffer &append(int i) { return insert(len, i); }
	StringBuffer &append(const char *str) { return insert(len, str); }
	StringBuffer &append(const char *str, int offset, int len) {
		return insert(this->len, str, offset, len);
	}
	int charAt(int index) const;
	StringBuffer &delete_(int start, int end);
	int getExisting() { return existing; }
	int getNo() { return no; }
	int indexOf(const char *str, int fromIndex = 0) const;
	StringBuffer &insert(int offset, char c);
	StringBuffer &insert(int offset, int i);
	StringBuffer &insert(int offset, const char *str);
	StringBuffer &insert(
		int index, const char *str, int offset, int len);
	int length() const { return len; }
private:
	int endsWith(const char *suffix) const;
	int equals(const char *str) const;
	int equalsIgnoreCase(const char *str) const;
	void init();
	int startsWith(const char *prefix) const;
	friend class String;
};

#endif
