Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int s_dstr::find(s_dstr needle)
- {
- assert(needle.len > 0);
- if(needle.len > len) { return - 1; }
- for(int haystack_i = 0; haystack_i < len; haystack_i++)
- {
- b8 all_match = true;
- for(int needle_i = 0; needle_i < needle.len; needle_i++)
- {
- char haystack_c = data[haystack_i + needle_i];
- char needle_c = needle.data[needle_i];
- if(haystack_c != needle_c)
- {
- all_match = false;
- }
- }
- if(all_match)
- {
- return haystack_i;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement