forked from Mirror/wren
Make String#contains return a bool.
This commit is contained in:
@ -176,10 +176,9 @@ DEF_PRIMITIVE(string_contains)
|
||||
const char* search = AS_CSTRING(args[1]);
|
||||
|
||||
// Corner case, the empty string contains the empty string.
|
||||
if (strlen(string) == 0 && strlen(search) == 0) return NUM_VAL(1);
|
||||
if (strlen(string) == 0 && strlen(search) == 0) return TRUE_VAL;
|
||||
|
||||
// TODO(bob): Return bool.
|
||||
return NUM_VAL(strstr(string, search) != NULL);
|
||||
return BOOL_VAL(strstr(string, search) != NULL);
|
||||
}
|
||||
|
||||
DEF_PRIMITIVE(string_count)
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
io.write("".contains("")) // expect: 1
|
||||
io.write("anything".contains("")) // expect: 1
|
||||
io.write("something".contains("meth")) // expect: 1
|
||||
io.write("something".contains("some")) // expect: 1
|
||||
io.write("something".contains("ing")) // expect: 1
|
||||
io.write("something".contains("math")) // expect: 0
|
||||
io.write("".contains("")) // expect: true
|
||||
io.write("anything".contains("")) // expect: true
|
||||
io.write("something".contains("meth")) // expect: true
|
||||
io.write("something".contains("some")) // expect: true
|
||||
io.write("something".contains("ing")) // expect: true
|
||||
io.write("something".contains("math")) // expect: false
|
||||
|
||||
// TODO(bob): Passing non-string as argument.
|
||||
|
||||
Reference in New Issue
Block a user