

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <array.h>

#include <dirent.h> 



class text{

	char * value;


	int usevalue = -1;

	int length;

	int capacity	= 500;

	
	int operator==( text * b ) {

		if( strcmp( this->value, b->value ) == 0 ) {

			return 1;

		} else {

			return 0;

		}

	}

	text * operator+=( char * b ) {

		this->append( b );

		return this;

	}

	void constructor( char * value ) {

		this->length		= strlen( value );

		if( this->length > this->capacity ) {

			this->capacity	= this->length * 2;

		}

		this->value			= malloc( sizeof( char ) * this->capacity );

		strcpy( this->value, value );
	}

	char get( int index ) {

		return this->value[ index ];

	}

	void resize( int size ) {

		this->value			= realloc( this->value, size );

		this->capacity		= size;

	}

	text * append( char * value ) {

		int originalLength 	= this->length;

		int newValueLength	= strlen( value );

		this->length		+= newValueLength;

		if( this->length > this->capacity ) {

			this->resize( this->length * 2 );

		}

		memcpy( this->value + originalLength, value, newValueLength + 1 );

		return this;

	}

	text * appendBinary( char * value, int size ) {

		int originalLength 	= this->length;

		int newValueLength	= size;

		this->length		+= newValueLength;

		if( this->length > this->capacity ) {

			this->resize( this->length * 2 );

		}

		memcpy( this->value + originalLength, value, newValueLength + 1 );

		return this;

	}


	text * appendObject( text * object ) {

		int originalLength 	= this->length;

		int newValueLength	= object->length;

		this->length	+= newValueLength;

		if( this->length > this->capacity ) {

			this->resize( this->length * 2 );

		}

		memcpy(this->value + originalLength, object->value, newValueLength + 1);

		return this;

	}

	text * concatenate( char * value ) {

		text * copy = new text( this->value );

		strcat( copy->value, value );

		return copy;

	}

	char * toNative() {

		return this->value;

	}

	char * whiteSpace( int whiteSpaceCount ) {

		char * output = malloc( 400 );

		for (int i = 0; i < whiteSpaceCount; ++i)
		{

			strcat( output, " " );

		}

		return output;

	}

	void free() {

		free( this->value );

		free( this );

	}

}