@@ -34,6 +34,7 @@ void OperatorBlocks::registerBlocks(IEngine *engine)
3434 engine->addCompileFunction (this , " operator_not" , &compileNot);
3535 engine->addCompileFunction (this , " operator_join" , &compileJoin);
3636 engine->addCompileFunction (this , " operator_letter_of" , &compileLetterOf);
37+ engine->addCompileFunction (this , " operator_length" , &compileLength);
3738}
3839
3940CompilerValue *OperatorBlocks::compileAdd (Compiler *compiler)
@@ -107,6 +108,12 @@ CompilerValue *OperatorBlocks::compileLetterOf(Compiler *compiler)
107108 return compiler->addFunctionCall (" operator_letter_of" , Compiler::StaticType::String, { Compiler::StaticType::Number, Compiler::StaticType::String }, { letter, string });
108109}
109110
111+ CompilerValue *OperatorBlocks::compileLength (Compiler *compiler)
112+ {
113+ auto string = compiler->addInput (" STRING" );
114+ return compiler->addFunctionCall (" operator_length" , Compiler::StaticType::Number, { Compiler::StaticType::String }, { string });
115+ }
116+
110117extern " C" char *operator_join (const char *string1, const char *string2)
111118{
112119 const size_t len1 = strlen (string1);
@@ -142,3 +149,9 @@ extern "C" char *operator_letter_of(double letter, const char *string)
142149
143150 return ret;
144151}
152+
153+ extern " C" double operator_length (const char *string)
154+ {
155+ // TODO: Rewrite this
156+ return utf8::utf8to16 (std::string (string)).size ();
157+ }
0 commit comments