BurntSushi / bstr

A string type for Rust that is not required to be valid UTF-8.
Other
793 stars 56 forks source link

Complementary ByteSlice functions addition - find_not_byte / rfind_not_byte #155

Open kam821 opened 1 year ago

kam821 commented 1 year ago

i've been working with bstr recently and noticed that the ByteSlice has some functions missing that would help to achieve API symmetry and reduce the potential overhead of unnecessary precondition checking.

find_byte/rfind_byte functions that utilize memchr/memrchr internally are available, however, their inverted cousins (find_not_byte/rfind_not_byte) are missing.

Currently it is necessary to use find_not_byteset/rfind_not_byteset that dispatch to scalar::inv_memchr/inv_memrchr if byteset.len() is equal to 1.

Best regards

BurntSushi commented 1 year ago

API symmetry isn't really a goal I have to be honest. It's definitely a consideration, and I do consider API symmetry valuable unto itself, but it is but one of many things that are valuable. For example, in this case, I personally think that find_not_byte is a very uncommon routine to need, and find it to be quite okay to need to use find_not_byteset instead.

I would be open to some documentation improvements that mention the use of find_not_byteset in the docs of find_byte.