#include "string32.h"

std::string32::string32() {
	memset(this, 0, sizeof(string32));
}

std::string32::string32(std::string str) {
	memset(this, 0, sizeof(std::string32));
	length = str.size();
	textlength = textlength | 0xF;
	if (str.size() < 16) {
		memcpy(it, str.c_str(), str.size());
		if (str.size() < 15)
			it[str.size()] = 0;
	}
	else {
		size_t size = str.size();
		if (size + 1 >= 0x1000)
			size += 8;

		pit = reinterpret_cast<char*>(malloc(size + 1));
		textlength = size;
		if (size + 1 >= 0x1000) {
			*reinterpret_cast<char**>(pit) = pit;
			pit += 8;
		}

		if (pit != 0x0) {
			memcpy(pit, str.c_str(), str.size());
			pit[str.size()] = 0;
		}
	}
}

char* std::string32::c_str() {
	if (textlength < 16)
		return this->it;
	else
		return this->pit;
}
