<commit_before>// String.cpp
// This file is part of the EScript programming language.
// See copyright notice in EScript.h
// ------------------------------------------------------
#include "String.h"
#include "../../EScript.h"
#include "../../Utils/StringUtils.h"

#include <sstream>

using namespace EScript;
//---

using std::string;

std::stack<String *> String::stringPool;

//! static, internal
StringData String::objToStringData(Object * obj){
	String * strObj=dynamic_cast<String*>(obj);
	return strObj==NULL ? StringData(obj->toString()) : strObj->sData;
}

//---

//! (static)
Type * String::getTypeObject(){
	// [String] ---|> [Object]
	static Type * typeObject=new Type(Object::getTypeObject());
	return typeObject;
}

//! initMembers
void String::init(EScript::Namespace & globals) {
	Type * typeObject = getTypeObject();
	typeObject->setFlag(Type::FLAG_CALL_BY_VALUE,true);
	initPrintableName(typeObject,getClassName());

	declareConstant(&globals,getClassName(),typeObject);

	//! [ESMF] String new String((String)Obj)
	ESF_DECLARE(typeObject,"_constructor",0,1,String::create(parameter[0].toString("")))

	//! [ESMF] String String[(Number)position ]
	ES_MFUNCTION_DECLARE(typeObject,String,"_get",1,1, {
		assertParamCount(runtime,parameter.count(),1,1);
		int pos=parameter[0]->toInt();
		if (static_cast<unsigned int>(pos)>=self->getString().length())
			return NULL;
		return  String::create(self->getString().substr(pos,1));
	})


	// ---
	//! [ESMF] Bool String.beginsWith( (String)search )
	ES_MFUNCTION_DECLARE(typeObject,String,"beginsWith",1,1, {
		const string & s(self->getString());
		string search=parameter[0]->toString();
		if(s.length()<search.length())
			return Bool::create(false);
		return Bool::create(s.substr(0,search.length())==search);
	})

	//! [ESMF] Bool String.contains (String)search [,(Number)startIndex] )
	ES_MFUNCTION_DECLARE(typeObject,String,"contains",1,2, {
		const string & s(self->getString());
		string search=parameter[0]->toString();
		size_t start=s.length();
		if (parameter.count()>1) {
			start=static_cast<size_t>(parameter[1].toInt());
			if (start>=s.length())
				start=s.length();
		}<commit_msg>Remove redundant assertParamCount<commit_after>// String.cpp
// This file is part of the EScript programming language.
// See copyright notice in EScript.h
// ------------------------------------------------------
#include "String.h"
#include "../../EScript.h"
#include "../../Utils/StringUtils.h"

#include <sstream>

using namespace EScript;
//---

using std::string;

std::stack<String *> String::stringPool;

//! static, internal
StringData String::objToStringData(Object * obj){
	String * strObj=dynamic_cast<String*>(obj);
	return strObj==NULL ? StringData(obj->toString()) : strObj->sData;
}

//---

//! (static)
Type * String::getTypeObject(){
	// [String] ---|> [Object]
	static Type * typeObject=new Type(Object::getTypeObject());
	return typeObject;
}

//! initMembers
void String::init(EScript::Namespace & globals) {
	Type * typeObject = getTypeObject();
	typeObject->setFlag(Type::FLAG_CALL_BY_VALUE,true);
	initPrintableName(typeObject,getClassName());

	declareConstant(&globals,getClassName(),typeObject);

	//! [ESMF] String new String((String)Obj)
	ESF_DECLARE(typeObject,"_constructor",0,1,String::create(parameter[0].toString("")))

	//! [ESMF] String String[(Number)position ]
	ES_MFUNCTION_DECLARE(typeObject,String,"_get",1,1, {
		int pos=parameter[0]->toInt();
		if (static_cast<unsigned int>(pos)>=self->getString().length())
			return NULL;
		return  String::create(self->getString().substr(pos,1));
	})


	// ---
	//! [ESMF] Bool String.beginsWith( (String)search )
	ES_MFUNCTION_DECLARE(typeObject,String,"beginsWith",1,1, {
		const string & s(self->getString());
		string search=parameter[0]->toString();
		if(s.length()<search.length())
			return Bool::create(false);
		return Bool::create(s.substr(0,search.length())==search);
	})

	//! [ESMF] Bool String.contains (String)search [,(Number)startIndex] )
	ES_MFUNCTION_DECLARE(typeObject,String,"contains",1,2, {
		const string & s(self->getString());
		string search=parameter[0]->toString();
		size_t start=s.length();
		if (parameter.count()>1) {
			start=static_cast<size_t>(parameter[1].toInt());
			if (start>=s.length())
				start=s.length();
		}
{'fraction_non_alphanumeric': 0.21190974645266342, 'fraction_numerical': 0.007908816003721796, 'mean_word_length': 4.756358768406961, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, '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': '7638188', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1375, 'n_words': 233}