string-cmp and string-cmp-ic added
This commit is contained in:
18
ml.cpp
18
ml.cpp
@@ -184,6 +184,10 @@ std::vector<std::string> MlValue::get_used_atoms() {
|
||||
}
|
||||
}
|
||||
|
||||
bool MlValue::is_nil() const {
|
||||
return type == NIL;
|
||||
}
|
||||
|
||||
bool MlValue::is_builtin() const {
|
||||
return type == BUILTIN;
|
||||
}
|
||||
@@ -1857,6 +1861,19 @@ MlValue string_find(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
return pos == -1 ? MlValue::nil() : MlValue((long) pos);
|
||||
}
|
||||
|
||||
MlValue string_cmp(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
eval_args(args, env);
|
||||
|
||||
if (args.size() != 2)
|
||||
throw MlError(MlValue("string-cmp", string_cmp), env, args.size() > 2 ? TOO_MANY_ARGS : TOO_FEW_ARGS);
|
||||
|
||||
if ( (args[0].is_nil() || (args[0].is_list() && args[0].as_list().empty())) ||
|
||||
(args[1].is_nil() || (args[1].is_list() && args[1].as_list().empty())) )
|
||||
return MlValue::nil();
|
||||
|
||||
|
||||
return MlValue((long)args[0].as_string().compare(args[1].as_string()));
|
||||
}
|
||||
|
||||
// trims characters " \n\r\t" from left or right or both ends of a string
|
||||
MlValue string_rltrim(std::vector<MlValue> args, MlEnvironment &env) {
|
||||
@@ -2240,6 +2257,7 @@ std::map<const std::string, Builtin> builtin_funcs
|
||||
std::make_pair("string-len", builtin::string_len),
|
||||
std::make_pair("string-substr", builtin::string_substr),
|
||||
std::make_pair("string-find", builtin::string_find),
|
||||
std::make_pair("string-cmp", builtin::string_cmp),
|
||||
|
||||
// Casting operations
|
||||
std::make_pair("int", builtin::cast_to_int),
|
||||
|
||||
Reference in New Issue
Block a user