<commit_before>#include "TextBox.hpp"

namespace cstr
{
	TextBox::TextBox()
	{
		rect.setPosition(0, 0);
	}
	
	TextBox::TextBox(const sf::IntRect& ir, const sf::Color& in, const sf::Color& out, const sf::Font& f)
	{
		rect.setPosition(ir.left, ir.top);
		rect.setSize({static_cast<float>(ir.width), static_cast<float>(ir.height)});
		rect.setFillColor(in);
		rect.setOutlineColor(out);
		rect.setOutlineThickness(-2);
		text.setFont(f);
		text.setPosition(rect.getPosition().x + 5, rect.getPosition().y + 5);
	}

	TextBox::~TextBox()
	{
	}
	
	void TextBox::setFont(const sf::Font& font)
	{
		text.setFont(font);
	}
	
	void TextBox::setTextColor(const sf::Color& tc)
	{
		text.setColor(tc);
	}
	
	void TextBox::setCharacterSize(unsigned size)
	{
		text.setCharacterSize(size);
	}
	
	const std::string& TextBox::getString() const
	{
		return string;
	}
	
	sf::FloatRect TextBox::getGlobalBounds() const
	{
		return rect.getGlobalBounds();
	}
	
	bool TextBox::contains(sf::Vector2i point)
	{
		return rect.getGlobalBounds().contains(static_cast<sf::Vector2f>(point));
	}
	
	void TextBox::mousePressed()
	{
		
	}
	
	void TextBox::mouseReleased()
	{
		
	}
	
	void TextBox::mouseMovedOn()
	{
		
	}
	
	void TextBox::mouseMovedOff()
	{
		
	}
	
	void TextBox::textEntered(char c)
	{
		// 8 = backspace, 13 = enter/return, 27 = escape, 127 = delete
		if(!(c == 8 || c == 13 || c == 27 || c == 127))
		{
			string += c;
			text.setString(string);
		}
		else if(c == 8)
		{
			string.erase(string.size() - 1);
			text.setString(string);
		}
	}
	
	void TextBox::draw(sf::RenderTarget& target, sf::RenderStates states) const
	{
		target.draw(rect, states);
		target.draw(text, states);
	}
}
<commit_msg>Fixed crash on backspacing too much.<commit_after>#include "TextBox.hpp"

namespace cstr
{
	TextBox::TextBox()
	{
		rect.setPosition(0, 0);
	}
	
	TextBox::TextBox(const sf::IntRect& ir, const sf::Color& in, const sf::Color& out, const sf::Font& f)
	{
		rect.setPosition(ir.left, ir.top);
		rect.setSize({static_cast<float>(ir.width), static_cast<float>(ir.height)});
		rect.setFillColor(in);
		rect.setOutlineColor(out);
		rect.setOutlineThickness(-2);
		text.setFont(f);
		text.setPosition(rect.getPosition().x + 5, rect.getPosition().y + 5);
	}

	TextBox::~TextBox()
	{
	}
	
	void TextBox::setFont(const sf::Font& font)
	{
		text.setFont(font);
	}
	
	void TextBox::setTextColor(const sf::Color& tc)
	{
		text.setColor(tc);
	}
	
	void TextBox::setCharacterSize(unsigned size)
	{
		text.setCharacterSize(size);
	}
	
	const std::string& TextBox::getString() const
	{
		return string;
	}
	
	sf::FloatRect TextBox::getGlobalBounds() const
	{
		return rect.getGlobalBounds();
	}
	
	bool TextBox::contains(sf::Vector2i point)
	{
		return rect.getGlobalBounds().contains(static_cast<sf::Vector2f>(point));
	}
	
	void TextBox::mousePressed()
	{
		
	}
	
	void TextBox::mouseReleased()
	{
		
	}
	
	void TextBox::mouseMovedOn()
	{
		
	}
	
	void TextBox::mouseMovedOff()
	{
		
	}
	
	void TextBox::textEntered(char c)
	{
		// 8 = backspace, 13 = enter/return, 27 = escape, 127 = delete
		if(!(c == 8 || c == 13 || c == 27 || c == 127))
		{
			string += c;
			text.setString(string);
		}
		else if(c == 8)
		{
			if(string.size() > 0)
			{
				string.erase(string.size() - 1);
				text.setString(string);
			}
		}
	}
	
	void TextBox::draw(sf::RenderTarget& target, sf::RenderStates states) const
	{
		target.draw(rect, states);
		target.draw(text, states);
	}
}

{'fraction_non_alphanumeric': 0.1719022687609075, 'fraction_numerical': 0.014834205933682374, 'mean_word_length': 3.912857142857143, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5496366', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1301, 'n_words': 223}