Advertisement
Tkap1

Untitled

Jul 16th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. int s_dstr::find(s_dstr needle)
  2. {
  3. assert(needle.len > 0);
  4. if(needle.len > len) { return - 1; }
  5. for(int haystack_i = 0; haystack_i < len; haystack_i++)
  6. {
  7. b8 all_match = true;
  8. for(int needle_i = 0; needle_i < needle.len; needle_i++)
  9. {
  10. char haystack_c = data[haystack_i + needle_i];
  11. char needle_c = needle.data[needle_i];
  12. if(haystack_c != needle_c)
  13. {
  14. all_match = false;
  15. }
  16. }
  17. if(all_match)
  18. {
  19. return haystack_i;
  20. }
  21. }
  22. return -1;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement