<commit_before>/**
 * Clever programming language
 * Copyright (c) Clever Team
 *
 * This file is distributed under the MIT license. See LICENSE for details.
 */

#include <string>
#include <sstream>
#include <cstdio>
#include "modules/std/core/str.h"
#include "core/compiler.h"
#include "core/vm.h"
#include "core/clever.h"

namespace clever {

void StrType::dump(TypeObject* value, std::ostream& out) const
{
	out << *static_cast<StrObject*>(value)->value;
}

// + operator
CLEVER_TYPE_OPERATOR(StrType::add)
{
	if (EXPECTED(rhs->isStr())) {
		// TODO(Felipe): Do not require CString everywhere (because it stores the
		// data in an string table)
		result->setStr(new StrObject(*lhs->getStr() + *rhs->getStr()));
	} else if (rhs->isInt()) {
		std::stringstream ss;

		ss << rhs->getInt();
		result->setStr(new StrObject(*lhs->getStr() + ss.str()));
	} else if (rhs->isDouble()) {
		std::stringstream ss;

		ss << rhs->getDouble();
		result->setStr(new StrObject(*lhs->getStr() + ss.str()));
	}
}

// * operator
CLEVER_TYPE_OPERATOR(StrType::mul)
{
	if (rhs->isInt()) {
		std::ostringstream os;

		for (long i = 0, j = rhs->getInt(); i < j; ++i) {
			os << *lhs->getStr();
		}

		result->setStr(new StrObject(os.str()));
	}
}

// > operator
CLEVER_TYPE_OPERATOR(StrType::greater)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() > *rhs->getStr());
	}
}

// >= operator
CLEVER_TYPE_OPERATOR(StrType::greater_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() >= *rhs->getStr());
	}
}

// < operator
CLEVER_TYPE_OPERATOR(StrType::less)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() < *rhs->getStr());
	}
}

// <= operator
CLEVER_TYPE_OPERATOR(StrType::less_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() <= *rhs->getStr());
	}
}

// == operator
CLEVER_TYPE_OPERATOR(StrType::equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() == *rhs->getStr());
	}
}

// != operator
CLEVER_TYPE_OPERATOR(StrType::not_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(lhs->getStr() != rhs->getStr());
	}<commit_msg>- Missing change for != operator<commit_after>/**
 * Clever programming language
 * Copyright (c) Clever Team
 *
 * This file is distributed under the MIT license. See LICENSE for details.
 */

#include <string>
#include <sstream>
#include <cstdio>
#include "modules/std/core/str.h"
#include "core/compiler.h"
#include "core/vm.h"
#include "core/clever.h"

namespace clever {

void StrType::dump(TypeObject* value, std::ostream& out) const
{
	out << *static_cast<StrObject*>(value)->value;
}

// + operator
CLEVER_TYPE_OPERATOR(StrType::add)
{
	if (EXPECTED(rhs->isStr())) {
		// TODO(Felipe): Do not require CString everywhere (because it stores the
		// data in an string table)
		result->setStr(new StrObject(*lhs->getStr() + *rhs->getStr()));
	} else if (rhs->isInt()) {
		std::stringstream ss;

		ss << rhs->getInt();
		result->setStr(new StrObject(*lhs->getStr() + ss.str()));
	} else if (rhs->isDouble()) {
		std::stringstream ss;

		ss << rhs->getDouble();
		result->setStr(new StrObject(*lhs->getStr() + ss.str()));
	}
}

// * operator
CLEVER_TYPE_OPERATOR(StrType::mul)
{
	if (rhs->isInt()) {
		std::ostringstream os;

		for (long i = 0, j = rhs->getInt(); i < j; ++i) {
			os << *lhs->getStr();
		}

		result->setStr(new StrObject(os.str()));
	}
}

// > operator
CLEVER_TYPE_OPERATOR(StrType::greater)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() > *rhs->getStr());
	}
}

// >= operator
CLEVER_TYPE_OPERATOR(StrType::greater_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() >= *rhs->getStr());
	}
}

// < operator
CLEVER_TYPE_OPERATOR(StrType::less)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() < *rhs->getStr());
	}
}

// <= operator
CLEVER_TYPE_OPERATOR(StrType::less_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() <= *rhs->getStr());
	}
}

// == operator
CLEVER_TYPE_OPERATOR(StrType::equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() == *rhs->getStr());
	}
}

// != operator
CLEVER_TYPE_OPERATOR(StrType::not_equal)
{
	if (EXPECTED(rhs->isStr())) {
		result->setBool(*lhs->getStr() != *rhs->getStr());
	}
{'fraction_non_alphanumeric': 0.2145043560160113, 'fraction_numerical': 0.0004709206498704968, 'mean_word_length': 4.582128777923785, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 101, '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': '4002812', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1657, 'n_words': 286}