std/lib: simplify String.{,r}index_of and improve speed for the index… (#907)

* std/lib: simplify String.{,r}index_of and improve speed for the index_of one

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

* lib/std/collections: add EnumMap.get_ref

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>

---------

Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2023-08-02 11:43:58 +02:00
committed by GitHub
parent 09bb7d3525
commit 9b1c75d061
3 changed files with 32 additions and 36 deletions

View File

@@ -80,6 +80,7 @@ fn void! test_index_of()
String test = "hello world hello";
assert(test.index_of("o")! == 4);
assert(test.index_of("ll")! == 2);
assert(test.index_of(" hello")! == 11);
assert(@catchof(test.index_of("wi")));
}
@@ -90,6 +91,7 @@ fn void! test_rindex_of()
assert(test.rindex_of("ll")! == 14);
assert(test.rindex_of("he")! == 12);
assert(test.rindex_of("world")! == 6);
assert(test.rindex_of("hello ")! == 0);
assert(@catchof(test.rindex_of("wi")));
}
@@ -98,6 +100,7 @@ fn void! test_index_of_char()
String test = "hello world hello";
assert(test.index_of_char('o')! == 4);
assert(test.index_of_char('l')! == 2);
assert(test.index_of_char('h')! == 0);
assert(@catchof(test.index_of_char('x')));
}
@@ -106,5 +109,6 @@ fn void! test_rindex_of_char()
String test = "hello world hello";
assert(test.rindex_of_char('o')! == 16);
assert(test.rindex_of_char('l')! == 15);
assert(test.rindex_of_char('h')! == 12);
assert(@catchof(test.index_of_char('x')));
}