shinh / elvm

EsoLangVM Compiler Infrastructure
MIT License
1.13k stars 143 forks source link

Add strcspn implementation #101

Open umutoztunc opened 3 years ago

umutoztunc commented 3 years ago

I thought of implementing it using a 256-bit bitmap. Like storing characters in s2 like a blacklist to stop iteration of s1. However, it might be an overkill to create a bitmap for overall use-cases. Under most circumstances, the length of s2 should be way smaller than s1. Thus, I decided to copy the implementation from Bionic like some other functions in string.h.

I was planning to write some test cases, but I noticed there are no test cases for functions like strchr and the test structure looked a bit weird to me. It might be better to refactor the tests at some point. Still, I can write tests similar to fgets if you'd like.