MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / search

Function search

rust/stringzilla.rs:3493–3526  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3491
3492 #[test]
3493 fn search() {
3494 let my_string: String = String::from("Hello, world!");
3495 let my_str: &str = my_string.as_str();
3496 let my_cow_str: Cow<'_, str> = Cow::from(&my_string);
3497
3498 // Identical to `memchr::memmem::find` and `memchr::memmem::rfind` functions
3499 assert_eq!(sz::find("Hello, world!", "world"), Some(7));
3500 assert_eq!(sz::rfind("Hello, world!", "world"), Some(7));
3501
3502 // Use the generic function with a String
3503 let world_string = String::from("world");
3504 assert_eq!(my_string.sz_find(&world_string), Some(7));
3505 assert_eq!(my_string.sz_rfind(&world_string), Some(7));
3506 assert_eq!(my_string.sz_find_byte_from(&world_string), Some(2));
3507 assert_eq!(my_string.sz_rfind_byte_from(&world_string), Some(11));
3508 assert_eq!(my_string.sz_find_byte_not_from(&world_string), Some(0));
3509 assert_eq!(my_string.sz_rfind_byte_not_from(&world_string), Some(12));
3510
3511 // Use the generic function with a &str
3512 assert_eq!(my_str.sz_find("world"), Some(7));
3513 assert_eq!(my_str.sz_rfind("world"), Some(7));
3514 assert_eq!(my_str.sz_find_byte_from("world"), Some(2));
3515 assert_eq!(my_str.sz_rfind_byte_from("world"), Some(11));
3516 assert_eq!(my_str.sz_find_byte_not_from("world"), Some(0));
3517 assert_eq!(my_str.sz_rfind_byte_not_from("world"), Some(12));
3518
3519 // Use the generic function with a Cow<'_, str>
3520 assert_eq!(my_cow_str.as_ref().sz_find("world"), Some(7));
3521 assert_eq!(my_cow_str.as_ref().sz_rfind("world"), Some(7));
3522 assert_eq!(my_cow_str.as_ref().sz_find_byte_from("world"), Some(2));
3523 assert_eq!(my_cow_str.as_ref().sz_rfind_byte_from("world"), Some(11));
3524 assert_eq!(my_cow_str.as_ref().sz_find_byte_not_from("world"), Some(0));
3525 assert_eq!(my_cow_str.as_ref().sz_rfind_byte_not_from("world"), Some(12));
3526 }
3527
3528 #[test]
3529 fn fill_random() {

Callers 2

operator()Method · 0.85
operator()Method · 0.85

Calls 1

as_strMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…