On 07/29/2010 12:40 PM, Pádraig Brady wrote:
I thought of that but thought it would be too much overhead for the general case since it seemed like it would need strlen, u8_mbsnlen& u8_mbtouc, with conversions back and forth.
No! You can cheat! :) Just pass 4 to u8_mbtouc. There will be no out-of-bounds access: if the string ends before that, you get either a complete character or an EILSEQ.
The only extra check that you have to do is for an empty needle, which is not the same as u8_strchr (s, 0).
Paolo